lkml.org 
[lkml]   [2021]   [May]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] selftests/bpf: Fix return value check in attach_bpf()
From
Date
On 5/28/21 11:07 AM, Yu Kuai wrote:
> use libbpf_get_error() to check the return value of
> bpf_program__attach().
>
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> ---
> tools/testing/selftests/bpf/benchs/bench_rename.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/benchs/bench_rename.c b/tools/testing/selftests/bpf/benchs/bench_rename.c
> index c7ec114eca56..b7d4a1d74fca 100644
> --- a/tools/testing/selftests/bpf/benchs/bench_rename.c
> +++ b/tools/testing/selftests/bpf/benchs/bench_rename.c
> @@ -65,7 +65,7 @@ static void attach_bpf(struct bpf_program *prog)
> struct bpf_link *link;
>
> link = bpf_program__attach(prog);
> - if (!link) {
> + if (libbpf_get_error(link)) {
> fprintf(stderr, "failed to attach program!\n");
> exit(1);
> }

Could you explain the rationale of this patch? bad2e478af3b ("selftests/bpf: Turn
on libbpf 1.0 mode and fix all IS_ERR checks") explains: 'Fix all the explicit
IS_ERR checks that now will be broken because libbpf returns NULL on error (and
sets errno).' So the !link check looks totally reasonable to me. Converting to
libbpf_get_error() is not wrong in itself, but given you don't make any use of
the err code, there is also no point in this diff here.

Thanks,
Daniel

\
 
 \ /
  Last update: 2021-05-28 23:14    [W:0.036 / U:0.680 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site