[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAEf4Bzasfsj7EouWseik7injZkp8pUZKNJWFbgy=OGdKm9LAuw@mail.gmail.com>
Date: Fri, 5 Sep 2025 14:46:05 -0700
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Feng Yang <yangfeng59949@....com>
Cc: ast@...nel.org, daniel@...earbox.net, john.fastabend@...il.com,
andrii@...nel.org, martin.lau@...ux.dev, eddyz87@...il.com, song@...nel.org,
yonghong.song@...ux.dev, kpsingh@...nel.org, sdf@...ichev.me,
haoluo@...gle.com, jolsa@...nel.org, bpf@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org
Subject: Re: [PATCH v2 bpf-next] selftests/bpf: Fix the issue where the error
code is 0
On Thu, Aug 28, 2025 at 6:41 PM Feng Yang <yangfeng59949@....com> wrote:
>
> From: Feng Yang <yangfeng@...inos.cn>
>
> The error message printed here only uses the previous err value,
> which results in it being printed as 0.
> Fix this issue by using libbpf_get_error to retrieve the error.
>
> 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
>
> Signed-off-by: Feng Yang <yangfeng@...inos.cn>
> ---
> Changes in v2:
> - Use libbpf_get_error, thanks: Alexei Starovoitov.
> - Link to v1: https://lore.kernel.org/all/20250828081507.1380218-1-yangfeng59949@163.com/
> ---
> 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 78423cf89e01..b8e102eb0908 100644
> --- a/tools/testing/selftests/bpf/test_loader.c
> +++ b/tools/testing/selftests/bpf/test_loader.c
> @@ -1082,8 +1082,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: err=%ld\n",
> + bpf_map__name(map), libbpf_get_error(link));
since libbpf 1.0 all that libbpf_get_error() is doing is returning
-errno if link is NULL. It's kind of discouraged now because it's too
easy to miss its reliance on errno. So let's use -errno here directly.
pw-bot: cr
> goto tobj_cleanup;
> }
> links[links_cnt++] = link;
> --
> 2.25.1
>
Powered by blists - more mailing lists