selftests/bpf: Fix the issue where the error code is 0
Subsystems (3)
PATCH v3 1/1 selftests/bpf: Fix the issue where the error code is 0
From: Feng Yang <[email protected]>
The error message printed here only uses the previous err value, which results in it being printed as 0.
When bpf_map__attach_struct_ops encounters an error,
it uses libbpf_err_ptr(err) to set errno = -err and returns NULL. Therefore, Using -errno can fix this issue.
Fix before:
run_subtest:FAIL:1019 bpf_map__attach_struct_ops failed for map pro_epilogue: err=0
Fix after:
run_subtest:FAIL:1019 bpf_map__attach_struct_ops failed for map pro_epilogue: err=-9
---
Changes in v3:
- Use -errno here directly, thanks: Andrii Nakryiko.
- Link to v2: https://lore.kernel.org/all/[email protected]/
---
Changes in v2:
- Use libbpf_get_error, thanks: Alexei Starovoitov.
- Link to v1: https://lore.kernel.org/all/[email protected]/
--- tools/testing/selftests/bpf/test_loader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/test_loader.c +1 -1
@@ -1083,7 +1083,7 @@ void run_subtest(struct test_loader *tester, link =bpf_map__attach_struct_ops (map);if (!link) {PRINT_FAIL ("bpf_map__attach_struct_ops failed for map %s: err=%d\n" , -bpf_map__name (map), err); +bpf_map__name (map), -errno); goto tobj_cleanup; } links[links_cnt++] = link;
Signature · 1 line
2.25.1
This patch was applied to bpf/bpf-next.git (master) by Martin KaFai Lau <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Martin KaFai Lau <[email protected]>:
Quoted 9 lines · On Mon, 8 Sep 2025 14:08:10 +0800 you wrote:
From: Feng Yang <[email protected]>
The error message printed here only uses the previous err value, which results in it being printed as 0.
Whenbpf_map__attach_struct_opsencounters an error,
it useslibbpf_err_ptr(err)to set errno = -err and returns NULL. Therefore, Using -errno can fix this issue.[...]
Here is the summary with links:
- [v3,bpf-next] selftests/bpf: Fix the issue where the error code is 0
https://git.kernel.org/bpf/bpf-next/c/93a83d044314
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html