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>
This commit is contained in:
+9
-22
@@ -2407,18 +2407,6 @@ int bpf_prog_new_fd(struct bpf_prog *prog)
|
|||||||
O_RDWR | O_CLOEXEC);
|
O_RDWR | O_CLOEXEC);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct bpf_prog *____bpf_prog_get(struct fd f)
|
|
||||||
{
|
|
||||||
if (!fd_file(f))
|
|
||||||
return ERR_PTR(-EBADF);
|
|
||||||
if (fd_file(f)->f_op != &bpf_prog_fops) {
|
|
||||||
fdput(f);
|
|
||||||
return ERR_PTR(-EINVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
return fd_file(f)->private_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void bpf_prog_add(struct bpf_prog *prog, int i)
|
void bpf_prog_add(struct bpf_prog *prog, int i)
|
||||||
{
|
{
|
||||||
atomic64_add(i, &prog->aux->refcnt);
|
atomic64_add(i, &prog->aux->refcnt);
|
||||||
@@ -2474,20 +2462,19 @@ bool bpf_prog_get_ok(struct bpf_prog *prog,
|
|||||||
static struct bpf_prog *__bpf_prog_get(u32 ufd, enum bpf_prog_type *attach_type,
|
static struct bpf_prog *__bpf_prog_get(u32 ufd, enum bpf_prog_type *attach_type,
|
||||||
bool attach_drv)
|
bool attach_drv)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(ufd);
|
CLASS(fd, f)(ufd);
|
||||||
struct bpf_prog *prog;
|
struct bpf_prog *prog;
|
||||||
|
|
||||||
prog = ____bpf_prog_get(f);
|
if (fd_empty(f))
|
||||||
if (IS_ERR(prog))
|
return ERR_PTR(-EBADF);
|
||||||
return prog;
|
if (fd_file(f)->f_op != &bpf_prog_fops)
|
||||||
if (!bpf_prog_get_ok(prog, attach_type, attach_drv)) {
|
return ERR_PTR(-EINVAL);
|
||||||
prog = ERR_PTR(-EINVAL);
|
|
||||||
goto out;
|
prog = fd_file(f)->private_data;
|
||||||
}
|
if (!bpf_prog_get_ok(prog, attach_type, attach_drv))
|
||||||
|
return ERR_PTR(-EINVAL);
|
||||||
|
|
||||||
bpf_prog_inc(prog);
|
bpf_prog_inc(prog);
|
||||||
out:
|
|
||||||
fdput(f);
|
|
||||||
return prog;
|
return prog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user