Commit cb01621b authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Andrii Nakryiko

bpf: Use struct_size()

Use struct_size() instead of hand writing it.
This is less verbose and more robust.
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Acked-by: default avatarYonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/bpf/20240429121323.3818497-1-andriy.shevchenko@linux.intel.com
parent 397658dd
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <linux/bpf.h> #include <linux/bpf.h>
#include <linux/btf.h> #include <linux/btf.h>
#include <linux/objtool.h> #include <linux/objtool.h>
#include <linux/overflow.h>
#include <linux/rbtree_latch.h> #include <linux/rbtree_latch.h>
#include <linux/kallsyms.h> #include <linux/kallsyms.h>
#include <linux/rcupdate.h> #include <linux/rcupdate.h>
...@@ -2455,13 +2456,14 @@ EXPORT_SYMBOL(bpf_empty_prog_array); ...@@ -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 *bpf_prog_array_alloc(u32 prog_cnt, gfp_t flags)
{ {
struct bpf_prog_array *p;
if (prog_cnt) if (prog_cnt)
return kzalloc(sizeof(struct bpf_prog_array) + p = kzalloc(struct_size(p, items, prog_cnt + 1), flags);
sizeof(struct bpf_prog_array_item) * else
(prog_cnt + 1), p = &bpf_empty_prog_array.hdr;
flags);
return &bpf_empty_prog_array.hdr; return p;
} }
void bpf_prog_array_free(struct bpf_prog_array *progs) void bpf_prog_array_free(struct bpf_prog_array *progs)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment