2023-05-31 05:25:38

by Su Hui

[permalink] [raw]
Subject: [PATCH] bpf/tests: Use struct_size()

Use struct_size() instead of hand writing it.
This is less verbose and more informative.

Signed-off-by: Su Hui <[email protected]>
---
lib/test_bpf.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lib/test_bpf.c b/lib/test_bpf.c
index ade9ac672adb..fa0833410ac1 100644
--- a/lib/test_bpf.c
+++ b/lib/test_bpf.c
@@ -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;

--
2.30.2



2023-05-31 06:20:00

by Yonghong Song

[permalink] [raw]
Subject: Re: [PATCH] bpf/tests: Use struct_size()



On 5/30/23 9:32 PM, Su Hui wrote:
> Use struct_size() instead of hand writing it.
> This is less verbose and more informative.
>
> Signed-off-by: Su Hui <[email protected]>

Acked-by: Yonghong Song <[email protected]>

2023-05-31 11:31:45

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH] bpf/tests: Use struct_size()

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <[email protected]>:

On Wed, 31 May 2023 12:32:51 +0800 you wrote:
> Use struct_size() instead of hand writing it.
> This is less verbose and more informative.
>
> Signed-off-by: Su Hui <[email protected]>
> ---
> lib/test_bpf.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)

Here is the summary with links:
- bpf/tests: Use struct_size()
https://git.kernel.org/bpf/bpf-next/c/0d2da4b595d0

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html