bpf: trivial conversions for fdget()

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>
This commit is contained in:
Al Viro
2024-08-13 14:34:10 -07:00
committed by Andrii Nakryiko
parent 55f325958c
commit eb80ee8580
3 changed files with 9 additions and 21 deletions
+3 -8
View 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;
}