diff options
author | Daniel Borkmann <daniel@iogearbox.net> | 2015-10-29 09:58:06 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-11-02 22:48:39 -0500 |
commit | aa79781b65b9cf79807ade78f2703f5e9402c336 (patch) | |
tree | 7b2eaa26b26f7c59283b87b6c44a5855dd249273 /kernel/bpf/syscall.c | |
parent | 1d6119baf0610f813eb9d9580eb4fd16de5b4ceb (diff) |
bpf: abstract anon_inode_getfd invocations
Since we're going to use anon_inode_getfd() invocations in more than just
the current places, make a helper function for both, so that we only need
to pass a map/prog pointer to the helper itself in order to get a fd. The
new helpers are called bpf_map_new_fd() and bpf_prog_new_fd().
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'kernel/bpf/syscall.c')
-rw-r--r-- | kernel/bpf/syscall.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 687dd6ca574d..2b89ef0a9757 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c | |||
@@ -111,6 +111,12 @@ static const struct file_operations bpf_map_fops = { | |||
111 | .release = bpf_map_release, | 111 | .release = bpf_map_release, |
112 | }; | 112 | }; |
113 | 113 | ||
114 | static int bpf_map_new_fd(struct bpf_map *map) | ||
115 | { | ||
116 | return anon_inode_getfd("bpf-map", &bpf_map_fops, map, | ||
117 | O_RDWR | O_CLOEXEC); | ||
118 | } | ||
119 | |||
114 | /* helper macro to check that unused fields 'union bpf_attr' are zero */ | 120 | /* helper macro to check that unused fields 'union bpf_attr' are zero */ |
115 | #define CHECK_ATTR(CMD) \ | 121 | #define CHECK_ATTR(CMD) \ |
116 | memchr_inv((void *) &attr->CMD##_LAST_FIELD + \ | 122 | memchr_inv((void *) &attr->CMD##_LAST_FIELD + \ |
@@ -141,8 +147,7 @@ static int map_create(union bpf_attr *attr) | |||
141 | if (err) | 147 | if (err) |
142 | goto free_map; | 148 | goto free_map; |
143 | 149 | ||
144 | err = anon_inode_getfd("bpf-map", &bpf_map_fops, map, O_RDWR | O_CLOEXEC); | 150 | err = bpf_map_new_fd(map); |
145 | |||
146 | if (err < 0) | 151 | if (err < 0) |
147 | /* failed to allocate fd */ | 152 | /* failed to allocate fd */ |
148 | goto free_map; | 153 | goto free_map; |
@@ -538,6 +543,12 @@ static const struct file_operations bpf_prog_fops = { | |||
538 | .release = bpf_prog_release, | 543 | .release = bpf_prog_release, |
539 | }; | 544 | }; |
540 | 545 | ||
546 | static int bpf_prog_new_fd(struct bpf_prog *prog) | ||
547 | { | ||
548 | return anon_inode_getfd("bpf-prog", &bpf_prog_fops, prog, | ||
549 | O_RDWR | O_CLOEXEC); | ||
550 | } | ||
551 | |||
541 | static struct bpf_prog *get_prog(struct fd f) | 552 | static struct bpf_prog *get_prog(struct fd f) |
542 | { | 553 | { |
543 | struct bpf_prog *prog; | 554 | struct bpf_prog *prog; |
@@ -647,7 +658,7 @@ static int bpf_prog_load(union bpf_attr *attr) | |||
647 | if (err < 0) | 658 | if (err < 0) |
648 | goto free_used_maps; | 659 | goto free_used_maps; |
649 | 660 | ||
650 | err = anon_inode_getfd("bpf-prog", &bpf_prog_fops, prog, O_RDWR | O_CLOEXEC); | 661 | err = bpf_prog_new_fd(prog); |
651 | if (err < 0) | 662 | if (err < 0) |
652 | /* failed to allocate fd */ | 663 | /* failed to allocate fd */ |
653 | goto free_used_maps; | 664 | goto free_used_maps; |