Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>

authored by

Al Viro and committed by
Andrii Nakryiko
eceb7b33 eb80ee85

+7 -15
+7 -15
kernel/bpf/syscall.c
··· 4901 4901 static int bpf_obj_get_info_by_fd(const union bpf_attr *attr, 4902 4902 union bpf_attr __user *uattr) 4903 4903 { 4904 - int ufd = attr->info.bpf_fd; 4905 - struct fd f; 4906 - int err; 4907 - 4908 4904 if (CHECK_ATTR(BPF_OBJ_GET_INFO_BY_FD)) 4909 4905 return -EINVAL; 4910 4906 4911 - f = fdget(ufd); 4912 - if (!fd_file(f)) 4907 + CLASS(fd, f)(attr->info.bpf_fd); 4908 + if (fd_empty(f)) 4913 4909 return -EBADFD; 4914 4910 4915 4911 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, 4917 4913 uattr); 4918 4914 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, 4920 4916 uattr); 4921 4917 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); 4923 4919 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, 4925 4921 attr, uattr); 4926 - else 4927 - err = -EINVAL; 4928 - 4929 - fdput(f); 4930 - return err; 4922 + return -EINVAL; 4931 4923 } 4932 4924 4933 4925 #define BPF_BTF_LOAD_LAST_FIELD btf_token_fd