]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bpf: trivial conversions for fdget()
authorAl Viro <viro@zeniv.linux.org.uk>
Tue, 13 Aug 2024 21:34:10 +0000 (14:34 -0700)
committerAndrii Nakryiko <andrii@kernel.org>
Tue, 13 Aug 2024 22:58:21 +0000 (15:58 -0700)
fdget() is the first thing done in scope, all matching fdput() are
immediately followed by leaving the scope.

Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
kernel/bpf/btf.c
kernel/bpf/syscall.c
kernel/bpf/token.c

index e34f58abc7e2eb9ffcee84ea247414bec1a356d0..c4506d788c858060e60e31a40d9d88211abb1514 100644 (file)
@@ -7676,21 +7676,16 @@ int btf_new_fd(const union bpf_attr *attr, bpfptr_t uattr, u32 uattr_size)
 struct btf *btf_get_by_fd(int fd)
 {
        struct btf *btf;
-       struct fd f;
+       CLASS(fd, f)(fd);
 
-       f = fdget(fd);
-
-       if (!fd_file(f))
+       if (fd_empty(f))
                return ERR_PTR(-EBADF);
 
-       if (fd_file(f)->f_op != &btf_fops) {
-               fdput(f);
+       if (fd_file(f)->f_op != &btf_fops)
                return ERR_PTR(-EINVAL);
-       }
 
        btf = fd_file(f)->private_data;
        refcount_inc(&btf->refcnt);
-       fdput(f);
 
        return btf;
 }
index ab0d94f41c48b9042b46724104e8944fe50504c7..d75e4e68801e15f3b35c9b5fcbeb6ca073ccc134 100644 (file)
@@ -3187,20 +3187,16 @@ int bpf_link_new_fd(struct bpf_link *link)
 
 struct bpf_link *bpf_link_get_from_fd(u32 ufd)
 {
-       struct fd f = fdget(ufd);
+       CLASS(fd, f)(ufd);
        struct bpf_link *link;
 
-       if (!fd_file(f))
+       if (fd_empty(f))
                return ERR_PTR(-EBADF);
-       if (fd_file(f)->f_op != &bpf_link_fops && fd_file(f)->f_op != &bpf_link_fops_poll) {
-               fdput(f);
+       if (fd_file(f)->f_op != &bpf_link_fops && fd_file(f)->f_op != &bpf_link_fops_poll)
                return ERR_PTR(-EINVAL);
-       }
 
        link = fd_file(f)->private_data;
        bpf_link_inc(link);
-       fdput(f);
-
        return link;
 }
 EXPORT_SYMBOL(bpf_link_get_from_fd);
index 9a1d356e79ed2c2ba009fb5519d51a9ade848bab..9b92cb886d491b1f4536063a5a93d66a0cac3fa5 100644 (file)
@@ -232,19 +232,16 @@ out_path:
 
 struct bpf_token *bpf_token_get_from_fd(u32 ufd)
 {
-       struct fd f = fdget(ufd);
+       CLASS(fd, f)(ufd);
        struct bpf_token *token;
 
-       if (!fd_file(f))
+       if (fd_empty(f))
                return ERR_PTR(-EBADF);
-       if (fd_file(f)->f_op != &bpf_token_fops) {
-               fdput(f);
+       if (fd_file(f)->f_op != &bpf_token_fops)
                return ERR_PTR(-EINVAL);
-       }
 
        token = fd_file(f)->private_data;
        bpf_token_inc(token);
-       fdput(f);
 
        return token;
 }