Skip to contentSkip to conversation

bpftool: print correct error message when failing to load BTF

PATCH Applied Tobias Klauser 2 participants 2 messages May 25, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpftool: print correct error message when failing to load BTF

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

---
 tools/bpf/bpftool/btf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/bpftool/btf.c +1 -1
index 41a1346934a1..da6c3b9bd821 100644
@@ -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));
Signature · 1 line
2.26.1
maintainer Applied
#1 lore raw
Quoted 11 lines · Tobias Klauser

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

Applied, thanks!