]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bpftool: Fix maybe-uninitialized warnings
authorAndrii Nakryiko <andrii@kernel.org>
Sat, 13 Mar 2021 21:09:18 +0000 (13:09 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 16 Mar 2021 19:26:49 +0000 (12:26 -0700)
Somehow when bpftool is compiled in -Og mode, compiler produces new warnings
about possibly uninitialized variables. Fix all the reported problems.

Fixes: 2119f2189df1 ("bpftool: add C output format option to btf dump subcommand")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20210313210920.1959628-3-andrii@kernel.org
tools/bpf/bpftool/btf.c
tools/bpf/bpftool/main.c
tools/bpf/bpftool/map.c

index 985610c3f19335f48d35fd9e6a9c663a8f3f8a6d..62953bbf68b44afadbe55c7ec08465cf60b0e06d 100644 (file)
@@ -546,6 +546,7 @@ static int do_dump(int argc, char **argv)
                        NEXT_ARG();
                        if (argc < 1) {
                                p_err("expecting value for 'format' option\n");
+                               err = -EINVAL;
                                goto done;
                        }
                        if (strcmp(*argv, "c") == 0) {
@@ -555,11 +556,13 @@ static int do_dump(int argc, char **argv)
                        } else {
                                p_err("unrecognized format specifier: '%s', possible values: raw, c",
                                      *argv);
+                               err = -EINVAL;
                                goto done;
                        }
                        NEXT_ARG();
                } else {
                        p_err("unrecognized option: '%s'", *argv);
+                       err = -EINVAL;
                        goto done;
                }
        }
index b86f450e6fce280effa3a3e818f47b7e8cd1ffb8..d9afb730136a4723d988cb36867c6cffdb462940 100644 (file)
@@ -276,7 +276,7 @@ static int do_batch(int argc, char **argv)
        int n_argc;
        FILE *fp;
        char *cp;
-       int err;
+       int err = 0;
        int i;
 
        if (argc < 2) {
@@ -370,7 +370,6 @@ static int do_batch(int argc, char **argv)
        } else {
                if (!json_output)
                        printf("processed %d commands\n", lines);
-               err = 0;
        }
 err_close:
        if (fp != stdin)
index b400364ee054e553efcb5af98b9a14a9f90d84c1..09ae0381205b69299bb852398b67597a3d113879 100644 (file)
@@ -100,7 +100,7 @@ static int do_dump_btf(const struct btf_dumper *d,
                       void *value)
 {
        __u32 value_id;
-       int ret;
+       int ret = 0;
 
        /* start of key-value pair */
        jsonw_start_object(d->jw);