[LTP] [PATCH 1/3] tst_ioctl: Cleanup the code

Petr Vorel pvorel@suse.cz
Wed Oct 11 18:08:20 CEST 2023


From: Petr Vorel <petr.vorel@gmail.com>

* Use SAFE_{OPEN,CLOSE}() (simplification), -1 return code is removed.
* Cleanup unused headers.
* Include tst_fs.h, to keep signature checked during compilation.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 lib/tst_ioctl.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/lib/tst_ioctl.c b/lib/tst_ioctl.c
index 364220bcd..34a056cf4 100644
--- a/lib/tst_ioctl.c
+++ b/lib/tst_ioctl.c
@@ -1,37 +1,27 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
 #include <sys/ioctl.h>
 #include <linux/fs.h>
 
 #define TST_NO_DEFAULT_MAIN
 
 #include "tst_test.h"
+#include "tst_fs.h"
 
 int tst_fibmap(const char *filename)
 {
-	/* test if FIBMAP ioctl is supported */
 	int fd, block = 0;
 
-	fd = open(filename, O_RDWR | O_CREAT, 0666);
-	if (fd < 0) {
-		tst_res(TWARN | TERRNO,
-			 "open(%s, O_RDWR | O_CREAT, 0666) failed", filename);
-		return -1;
-	}
+	fd = SAFE_OPEN(filename, O_RDWR | O_CREAT, 0666);
 
 	if (ioctl(fd, FIBMAP, &block)) {
 		tst_res(TINFO | TERRNO, "FIBMAP ioctl is NOT supported");
 		close(fd);
 		return 1;
 	}
+
 	tst_res(TINFO, "FIBMAP ioctl is supported");
+	SAFE_CLOSE(fd);
 
-	if (close(fd)) {
-		tst_res(TWARN | TERRNO, "close(fd) failed");
-		return -1;
-	}
 	return 0;
 }
-- 
2.42.0



More information about the ltp mailing list