]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fdget_raw() users: switch to CLASS(fd_raw)
authorAl Viro <viro@zeniv.linux.org.uk>
Sat, 1 Jun 2024 02:45:26 +0000 (22:45 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Sun, 3 Nov 2024 06:28:06 +0000 (01:28 -0500)
Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
arch/arm/kernel/sys_oabi-compat.c
fs/fcntl.c
fs/namei.c
fs/open.c
fs/quota/quota.c
fs/statfs.c
kernel/cgroup/cgroup.c
security/landlock/syscalls.c

index f5781ff54a5ca3c67e75dd1771cda33879d97bd3..2944721e82a2b350c82ec74074dd683967fd9579 100644 (file)
@@ -235,12 +235,12 @@ asmlinkage long sys_oabi_fcntl64(unsigned int fd, unsigned int cmd,
                                 unsigned long arg)
 {
        void __user *argp = (void __user *)arg;
-       struct fd f = fdget_raw(fd);
+       CLASS(fd_raw, f)(fd);
        struct flock64 flock;
-       long err = -EBADF;
+       long err;
 
-       if (!fd_file(f))
-               goto out;
+       if (fd_empty(f))
+               return -EBADF;
 
        switch (cmd) {
        case F_GETLK64:
@@ -271,8 +271,6 @@ asmlinkage long sys_oabi_fcntl64(unsigned int fd, unsigned int cmd,
                err = sys_fcntl64(fd, cmd, arg);
                break;
        }
-       fdput(f);
-out:
        return err;
 }
 
index 22dd9dcce7ecc8536afd9dd59b8aaf4644babb29..bd022a54bd0d61b6394e74f0699ba952d6c69517 100644 (file)
@@ -570,24 +570,21 @@ static int check_fcntl_cmd(unsigned cmd)
 
 SYSCALL_DEFINE3(fcntl, unsigned int, fd, unsigned int, cmd, unsigned long, arg)
 {      
-       struct fd f = fdget_raw(fd);
-       long err = -EBADF;
+       CLASS(fd_raw, f)(fd);
+       long err;
 
-       if (!fd_file(f))
-               goto out;
+       if (fd_empty(f))
+               return -EBADF;
 
        if (unlikely(fd_file(f)->f_mode & FMODE_PATH)) {
                if (!check_fcntl_cmd(cmd))
-                       goto out1;
+                       return -EBADF;
        }
 
        err = security_file_fcntl(fd_file(f), cmd, arg);
        if (!err)
                err = do_fcntl(fd, cmd, arg, fd_file(f));
 
-out1:
-       fdput(f);
-out:
        return err;
 }
 
@@ -596,21 +593,21 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd,
                unsigned long, arg)
 {      
        void __user *argp = (void __user *)arg;
-       struct fd f = fdget_raw(fd);
+       CLASS(fd_raw, f)(fd);
        struct flock64 flock;
-       long err = -EBADF;
+       long err;
 
-       if (!fd_file(f))
-               goto out;
+       if (fd_empty(f))
+               return -EBADF;
 
        if (unlikely(fd_file(f)->f_mode & FMODE_PATH)) {
                if (!check_fcntl_cmd(cmd))
-                       goto out1;
+                       return -EBADF;
        }
 
        err = security_file_fcntl(fd_file(f), cmd, arg);
        if (err)
-               goto out1;
+               return err;
        
        switch (cmd) {
        case F_GETLK64:
@@ -635,9 +632,6 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd,
                err = do_fcntl(fd, cmd, arg, fd_file(f));
                break;
        }
-out1:
-       fdput(f);
-out:
        return err;
 }
 #endif
@@ -733,21 +727,21 @@ static int fixup_compat_flock(struct flock *flock)
 static long do_compat_fcntl64(unsigned int fd, unsigned int cmd,
                             compat_ulong_t arg)
 {
-       struct fd f = fdget_raw(fd);
+       CLASS(fd_raw, f)(fd);
        struct flock flock;
-       long err = -EBADF;
+       long err;
 
-       if (!fd_file(f))
-               return err;
+       if (fd_empty(f))
+               return -EBADF;
 
        if (unlikely(fd_file(f)->f_mode & FMODE_PATH)) {
                if (!check_fcntl_cmd(cmd))
-                       goto out_put;
+                       return -EBADF;
        }
 
        err = security_file_fcntl(fd_file(f), cmd, arg);
        if (err)
-               goto out_put;
+               return err;
 
        switch (cmd) {
        case F_GETLK:
@@ -790,8 +784,6 @@ static long do_compat_fcntl64(unsigned int fd, unsigned int cmd,
                err = do_fcntl(fd, cmd, arg, fd_file(f));
                break;
        }
-out_put:
-       fdput(f);
        return err;
 }
 
index 4a4a22a08ac20df0e2cbe4b242d47eb4bc630faa..f0db1e724262821309a9c2ae92f0fc3d6fe69aaa 100644 (file)
@@ -2503,26 +2503,22 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
                }
        } else {
                /* Caller must check execute permissions on the starting path component */
-               struct fd f = fdget_raw(nd->dfd);
+               CLASS(fd_raw, f)(nd->dfd);
                struct dentry *dentry;
 
-               if (!fd_file(f))
+               if (fd_empty(f))
                        return ERR_PTR(-EBADF);
 
                if (flags & LOOKUP_LINKAT_EMPTY) {
                        if (fd_file(f)->f_cred != current_cred() &&
-                           !ns_capable(fd_file(f)->f_cred->user_ns, CAP_DAC_READ_SEARCH)) {
-                               fdput(f);
+                           !ns_capable(fd_file(f)->f_cred->user_ns, CAP_DAC_READ_SEARCH))
                                return ERR_PTR(-ENOENT);
-                       }
                }
 
                dentry = fd_file(f)->f_path.dentry;
 
