]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
selftests/bpf: Fix build error due to certain uninitialized variables
authorYonghong Song <yonghong.song@linux.dev>
Tue, 15 Jul 2025 18:59:10 +0000 (11:59 -0700)
committerAndrii Nakryiko <andrii@kernel.org>
Tue, 15 Jul 2025 21:38:58 +0000 (14:38 -0700)
With the latest llvm21 compiler, I hit several errors when building bpf
selftests. Some of errors look like below:

  test_maps.c:565:40: error: variable 'val' is uninitialized when passed as a
      const pointer argument here [-Werror,-Wuninitialized-const-pointer]
    565 |         assert(bpf_map_update_elem(fd, NULL, &val, 0) < 0 &&
        |                                               ^~~

  prog_tests/bpf_iter.c:400:25: error: variable 'c' is uninitialized when passed
      as a const pointer argument here [-Werror,-Wuninitialized-const-pointer]
  400 |         write(finish_pipe[1], &c, 1);
      |                                ^

Some other errors have similar the pattern as the above.

These errors are fixed by initializing those variables properly.

Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20250715185910.3659447-1-yonghong.song@linux.dev
tools/testing/selftests/bpf/prog_tests/bloom_filter_map.c
tools/testing/selftests/bpf/prog_tests/bpf_iter.c
tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c
tools/testing/selftests/bpf/prog_tests/verify_pkcs7_sig.c
tools/testing/selftests/bpf/test_maps.c

index 67557cda22083545e17b7669ea74b6a20ca98d81..42b49870e52053bac9d550b933f5b649df8d9973 100644 (file)
@@ -13,7 +13,7 @@
 static void test_fail_cases(void)
 {
        LIBBPF_OPTS(bpf_map_create_opts, opts);
-       __u32 value;
+       __u32 value = 0;
        int fd, err;
 
        /* Invalid key size */
index add4a18c33bdb2f4ce5eea495d25cd0b81c168cf..5225d69bf79bbaefa0349204caa0e4e665759bf8 100644 (file)
@@ -323,7 +323,7 @@ static void test_task_pidfd(void)
 static void test_task_sleepable(void)
 {
        struct bpf_iter_tasks *skel;
-       int pid, status, err, data_pipe[2], finish_pipe[2], c;
+       int pid, status, err, data_pipe[2], finish_pipe[2], c = 0;
        char *test_data = NULL;
        char *test_data_long = NULL;
        char *data[2];
index c397336fe1ed1c0a6b81576e0bfde87555aab4d2..b17dc39a23dbfa54012f25826b4692ab64cb41b2 100644 (file)
@@ -251,7 +251,7 @@ static void test_uretprobe_syscall_call(void)
                .retprobe = true,
        );
        struct uprobe_syscall_executed *skel;
-       int pid, status, err, go[2], c;
+       int pid, status, err, go[2], c = 0;
 
        if (!ASSERT_OK(pipe(go), "pipe"))
                return;
index ab0f02faa80cc17e4c7a72a112e4320fede72ec5..4d69d9d55e17459c01f46f8212010a0bba69e82a 100644 (file)
@@ -268,7 +268,7 @@ static void test_verify_pkcs7_sig_from_map(void)
        char *tmp_dir;
        struct test_verify_pkcs7_sig *skel = NULL;
        struct bpf_map *map;
-       struct data data;
+       struct data data = {};
        int ret, zero = 0;
 
        /* Trigger creation of session keyring. */
index 986ce32b113a341b2d8d3820f9a83caf718bbd45..3fae9ce46ca9bfdfe060c874ea06ef6438207986 100644 (file)
@@ -535,7 +535,7 @@ static void test_devmap_hash(unsigned int task, void *data)
 static void test_queuemap(unsigned int task, void *data)
 {
        const int MAP_SIZE = 32;
-       __u32 vals[MAP_SIZE + MAP_SIZE/2], val;
+       __u32 vals[MAP_SIZE + MAP_SIZE/2], val = 0;
        int fd, i;
 
        /* Fill test values to be used */
@@ -591,7 +591,7 @@ static void test_queuemap(unsigned int task, void *data)
 static void test_stackmap(unsigned int task, void *data)
 {
        const int MAP_SIZE = 32;
-       __u32 vals[MAP_SIZE + MAP_SIZE/2], val;
+       __u32 vals[MAP_SIZE + MAP_SIZE/2], val = 0;
        int fd, i;
 
        /* Fill test values to be used */