bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bpftool: print correct error message when failing to load BTF
@ 2020-05-25 13:54 Tobias Klauser
  2020-05-25 22:18 ` Daniel Borkmann
  0 siblings, 1 reply; 2+ messages in thread
From: Tobias Klauser @ 2020-05-25 13:54 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann; +Cc: bpf

btf__parse_raw and btf__parse_elf return negative error numbers wrapped
in an ERR_PTR, so the extracted value needs to be negated before passing
them to strerror which expects a positive error number.

Before:
  Error: failed to load BTF from .../vmlinux: Unknown error -2

After:
  Error: failed to load BTF from .../vmlinux: No such file or directory

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
---
 tools/bpf/bpftool/btf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
index 41a1346934a1..da6c3b9bd821 100644
--- a/tools/bpf/bpftool/btf.c
+++ b/tools/bpf/bpftool/btf.c
@@ -553,7 +553,7 @@ static int do_dump(int argc, char **argv)
 			btf = btf__parse_elf(*argv, NULL);
 
 		if (IS_ERR(btf)) {
-			err = PTR_ERR(btf);
+			err = -PTR_ERR(btf);
 			btf = NULL;
 			p_err("failed to load BTF from %s: %s",
 			      *argv, strerror(err));
-- 
2.26.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] bpftool: print correct error message when failing to load BTF
  2020-05-25 13:54 [PATCH] bpftool: print correct error message when failing to load BTF Tobias Klauser
@ 2020-05-25 22:18 ` Daniel Borkmann
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Borkmann @ 2020-05-25 22:18 UTC (permalink / raw)
  To: Tobias Klauser, Alexei Starovoitov; +Cc: bpf

On 5/25/20 3:54 PM, Tobias Klauser wrote:
> btf__parse_raw and btf__parse_elf return negative error numbers wrapped
> in an ERR_PTR, so the extracted value needs to be negated before passing
> them to strerror which expects a positive error number.
> 
> Before:
>    Error: failed to load BTF from .../vmlinux: Unknown error -2
> 
> After:
>    Error: failed to load BTF from .../vmlinux: No such file or directory
> 
> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>

Applied, thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-05-25 22:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-25 13:54 [PATCH] bpftool: print correct error message when failing to load BTF Tobias Klauser
2020-05-25 22:18 ` Daniel Borkmann

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).