-               if (*s && unlikely(!d_can_lookup(dentry))) {
-                       fdput(f);
+               if (*s && unlikely(!d_can_lookup(dentry)))
                        return ERR_PTR(-ENOTDIR);
-               }
 
                nd->path = fd_file(f)->f_path;
                if (flags & LOOKUP_RCU) {
@@ -2532,7 +2528,6 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
                        path_get(&nd->path);
                        nd->inode = nd->path.dentry->d_inode;
                }
-               fdput(f);
        }
 
        /* For scoped-lookups we need to set the root to the dirfd as well. */
index acaeb3e25c88ecdd635619872eea8ebe23622349..a0c1fa3f60d5fd5c13527f551e7965707de7f30d 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -580,23 +580,18 @@ out:
 
 SYSCALL_DEFINE1(fchdir, unsigned int, fd)
 {
-       struct fd f = fdget_raw(fd);
+       CLASS(fd_raw, f)(fd);
        int error;
 
-       error = -EBADF;
-       if (!fd_file(f))
-               goto out;
+       if (fd_empty(f))
+               return -EBADF;
 
-       error = -ENOTDIR;
        if (!d_can_lookup(fd_file(f)->f_path.dentry))
-               goto out_putf;
+               return -ENOTDIR;
 
        error = file_permission(fd_file(f), MAY_EXEC | MAY_CHDIR);
        if (!error)
                set_fs_pwd(current->fs, &fd_file(f)->f_path);
-out_putf:
-       fdput(f);
-out:
        return error;
 }
 
