diff options
author | Andy Shevchenko <andriy.shevchenko@linux.intel.com> | 2024-04-29 15:13:22 +0300 |
---|---|---|
committer | Andrii Nakryiko <andrii@kernel.org> | 2024-04-29 16:12:03 -0700 |
commit | cb01621b6d91567ac74c8b95e4db731febdbdec3 (patch) | |
tree | 824adabc8b3315962dc97d52a7dd79a93a3255e9 /kernel/bpf | |
parent | 397658ddc88ce3c21d2aa3bed8e15fc69dfec946 (diff) |
bpf: Use struct_size()
Use struct_size() instead of hand writing it.
This is less verbose and more robust.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/bpf/20240429121323.3818497-1-andriy.shevchenko@linux.intel.com
Diffstat (limited to 'kernel/bpf')
-rw-r--r-- | kernel/bpf/core.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 95c7fd093e55..a8ca6dd6e614 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -26,6 +26,7 @@ #include <linux/bpf.h> #include <linux/btf.h> #include <linux/objtool.h> +#include <linux/overflow.h> #include <linux/rbtree_latch.h> #include <linux/kallsyms.h> #include <linux/rcupdate.h> @@ -2455,13 +2456,14 @@ EXPORT_SYMBOL(bpf_empty_prog_array); struct bpf_prog_array *bpf_prog_array_alloc(u32 prog_cnt, gfp_t flags) { + struct bpf_prog_array *p; + if (prog_cnt) - return kzalloc(sizeof(struct bpf_prog_array) + - sizeof(struct bpf_prog_array_item) * - (prog_cnt + 1), - flags); + p = kzalloc(struct_size(p, items, prog_cnt + 1), flags); + else + p = &bpf_empty_prog_array.hdr; - return &bpf_empty_prog_array.hdr; + return p; } void bpf_prog_array_free(struct bpf_prog_array *progs) |