[PATCH] bpf/tests: Use struct_size()

Su Hui posted 1 patch 2 years, 8 months ago
lib/test_bpf.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
[PATCH] bpf/tests: Use struct_size()
Posted by Su Hui 2 years, 8 months ago
Use struct_size() instead of hand writing it.
This is less verbose and more informative.

Signed-off-by: Su Hui <suhui@nfschina.com>
---
 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
Re: [PATCH] bpf/tests: Use struct_size()
Posted by patchwork-bot+netdevbpf@kernel.org 2 years, 8 months ago
Hello:

This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

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 <suhui@nfschina.com>
> ---
>  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
Re: [PATCH] bpf/tests: Use struct_size()
Posted by Yonghong Song 2 years, 8 months ago

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 <suhui@nfschina.com>

Acked-by: Yonghong Song <yhs@fb.com>