[PATCH] selftests/bpf: Fix incorrect array size calculation

Jiayuan Chen posted 1 patch 3 weeks, 2 days ago
There is a newer version of this series
tools/testing/selftests/bpf/benchs/bench_sockmap.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
[PATCH] selftests/bpf: Fix incorrect array size calculation
Posted by Jiayuan Chen 3 weeks, 2 days ago
Fix it by using ARRAY_SIZE.

Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/bpf/aLqfWuRR9R_KTe5e@stanley.mountain/
---
 tools/testing/selftests/bpf/benchs/bench_sockmap.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/benchs/bench_sockmap.c b/tools/testing/selftests/bpf/benchs/bench_sockmap.c
index 8ebf563a67a2..cfc072aa7fff 100644
--- a/tools/testing/selftests/bpf/benchs/bench_sockmap.c
+++ b/tools/testing/selftests/bpf/benchs/bench_sockmap.c
@@ -10,6 +10,7 @@
 #include <argp.h>
 #include "bench.h"
 #include "bench_sockmap_prog.skel.h"
+#include "bpf_util.h"
 
 #define FILE_SIZE (128 * 1024)
 #define DATA_REPEAT_SIZE 10
@@ -124,8 +125,8 @@ static void bench_sockmap_prog_destroy(void)
 {
 	int i;
 
-	for (i = 0; i < sizeof(ctx.fds); i++) {
-		if (ctx.fds[0] > 0)
+	for (i = 0; i < ARRAY_SIZE(ctx.fds); i++) {
+		if (ctx.fds[i] > 0)
 			close(ctx.fds[i]);
 	}
 

base-commit: 60ef54156148ffaa719845bc5b1fdeafa67763fc
-- 
2.43.0
Re: [PATCH] selftests/bpf: Fix incorrect array size calculation
Posted by Alexei Starovoitov 3 weeks, 2 days ago
On Mon, Sep 8, 2025 at 7:31 PM Jiayuan Chen <jiayuan.chen@linux.dev> wrote:
>
> Fix it by using ARRAY_SIZE.

Fix what ?
The commit log should be clear on its own and shouldn't require
people clicking through the links.

pw-bot: cr