Skip to content

Commit

Permalink
bpf/tests: Use struct_size()
Browse files Browse the repository at this point in the history
Use struct_size() instead of hand writing it. This is less verbose and
more informative.

Signed-off-by: Su Hui <suhui@nfschina.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20230531043251.989312-1-suhui@nfschina.com
  • Loading branch information
Su Hui authored and Daniel Borkmann committed May 31, 2023
1 parent e38096d commit 0d2da4b
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions lib/test_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -15056,8 +15056,7 @@ static __init int prepare_tail_call_tests(struct bpf_array **pprogs)
int which, err;

/* Allocate the table of programs to be used for tall calls */
progs = kzalloc(sizeof(*progs) + (ntests + 1) * sizeof(progs->ptrs[0]),
GFP_KERNEL);
progs = kzalloc(struct_size(progs, ptrs, ntests + 1), GFP_KERNEL);
if (!progs)
goto out_nomem;

Expand Down

0 comments on commit 0d2da4b

Please sign in to comment.