Skip to content

Commit eceb7b3

Browse files
Al Viroanakryiko
Al Viro
authored andcommitted
bpf: more trivial fdget() conversions
All failure exits prior to fdget() leave the scope, all matching fdput() are immediately followed by leaving the scope. Reviewed-by: Christian Brauner <[email protected]> Signed-off-by: Al Viro <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]>
1 parent eb80ee8 commit eceb7b3

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

kernel/bpf/syscall.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4901,33 +4901,25 @@ static int bpf_link_get_info_by_fd(struct file *file,
49014901
static int bpf_obj_get_info_by_fd(const union bpf_attr *attr,
49024902
union bpf_attr __user *uattr)
49034903
{
4904-
int ufd = attr->info.bpf_fd;
4905-
struct fd f;
4906-
int err;
4907-
49084904
if (CHECK_ATTR(BPF_OBJ_GET_INFO_BY_FD))
49094905
return -EINVAL;
49104906

4911-
f = fdget(ufd);
4912-
if (!fd_file(f))
4907+
CLASS(fd, f)(attr->info.bpf_fd);
4908+
if (fd_empty(f))
49134909
return -EBADFD;
49144910

49154911
if (fd_file(f)->f_op == &bpf_prog_fops)
4916-
err = bpf_prog_get_info_by_fd(fd_file(f), fd_file(f)->private_data, attr,
4912+
return bpf_prog_get_info_by_fd(fd_file(f), fd_file(f)->private_data, attr,
49174913
uattr);
49184914
else if (fd_file(f)->f_op == &bpf_map_fops)
4919-
err = bpf_map_get_info_by_fd(fd_file(f), fd_file(f)->private_data, attr,
4915+
return bpf_map_get_info_by_fd(fd_file(f), fd_file(f)->private_data, attr,
49204916
uattr);
49214917
else if (fd_file(f)->f_op == &btf_fops)
4922-
err = bpf_btf_get_info_by_fd(fd_file(f), fd_file(f)->private_data, attr, uattr);
4918+
return bpf_btf_get_info_by_fd(fd_file(f), fd_file(f)->private_data, attr, uattr);
49234919
else if (fd_file(f)->f_op == &bpf_link_fops || fd_file(f)->f_op == &bpf_link_fops_poll)
4924-
err = bpf_link_get_info_by_fd(fd_file(f), fd_file(f)->private_data,
4920+
return bpf_link_get_info_by_fd(fd_file(f), fd_file(f)->private_data,
49254921
attr, uattr);
4926-
else
4927-
err = -EINVAL;
4928-
4929-
fdput(f);
4930-
return err;
4922+
return -EINVAL;
49314923
}
49324924

49334925
#define BPF_BTF_LOAD_LAST_FIELD btf_token_fd

0 commit comments

Comments
 (0)