* [PATCH bpf-next] selftests/bpf: Fix the issue where the error code is 0
@ 2025-08-28 8:15 Feng Yang
2025-08-28 16:15 ` Alexei Starovoitov
0 siblings, 1 reply; 2+ messages in thread
From: Feng Yang @ 2025-08-28 8:15 UTC (permalink / raw)
To: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
yonghong.song, kpsingh, sdf, haoluo, jolsa
Cc: bpf, linux-kernel, linux-kselftest
From: Feng Yang <yangfeng@kylinos.cn>
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, strerror(errno) can be used to 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: Bad file descriptor
Signed-off-by: Feng Yang <yangfeng@kylinos.cn>
---
tools/testing/selftests/bpf/test_loader.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/test_loader.c b/tools/testing/selftests/bpf/test_loader.c
index f361c8aa1daf..686a7d7f87b1 100644
--- a/tools/testing/selftests/bpf/test_loader.c
+++ b/tools/testing/selftests/bpf/test_loader.c
@@ -1008,8 +1008,8 @@ 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);
+ PRINT_FAIL("bpf_map__attach_struct_ops failed for map %s: %s\n",
+ bpf_map__name(map), strerror(errno));
goto tobj_cleanup;
}
links[links_cnt++] = link;
--
2.27.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH bpf-next] selftests/bpf: Fix the issue where the error code is 0
2025-08-28 8:15 [PATCH bpf-next] selftests/bpf: Fix the issue where the error code is 0 Feng Yang
@ 2025-08-28 16:15 ` Alexei Starovoitov
0 siblings, 0 replies; 2+ messages in thread
From: Alexei Starovoitov @ 2025-08-28 16:15 UTC (permalink / raw)
To: Feng Yang
Cc: Alexei Starovoitov, Daniel Borkmann, John Fastabend,
Andrii Nakryiko, Martin KaFai Lau, Eduard, Song Liu,
Yonghong Song, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
bpf, LKML, open list:KERNEL SELFTEST FRAMEWORK
On Thu, Aug 28, 2025 at 1:15 AM Feng Yang <yangfeng59949@163.com> wrote:
>
> From: Feng Yang <yangfeng@kylinos.cn>
>
> 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.
Yes, but libbpf_get_error() is better.
And decimal number is preferred as ASSERT_OK_PTR() macro does.
pw-bot: cr
> Therefore, strerror(errno) can be used to 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: Bad file descriptor
>
> Signed-off-by: Feng Yang <yangfeng@kylinos.cn>
> ---
> tools/testing/selftests/bpf/test_loader.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/test_loader.c b/tools/testing/selftests/bpf/test_loader.c
> index f361c8aa1daf..686a7d7f87b1 100644
> --- a/tools/testing/selftests/bpf/test_loader.c
> +++ b/tools/testing/selftests/bpf/test_loader.c
> @@ -1008,8 +1008,8 @@ 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);
> + PRINT_FAIL("bpf_map__attach_struct_ops failed for map %s: %s\n",
> + bpf_map__name(map), strerror(errno));
> goto tobj_cleanup;
> }
> links[links_cnt++] = link;
> --
> 2.27.0
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-08-28 16:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-28 8:15 [PATCH bpf-next] selftests/bpf: Fix the issue where the error code is 0 Feng Yang
2025-08-28 16:15 ` Alexei Starovoitov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).