diff mbox series

[1/3] tst_ioctl: Cleanup the code

Message ID 20231011160822.578637-2-pvorel@suse.cz
State Accepted
Headers show
Series Cleanup tst_ioctl.c, libswap.c | expand

Commit Message

Petr Vorel Oct. 11, 2023, 4:08 p.m. UTC
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(-)

Comments

Cyril Hrubis Dec. 8, 2023, 3:48 p.m. UTC | #1
Hi!
>  
>  	if (ioctl(fd, FIBMAP, &block)) {
>  		tst_res(TINFO | TERRNO, "FIBMAP ioctl is NOT supported");
>  		close(fd);

This should be SAFE_CLOSE() as well, since we are doing the conversion.

Other than that:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Petr Vorel Dec. 10, 2023, 4:22 p.m. UTC | #2
Hi Cyril,

> Hi!

> >  	if (ioctl(fd, FIBMAP, &block)) {
> >  		tst_res(TINFO | TERRNO, "FIBMAP ioctl is NOT supported");
> >  		close(fd);

> This should be SAFE_CLOSE() as well, since we are doing the conversion.

Good point, thanks. I added missing license and merged.

Kind regards,
Petr
diff mbox series

Patch

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;
 }