]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
regularize emptiness checks in fini_module(2) and vfs_dedupe_file_range()
authorAl Viro <viro@zeniv.linux.org.uk>
Sat, 20 Jul 2024 05:17:52 +0000 (01:17 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Sun, 3 Nov 2024 06:28:06 +0000 (01:28 -0500)
With few exceptions emptiness checks are done as fd_file(...) in boolean
context (usually something like if (!fd_file(f))...); those will be
taken care of later.

However, there's a couple of places where we do those checks as
'store fd_file(...) into a variable, then check if this variable is
NULL' and those are harder to spot.

Get rid of those now.

use fd_empty() instead of extracting file and then checking it for NULL.

Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/remap_range.c
kernel/module/main.c

index 4403d5c68fcbedeed03c6d4fc0d6d83d8df7c73a..017d0d1ea6c9a137c28b16f196a247ddb32ab82d 100644 (file)
@@ -537,9 +537,8 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same)
 
        for (i = 0, info = same->info; i < count; i++, info++) {
                struct fd dst_fd = fdget(info->dest_fd);
-               struct file *dst_file = fd_file(dst_fd);
 
-               if (!dst_file) {
+               if (fd_empty(dst_fd)) {
                        info->status = -EBADF;
                        goto next_loop;
                }
@@ -549,7 +548,7 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same)
                        goto next_fdput;
                }
 
-               deduped = vfs_dedupe_file_range_one(file, off, dst_file,
+               deduped = vfs_dedupe_file_range_one(file, off, fd_file(dst_fd),
                                                    info->dest_offset, len,
                                                    REMAP_FILE_CAN_SHORTEN);
                if (deduped == -EBADE)
index 49b9bca9de12f77121e80aafa1c705516e3b7e98..d785973d8a51d5b79c78d08d37b8e619a99f78ab 100644 (file)
@@ -3202,7 +3202,7 @@ static int idempotent_init_module(struct file *f, const char __user * uargs, int
 {
        struct idempotent idem;
 
-       if (!f || !(f->f_mode & FMODE_READ))
+       if (!(f->f_mode & FMODE_READ))
                return -EBADF;
 
        /* Are we the winners of the race and get to do this? */
@@ -3234,6 +3234,8 @@ SYSCALL_DEFINE3(finit_module, int, fd, const char __user *, uargs, int, flags)
                return -EINVAL;
 
        f = fdget(fd);
+       if (fd_empty(f))
+               return -EBADF;
        err = idempotent_init_module(fd_file(f), uargs, flags);
        fdput(f);
        return err;