selftests/bpf: Fix few more compiler warnings
authorAndrii Nakryiko <andrii@kernel.org>
Tue, 5 Jul 2022 22:48:17 +0000 (15:48 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 6 Jul 2022 14:46:14 +0000 (16:46 +0200)
When compiling with -O2, GCC detects few problems with selftests/bpf, so
fix all of them. Two are real issues (uninitialized err and nums
out-of-bounds access), but two other uninitialized variables warnings
are due to GCC not being able to prove that variables are indeed
initialized under conditions under which they are used.

Fix all 4 cases, though.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yhs@fb.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/bpf/20220705224818.4026623-3-andrii@kernel.org
tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
tools/testing/selftests/bpf/prog_tests/usdt.c
tools/testing/selftests/bpf/prog_tests/xdp_synproxy.c

index 586dc52d6fb960b674e40aad6fcbec1bd89afb2f..a8cb8a96ddafbb74ac7e58fa9da09584ccf319b7 100644 (file)
@@ -329,7 +329,7 @@ static int get_syms(char ***symsp, size_t *cntp)
        struct hashmap *map;
        char buf[256];
        FILE *f;
-       int err;
+       int err = 0;
 
        /*
         * The available_filter_functions contains many duplicates,
@@ -404,7 +404,7 @@ static void test_bench_attach(void)
        double attach_delta, detach_delta;
        struct bpf_link *link = NULL;
        char **syms = NULL;
-       size_t cnt, i;
+       size_t cnt = 0, i;
 
        if (!ASSERT_OK(get_syms(&syms, &cnt), "get_syms"))
                return;
index 5f733d50b0d704197b4694fd5993224b0d1da05a..9ad9da0f215ef53fc953845440c88691e136b980 100644 (file)
@@ -12,7 +12,7 @@ int lets_test_this(int);
 
 static volatile int idx = 2;
 static volatile __u64 bla = 0xFEDCBA9876543210ULL;
-static volatile short nums[] = {-1, -2, -3, };
+static volatile short nums[] = {-1, -2, -3, -4};
 
 static volatile struct {
        int x;
index fb77a123fe8961c922f5017098e814a501cb25aa..874a846e298ca1a68b4891563f37970417f139ab 100644 (file)
@@ -63,7 +63,7 @@ static bool expect_str(char *buf, size_t size, const char *str, const char *name
 static void test_synproxy(bool xdp)
 {
        int server_fd = -1, client_fd = -1, accept_fd = -1;
-       char *prog_id, *prog_id_end;
+       char *prog_id = NULL, *prog_id_end;
        struct nstoken *ns = NULL;
        FILE *ctrl_file = NULL;
        char buf[CMD_OUT_BUF_SIZE];