index 290157bc7bec2c8101713471510d248865a5bd38..7c2b75a4448528ca3ed92ca384f9375208d84e8e 100644 (file)
@@ -976,21 +976,19 @@ SYSCALL_DEFINE4(quotactl_fd, unsigned int, fd, unsigned int, cmd,
        struct super_block *sb;
        unsigned int cmds = cmd >> SUBCMDSHIFT;
        unsigned int type = cmd & SUBCMDMASK;
-       struct fd f;
+       CLASS(fd_raw, f)(fd);
        int ret;
 
-       f = fdget_raw(fd);
-       if (!fd_file(f))
+       if (fd_empty(f))
                return -EBADF;
 
-       ret = -EINVAL;
        if (type >= MAXQUOTAS)
-               goto out;
+               return -EINVAL;
 
        if (quotactl_cmd_write(cmds)) {
                ret = mnt_want_write(fd_file(f)->f_path.mnt);
                if (ret)
-                       goto out;
+                       return ret;
        }
 
        sb = fd_file(f)->f_path.mnt->mnt_sb;
@@ -1008,7 +1006,5 @@ SYSCALL_DEFINE4(quotactl_fd, unsigned int, fd, unsigned int, cmd,
 
        if (quotactl_cmd_write(cmds))
                mnt_drop_write(fd_file(f)->f_path.mnt);
-out:
-       fdput(f);
        return ret;
 }
index 9c7bb27e79324e1f484363708ddd98d248426f9d..a45ac85e6048681c726b61a8b06ed516617cd916 100644 (file)
@@ -114,13 +114,11 @@ retry:
 
 int fd_statfs(int fd, struct kstatfs *st)
 {
-       struct fd f = fdget_raw(fd);
-       int error = -EBADF;
-       if (fd_file(f)) {
-               error = vfs_statfs(&fd_file(f)->f_path, st);
-               fdput(f);
-       }
-       return error;
+       CLASS(fd_raw, f)(fd);
+
+       if (fd_empty(f))
+               return -EBADF;
+       return vfs_statfs(&fd_file(f)->f_path, st);
 }
 
 static int do_statfs_native(struct kstatfs *st, struct statfs __user *p)
index 5886b95c6eaee60e12d5035e4eee41964ed47e9a..8305a67ea8d99af2a9850fcafd15240ca0c0a5b8 100644 (file)
@@ -6966,14 +6966,11 @@ EXPORT_SYMBOL_GPL(cgroup_get_from_path);
  */
 struct cgroup *cgroup_v1v2_get_from_fd(int fd)
 {
-       struct cgroup *cgrp;
-       struct fd f = fdget_raw(fd);
-       if (!fd_file(f))
+       CLASS(fd_raw, f)(fd);
+       if (fd_empty(f))
                return ERR_PTR(-EBADF);
 
-       cgrp = cgroup_v1v2_get_from_file(fd_file(f));
-       fdput(f);
-       return cgrp;
+       return cgroup_v1v2_get_from_file(fd_file(f));
 }
 
 /**
index f5a0e7182ec0d8febc7ef37e2d1e7ad32536f84d..f32eb38abd0f3c0c9b80635f8f8133ebbc733258 100644 (file)
@@ -276,15 +276,12 @@ out_fdput:
  */
 static int get_path_from_fd(const s32 fd, struct path *const path)
 {
-       struct fd f;
-       int err = 0;
+       CLASS(fd_raw, f)(fd);
 
        BUILD_BUG_ON(!__same_type(
                fd, ((struct landlock_path_beneath_attr *)NULL)->parent_fd));
 
-       /* Handles O_PATH. */
-       f = fdget_raw(fd);
-       if (!fd_file(f))
+       if (fd_empty(f))
                return -EBADF;
        /*
         * Forbids ruleset FDs, internal filesystems (e.g. nsfs), including
@@ -295,16 +292,12 @@ static int get_path_from_fd(const s32 fd, struct path *const path)
            (fd_file(f)->f_path.mnt->mnt_flags & MNT_INTERNAL) ||
            (fd_file(f)->f_path.dentry->d_sb->s_flags & SB_NOUSER) ||
            d_is_negative(fd_file(f)->f_path.dentry) ||
-           IS_PRIVATE(d_backing_inode(fd_file(f)->f_path.dentry))) {
-               err = -EBADFD;
-               goto out_fdput;
-       }
+           IS_PRIVATE(d_backing_inode(fd_file(f)->f_path.dentry)))
+               return -EBADFD;
+
        *path = fd_file(f)->f_path;
        path_get(path);
-
-out_fdput:
-       fdput(f);
-       return err;
+       return 0;
 }
 
 static int add_rule_path_beneath(struct landlock_ruleset *const ruleset,