diff options
author | Hengqi Chen <hengqi.chen@gmail.com> | 2021-11-15 04:24:36 +0300 |
---|---|---|
committer | Andrii Nakryiko <andrii@kernel.org> | 2021-11-15 05:38:13 +0300 |
commit | e5043894b21f7d99d3db31ad06308d6c5726caa6 (patch) | |
tree | 0ccaa10b8751a723e46994d985e39b891dbff4bc /tools/bpf/bpftool/btf.c | |
parent | c874dff452f34056315b01d7954ce613ce6c18ab (diff) | |
download | linux-e5043894b21f7d99d3db31ad06308d6c5726caa6.tar.xz |
bpftool: Use libbpf_get_error() to check error
Currently, LIBBPF_STRICT_ALL mode is enabled by default for
bpftool which means on error cases, some libbpf APIs would
return NULL pointers. This makes IS_ERR check failed to detect
such cases and result in segfault error. Use libbpf_get_error()
instead like we do in libbpf itself.
Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20211115012436.3143318-1-hengqi.chen@gmail.com
Diffstat (limited to 'tools/bpf/bpftool/btf.c')
-rw-r--r-- | tools/bpf/bpftool/btf.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c index c7e3b0b0029e..59833125ac0a 100644 --- a/tools/bpf/bpftool/btf.c +++ b/tools/bpf/bpftool/btf.c @@ -421,8 +421,9 @@ static int dump_btf_c(const struct btf *btf, int err = 0, i; d = btf_dump__new(btf, btf_dump_printf, NULL, NULL); - if (IS_ERR(d)) - return PTR_ERR(d); + err = libbpf_get_error(d); + if (err) + return err; printf("#ifndef __VMLINUX_H__\n"); printf("#define __VMLINUX_H__\n"); @@ -549,8 +550,8 @@ static int do_dump(int argc, char **argv) } btf = btf__parse_split(*argv, base ?: base_btf); - if (IS_ERR(btf)) { - err = -PTR_ERR(btf); + err = libbpf_get_error(btf); + if (err) { btf = NULL; p_err("failed to load BTF from %s: %s", *argv, strerror(err)); |