From patchwork Fri Jul 1 14:26:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 71311 Delivered-To: patches@linaro.org Received: by 10.140.28.4 with SMTP id 4csp331721qgy; Fri, 1 Jul 2016 07:26:04 -0700 (PDT) X-Received: by 10.194.48.7 with SMTP id h7mr3906516wjn.9.1467383164082; Fri, 01 Jul 2016 07:26:04 -0700 (PDT) Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id f1si2275635wjg.78.2016.07.01.07.26.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Jul 2016 07:26:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1bIzON-0007kw-7U; Fri, 01 Jul 2016 15:26:03 +0100 From: Peter Maydell To: ltp@lists.linux.it Cc: patches@linaro.org Subject: [PATCH] syscalls/mount03: close files in MS_NOATIME test error paths Date: Fri, 1 Jul 2016 15:26:02 +0100 Message-Id: <1467383162-2072-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.9.1 The mount03 test has a bug in the error handling code paths for the MS_NOATIME flag test: if for instance a read() fails then we return from test_rwflag() without doing a close() on the filedescriptor. This then causes the umount() performed by tst_release_device() to fail with EBUSY, and then the loopback device is left mounted. Later, other test cases that try to use the loopback device then fail unnecessarily. Close open file descriptors in error-exit codepaths, so that cleanup on failure works as intended. This brings the code for MS_NOATIME into line with how the other test cases in the function handle this. Signed-off-by: Peter Maydell --- testcases/kernel/syscalls/mount/mount03.c | 4 ++++ 1 file changed, 4 insertions(+) -- 1.9.1 diff --git a/testcases/kernel/syscalls/mount/mount03.c b/testcases/kernel/syscalls/mount/mount03.c index 1873f0f..a8abbff 100644 --- a/testcases/kernel/syscalls/mount/mount03.c +++ b/testcases/kernel/syscalls/mount/mount03.c @@ -308,11 +308,13 @@ int test_rwflag(int i, int cnt) if (write(fd, "TEST_MS_NOATIME", 15) != 15) { tst_resm(TWARN | TERRNO, "write %s failed", file); + close(fd); return 1; } if (fstat(fd, &file_stat) == -1) { tst_resm(TWARN | TERRNO, "stat %s failed #1", file); + close(fd); return 1; } @@ -322,11 +324,13 @@ int test_rwflag(int i, int cnt) if (read(fd, readbuf, sizeof(readbuf)) == -1) { tst_resm(TWARN | TERRNO, "read %s failed", file); + close(fd); return 1; } if (fstat(fd, &file_stat) == -1) { tst_resm(TWARN | TERRNO, "stat %s failed #2", file); + close(fd); return 1; } close(fd);