Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/bpf: Fix incorrect array size calculation

The loop in bench_sockmap_prog_destroy() has two issues:

1. Using 'sizeof(ctx.fds)' as the loop bound results in the number of
bytes, not the number of file descriptors, causing the loop to iterate
far more times than intended.

2. The condition 'ctx.fds[0] > 0' incorrectly checks only the first fd for
all iterations, potentially leaving file descriptors unclosed. Change
it to 'ctx.fds[i] > 0' to check each fd properly.

These fixes ensure correct cleanup of all file descriptors when the
benchmark exits.

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20250909124721.191555-1-jiayuan.chen@linux.dev

Closes: https://lore.kernel.org/bpf/aLqfWuRR9R_KTe5e@stanley.mountain/

authored by

Jiayuan Chen and committed by
Andrii Nakryiko
f8598132 60ef5415

+3 -2
+3 -2
tools/testing/selftests/bpf/benchs/bench_sockmap.c
··· 10 10 #include <argp.h> 11 11 #include "bench.h" 12 12 #include "bench_sockmap_prog.skel.h" 13 + #include "bpf_util.h" 13 14 14 15 #define FILE_SIZE (128 * 1024) 15 16 #define DATA_REPEAT_SIZE 10 ··· 125 124 { 126 125 int i; 127 126 128 - for (i = 0; i < sizeof(ctx.fds); i++) { 129 - if (ctx.fds[0] > 0) 127 + for (i = 0; i < ARRAY_SIZE(ctx.fds); i++) { 128 + if (ctx.fds[i] > 0) 130 129 close(ctx.fds[i]); 131 130 } 132 131