bpftool: Migrate -1 err checks of libbpf fn calls
authorDave Marchevsky <davemarchevsky@fb.com>
Mon, 1 Nov 2021 22:43:54 +0000 (15:43 -0700)
committerAndrii Nakryiko <andrii@kernel.org>
Wed, 3 Nov 2021 18:22:30 +0000 (11:22 -0700)
Per [0], callers of libbpf functions with LIBBPF_STRICT_DIRECT_ERRS set
should handle negative error codes of various values (e.g. -EINVAL).
Migrate two callsites which were explicitly checking for -1 only to
handle the new scheme.

  [0]: https://github.com/libbpf/libbpf/wiki/Libbpf-1.0-migration-guide#direct-error-code-returning-libbpf_strict_direct_errs

Signed-off-by: Dave Marchevsky <davemarchevsky@fb.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Quentin Monnet <quentin@isovalent.com>
Link: https://lore.kernel.org/bpf/20211101224357.2651181-2-davemarchevsky@fb.com
tools/bpf/bpftool/btf_dumper.c
tools/bpf/bpftool/struct_ops.c

index 9c25286a5c737972959e08a989b6271f3c8dca1e..6934e8634b94bf154c00a0f9cfa321cb0536c93b 100644 (file)
@@ -52,7 +52,7 @@ static int dump_prog_id_as_func_ptr(const struct btf_dumper *d,
 
        /* Get the bpf_prog's name.  Obtain from func_info. */
        prog_fd = bpf_prog_get_fd_by_id(prog_id);
-       if (prog_fd == -1)
+       if (prog_fd < 0)
                goto print;
 
        prog_info = bpf_program__get_prog_info_linear(prog_fd,
index ab2d2290569a41bcd0a893abf2aa560a30a1f854..20f803dce2e4dd74e0857c7ec6e6bd337bd1b19c 100644 (file)
@@ -252,7 +252,7 @@ static struct res do_one_id(const char *id_str, work_func func, void *data,
        }
 
        fd = bpf_map_get_fd_by_id(id);
-       if (fd == -1) {
+       if (fd < 0) {
                p_err("can't get map by id (%lu): %s", id, strerror(errno));
                res.nr_errs++;
                return res;