use libbpf_get_error() to check the return value of
bpf_program__attach().
Reported-by: Hulk Robot <redacted>
Signed-off-by: Yu Kuai <redacted>
---
tools/testing/selftests/bpf/benchs/bench_rename.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Daniel Borkmann <daniel@iogearbox.net> Date: 2021-05-28 21:13:47
On 5/28/21 11:07 AM, Yu Kuai wrote:
quoted hunk
use libbpf_get_error() to check the return value of
bpf_program__attach().
Reported-by: Hulk Robot <redacted>
Signed-off-by: Yu Kuai <redacted>
---
tools/testing/selftests/bpf/benchs/bench_rename.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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
From: John Fastabend <john.fastabend@gmail.com> Date: 2021-05-28 21:16:29
Yu Kuai wrote:
quoted hunk
use libbpf_get_error() to check the return value of
bpf_program__attach().
Reported-by: Hulk Robot <redacted>
Signed-off-by: Yu Kuai <redacted>
---
tools/testing/selftests/bpf/benchs/bench_rename.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: John Fastabend <john.fastabend@gmail.com> Date: 2021-05-28 21:19:28
John Fastabend wrote:
Yu Kuai wrote:
quoted
use libbpf_get_error() to check the return value of
bpf_program__attach().
Reported-by: Hulk Robot <redacted>
Signed-off-by: Yu Kuai <redacted>
---
tools/testing/selftests/bpf/benchs/bench_rename.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
use libbpf_get_error() to check the return value of
bpf_program__attach().
Reported-by: Hulk Robot <redacted>
Signed-off-by: Yu Kuai <redacted>
---
tools/testing/selftests/bpf/benchs/bench_rename.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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.
Hi,
I was thinking that bpf_program__attach() can return error code
theoretically(for example -ESRCH), and such case need to be handled.
Thanks,
Yu Kuai
On Fri, May 28, 2021 at 6:25 PM yukuai (C) [off-list ref] wrote:
On 2021/05/29 4:46, Daniel Borkmann wrote:
quoted
On 5/28/21 11:07 AM, Yu Kuai wrote:
quoted
use libbpf_get_error() to check the return value of
bpf_program__attach().
Reported-by: Hulk Robot <redacted>
Signed-off-by: Yu Kuai <redacted>
---
tools/testing/selftests/bpf/benchs/bench_rename.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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.
Hi,
I was thinking that bpf_program__attach() can return error code
theoretically(for example -ESRCH), and such case need to be handled.
I explicitly changed to NULL check + libbpf 1.0 error reporting mode
because I don't care about specific error in benchmarks. So as Daniel
and John pointed out, existing code is correct and doesn't need
adjustment.
You are right, though, that error code is indeed returned, but you can
check errno directly (but need to enable libbpf 1.0 mode) or use
libbpf_get_error() (which will get deprecated some time before libbpf
1.0) if you don't know which mode your code will be run in.