selftests/bpf: Fix return value checks in perf_event_stackmap.c
Subsystems (5)
PATCH 1/1 selftests/bpf: Fix return value checks in perf_event_stackmap.c
The bpf_get_stackid() function may also return 0 on success.
--- tools/testing/selftests/bpf/progs/perf_event_stackmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/progs/perf_event_stackmap.c +2 -2
@@ -35,10 +35,10 @@ int oncpu(void *ctx)long val; val =bpf_get_stackid (ctx, &stackmap,0 ); -if (val >0 ) +if (val >=0 ) stackid_kernel =2 ; val =bpf_get_stackid (ctx, &stackmap,BPF_F_USER_STACK ); -if (val >0 ) +if (val >=0 ) stackid_user =2 ; trace =bpf_map_lookup_elem (&stackdata_map, &key);
Signature · 1 line
2.35.1
Quoted 1 line · Yuntao Wang
The
bpf_get_stackid()function may also return 0 on success.
Can you add couple of sentences to describe what this patch does? bpf_get_stackid() may also return doesn't really say anything about why this patch is needed.
Quoted 14 lines
Signed-off-by Yuntao Wang <[email protected]>--- tools/testing/selftests/bpf/progs/perf_event_stackmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/testing/selftests/bpf/progs/perf_event_stackmap.c +0
-0@@ -35,10 +35,10 @@ int oncpu(void *ctx)long val;
tools/testing/selftests/bpf/progs/perf_event_stackmap.c int oncpu(void *ctx) · line 44
Quoted 10 lines
tools/testing/selftests/bpf/progs/perf_event_stackmap.c +2
-2val =bpf_get_stackid (ctx, &stackmap,0 ); -if (val >0 ) +if (val >=0 ) stackid_kernel =2 ; val =bpf_get_stackid (ctx, &stackmap,BPF_F_USER_STACK ); -if (val >0 ) +if (val >=0 ) stackid_user =2 ; trace =bpf_map_lookup_elem (&stackdata_map, &key);
Linux 5.18-rc1 shows a couple of more bpf_get_stackid() in this function. Removed in bpf-next - I assume.
The change is good. I would like to see it explained better in the commit log.
With the commit log fixed to explain why this change is needed and what happens if val equals to 0 condition isn't checked:
thanks,
-- Shuah
PATCH v2 1/1 selftests/bpf: Fix return value checks in perf_event_stackmap.c
The bpf_get_stackid() function may also return 0 on success.
Correct checks from 'val > 0' to 'val >= 0' to ensure that they cover all possible success return values.
---
v1 -> v2: update commit message
tools/testing/selftests/bpf/progs/perf_event_stackmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/progs/perf_event_stackmap.c +2 -2
@@ -35,10 +35,10 @@ int oncpu(void *ctx)long val; val =bpf_get_stackid (ctx, &stackmap,0 ); -if (val >0 ) +if (val >=0 ) stackid_kernel =2 ; val =bpf_get_stackid (ctx, &stackmap,BPF_F_USER_STACK ); -if (val >0 ) +if (val >=0 ) stackid_user =2 ; trace =bpf_map_lookup_elem (&stackdata_map, &key);
Signature · 1 line
2.35.0.rc2
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Quoted 8 lines · On Fri, 8 Apr 2022 12:14:52 +0800 you wrote:
The
bpf_get_stackid()function may also return 0 on success.Correct checks from 'val > 0' to 'val >= 0' to ensure that they cover all possible success return values.
Signed-off-by Yuntao Wang <[email protected]>[...]
Here is the summary with links:
- [bpf-next,v2] selftests/bpf: Fix return value checks in perf_event_stackmap.c
https://git.kernel.org/bpf/bpf-next/c/658d87687cd5
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html