Skip to contentSkip to conversation

fuse: use min_t() instead of ternary operator

PATCH In review Mahad Ibrahim 2 participants 2 messages Jun 7 – Jun 9

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fuse: use min_t() instead of ternary operator

Replace existing ternary operators for finding minimum value with min_t macro to adhere to kernel coding standards and improve readability.

Fix coccinelle warning:
WARNING opportunity for min()

Testing: Tested at runtime via sshfs with file creation, appendating and reading.

---
 fs/fuse/file.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/fuse/file.c +3 -2
index f94f3dc082c6..67bab59bc6a7 100644
@@ -14,6 +14,7 @@
 #include <linux/sched.h>
 #include <linux/sched/signal.h>
 #include <linux/module.h>
+#include <linux/minmax.h>
 #include <linux/swap.h>
 #include <linux/falloc.h>
 #include <linux/uio.h>
@@ -1066,7 +1067,7 @@ static void fuse_send_readpages(struct fuse_io_args *ia, struct file *file,
 			return;
 	} else {
 		res = fuse_simple_request(fm, &ap->args);
-		err = res < 0 ? res : 0;
+		err = min_t(int, res, 0);
 	}
 	fuse_readpages_end(fm, &ap->args, err);
 }
@@ -2895,7 +2896,7 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
 	if (io->async) {
 		bool blocking = io->blocking;
 
-		fuse_aio_complete(io, ret < 0 ? ret : 0, -1);
+		fuse_aio_complete(io, min_t(int, ret, 0), -1);
 
 		/* we have a non-extending, async request, so return */
 		if (!blocking)
Signature · 1 line
2.47.3
maintainer
#1 lore raw
Quoted 3 lines · Mahad Ibrahim

Replace existing ternary operators for finding minimum value with min_t macro to adhere to kernel coding standards and improve readability.

Doesn't improve readability, on the contrary, it obfuscates the real meaning (return error or zero).

Thanks,
Miklos