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:
parent
55f325958c
commit
eb80ee8580
@ -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_get_by_fd(int fd)
|
||||||
{
|
{
|
||||||
struct btf *btf;
|
struct btf *btf;
|
||||||
struct fd f;
|
CLASS(fd, f)(fd);
|
||||||
|
|
||||||
f = fdget(fd);
|
if (fd_empty(f))
|
||||||
|
|
||||||
if (!fd_file(f))
|
|
||||||
return ERR_PTR(-EBADF);
|
return ERR_PTR(-EBADF);
|
||||||
|
|
||||||
if (fd_file(f)->f_op != &btf_fops) {
|
if (fd_file(f)->f_op != &btf_fops)
|
||||||
fdput(f);
|
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
|
||||||
|
|
||||||
btf = fd_file(f)->private_data;
|
btf = fd_file(f)->private_data;
|
||||||
refcount_inc(&btf->refcnt);
|
refcount_inc(&btf->refcnt);
|
||||||
fdput(f);
|
|
||||||
|
|
||||||
return btf;
|
return btf;
|
||||||
}
|
}
|
||||||
|
@ -3187,20 +3187,16 @@ int bpf_link_new_fd(struct bpf_link *link)
|
|||||||
|
|
||||||
struct bpf_link *bpf_link_get_from_fd(u32 ufd)
|
struct bpf_link *bpf_link_get_from_fd(u32 ufd)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(ufd);
|
CLASS(fd, f)(ufd);
|
||||||
struct bpf_link *link;
|
struct bpf_link *link;
|
||||||
|
|
||||||
if (!fd_file(f))
|
if (fd_empty(f))
|
||||||
return ERR_PTR(-EBADF);
|
return ERR_PTR(-EBADF);
|
||||||
if (fd_file(f)->f_op != &bpf_link_fops && fd_file(f)->f_op != &bpf_link_fops_poll) {
|
if (fd_file(f)->f_op != &bpf_link_fops && fd_file(f)->f_op != &bpf_link_fops_poll)
|
||||||
fdput(f);
|
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
|
||||||
|
|
||||||
link = fd_file(f)->private_data;
|
link = fd_file(f)->private_data;
|
||||||
bpf_link_inc(link);
|
bpf_link_inc(link);
|
||||||
fdput(f);
|
|
||||||
|
|
||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(bpf_link_get_from_fd);
|
EXPORT_SYMBOL(bpf_link_get_from_fd);
|
||||||
|
@ -232,19 +232,16 @@ out_path:
|
|||||||
|
|
||||||
struct bpf_token *bpf_token_get_from_fd(u32 ufd)
|
struct bpf_token *bpf_token_get_from_fd(u32 ufd)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(ufd);
|
CLASS(fd, f)(ufd);
|
||||||
struct bpf_token *token;
|
struct bpf_token *token;
|
||||||
|
|
||||||
if (!fd_file(f))
|
if (fd_empty(f))
|
||||||
return ERR_PTR(-EBADF);
|
return ERR_PTR(-EBADF);
|
||||||
if (fd_file(f)->f_op != &bpf_token_fops) {
|
if (fd_file(f)->f_op != &bpf_token_fops)
|
||||||
fdput(f);
|
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
|
||||||
|
|
||||||
token = fd_file(f)->private_data;
|
token = fd_file(f)->private_data;
|
||||||
bpf_token_inc(token);
|
bpf_token_inc(token);
|
||||||
fdput(f);
|
|
||||||
|
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user