Skip to content

Commit d719737

Browse files
Al Viroanakryiko
authored andcommitted
bpf: convert __bpf_prog_get() to CLASS(fd, ...)
Irregularity here is fdput() not in the same scope as fdget(); just fold ____bpf_prog_get() into its (only) caller and that's it... Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Acked-by: Andrii Nakryiko <andrii@kernel.org> Reviewed-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
1 parent 50470d3 commit d719737

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

kernel/bpf/syscall.c

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,18 +2407,6 @@ int bpf_prog_new_fd(struct bpf_prog *prog)
24072407
O_RDWR | O_CLOEXEC);
24082408
}
24092409

2410-
static struct bpf_prog *____bpf_prog_get(struct fd f)
2411-
{
2412-
if (!fd_file(f))
2413-
return ERR_PTR(-EBADF);
2414-
if (fd_file(f)->f_op != &bpf_prog_fops) {
2415-
fdput(f);
2416-
return ERR_PTR(-EINVAL);
2417-
}
2418-
2419-
return fd_file(f)->private_data;
2420-
}
2421-
24222410
void bpf_prog_add(struct bpf_prog *prog, int i)
24232411
{
24242412
atomic64_add(i, &prog->aux->refcnt);
@@ -2474,20 +2462,19 @@ bool bpf_prog_get_ok(struct bpf_prog *prog,
24742462
static struct bpf_prog *__bpf_prog_get(u32 ufd, enum bpf_prog_type *attach_type,
24752463
bool attach_drv)
24762464
{
2477-
struct fd f = fdget(ufd);
2465+
CLASS(fd, f)(ufd);
24782466
struct bpf_prog *prog;
24792467

2480-
prog = ____bpf_prog_get(f);
2481-
if (IS_ERR(prog))
2482-
return prog;
2483-
if (!bpf_prog_get_ok(prog, attach_type, attach_drv)) {
2484-
prog = ERR_PTR(-EINVAL);
2485-
goto out;
2486-
}
2468+
if (fd_empty(f))
2469+
return ERR_PTR(-EBADF);
2470+
if (fd_file(f)->f_op != &bpf_prog_fops)
2471+
return ERR_PTR(-EINVAL);
2472+
2473+
prog = fd_file(f)->private_data;
2474+
if (!bpf_prog_get_ok(prog, attach_type, attach_drv))
2475+
return ERR_PTR(-EINVAL);
24872476

24882477
bpf_prog_inc(prog);
2489-
out:
2490-
fdput(f);
24912478
return prog;
24922479
}
24932480

0 commit comments

Comments
 (0)