Skip to content

Commit eb80ee8

Browse files
Al Viroanakryiko
authored andcommitted
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>
1 parent 55f3259 commit eb80ee8

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

kernel/bpf/btf.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7676,21 +7676,16 @@ int btf_new_fd(const union bpf_attr *attr, bpfptr_t uattr, u32 uattr_size)
76767676
struct btf *btf_get_by_fd(int fd)
76777677
{
76787678
struct btf *btf;
7679-
struct fd f;
7679+
CLASS(fd, f)(fd);
76807680

7681-
f = fdget(fd);
7682-
7683-
if (!fd_file(f))
7681+
if (fd_empty(f))
76847682
return ERR_PTR(-EBADF);
76857683

7686-
if (fd_file(f)->f_op != &btf_fops) {
7687-
fdput(f);
7684+
if (fd_file(f)->f_op != &btf_fops)
76887685
return ERR_PTR(-EINVAL);
7689-
}
76907686

76917687
btf = fd_file(f)->private_data;
76927688
refcount_inc(&btf->refcnt);
7693-
fdput(f);
76947689

76957690
return btf;
76967691
}

kernel/bpf/syscall.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3187,20 +3187,16 @@ int bpf_link_new_fd(struct bpf_link *link)
31873187

31883188
struct bpf_link *bpf_link_get_from_fd(u32 ufd)
31893189
{
3190-
struct fd f = fdget(ufd);
3190+
CLASS(fd, f)(ufd);
31913191
struct bpf_link *link;
31923192

3193-
if (!fd_file(f))
3193+
if (fd_empty(f))
31943194
return ERR_PTR(-EBADF);
3195-
if (fd_file(f)->f_op != &bpf_link_fops && fd_file(f)->f_op != &bpf_link_fops_poll) {
3196-
fdput(f);
3195+
if (fd_file(f)->f_op != &bpf_link_fops && fd_file(f)->f_op != &bpf_link_fops_poll)
31973196
return ERR_PTR(-EINVAL);
3198-
}
31993197

32003198
link = fd_file(f)->private_data;
32013199
bpf_link_inc(link);
3202-
fdput(f);
3203-
32043200
return link;
32053201
}
32063202
EXPORT_SYMBOL(bpf_link_get_from_fd);

kernel/bpf/token.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,19 +232,16 @@ int bpf_token_create(union bpf_attr *attr)
232232

233233
struct bpf_token *bpf_token_get_from_fd(u32 ufd)
234234
{
235-
struct fd f = fdget(ufd);
235+
CLASS(fd, f)(ufd);
236236
struct bpf_token *token;
237237

238-
if (!fd_file(f))
238+
if (fd_empty(f))
239239
return ERR_PTR(-EBADF);
240-
if (fd_file(f)->f_op != &bpf_token_fops) {
241-
fdput(f);
240+
if (fd_file(f)->f_op != &bpf_token_fops)
242241
return ERR_PTR(-EINVAL);
243-
}
244242

245243
token = fd_file(f)->private_data;
246244
bpf_token_inc(token);
247-
fdput(f);
248245

249246
return token;
250247
}

0 commit comments

Comments
 (0)