Skip to contentSkip to conversation

selftests/bpf: Fix incorrect array size calculation

PATCH Superseded Jiayuan Chen 2 participants 2 messages Sep 9, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/bpf: Fix incorrect array size calculation

Fix it by using ARRAY_SIZE.

---
 tools/testing/selftests/bpf/benchs/bench_sockmap.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/benchs/bench_sockmap.c +3 -2
index 8ebf563a67a2..cfc072aa7fff 100644
@@ -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

Signature · 1 line
2.43.0
#1 lore raw
Quoted 2 lines · Jiayuan Chen

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