* [PATCH bpf-next v2] selftests/bpf: Fix incorrect array size calculation
@ 2025-09-09 12:47 Jiayuan Chen
2025-09-09 16:30 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Jiayuan Chen @ 2025-09-09 12:47 UTC (permalink / raw)
To: jiayuan.chen
Cc: Dan Carpenter, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
Hao Luo, Jiri Olsa, Mykola Lysenko, Shuah Khan, Jiapeng Chong,
bpf, linux-kselftest, linux-kernel
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.
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]);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH bpf-next v2] selftests/bpf: Fix incorrect array size calculation
2025-09-09 12:47 [PATCH bpf-next v2] selftests/bpf: Fix incorrect array size calculation Jiayuan Chen
@ 2025-09-09 16:30 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-09-09 16:30 UTC (permalink / raw)
To: Jiayuan Chen
Cc: dan.carpenter, ast, daniel, andrii, martin.lau, eddyz87, song,
yonghong.song, john.fastabend, kpsingh, sdf, haoluo, jolsa,
mykolal, shuah, jiapeng.chong, bpf, linux-kselftest, linux-kernel
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:
On Tue, 9 Sep 2025 20:47:04 +0800 you wrote:
> 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.
>
> [...]
Here is the summary with links:
- [bpf-next,v2] selftests/bpf: Fix incorrect array size calculation
https://git.kernel.org/bpf/bpf-next/c/f85981327a90
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-09-09 16:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-09 12:47 [PATCH bpf-next v2] selftests/bpf: Fix incorrect array size calculation Jiayuan Chen
2025-09-09 16:30 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox