Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Fix build error due to certain uninitialized variables

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

authored by

Yonghong Song and committed by
Andrii Nakryiko
e860a98c ea2aecdf

+6 -6
+1 -1
tools/testing/selftests/bpf/prog_tests/bloom_filter_map.c
··· 13 13 static void test_fail_cases(void) 14 14 { 15 15 LIBBPF_OPTS(bpf_map_create_opts, opts); 16 - __u32 value; 16 + __u32 value = 0; 17 17 int fd, err; 18 18 19 19 /* Invalid key size */
+1 -1
tools/testing/selftests/bpf/prog_tests/bpf_iter.c
··· 323 323 static void test_task_sleepable(void) 324 324 { 325 325 struct bpf_iter_tasks *skel; 326 - int pid, status, err, data_pipe[2], finish_pipe[2], c; 326 + int pid, status, err, data_pipe[2], finish_pipe[2], c = 0; 327 327 char *test_data = NULL; 328 328 char *test_data_long = NULL; 329 329 char *data[2];
+1 -1
tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c
··· 251 251 .retprobe = true, 252 252 ); 253 253 struct uprobe_syscall_executed *skel; 254 - int pid, status, err, go[2], c; 254 + int pid, status, err, go[2], c = 0; 255 255 256 256 if (!ASSERT_OK(pipe(go), "pipe")) 257 257 return;
+1 -1
tools/testing/selftests/bpf/prog_tests/verify_pkcs7_sig.c
··· 268 268 char *tmp_dir; 269 269 struct test_verify_pkcs7_sig *skel = NULL; 270 270 struct bpf_map *map; 271 - struct data data; 271 + struct data data = {}; 272 272 int ret, zero = 0; 273 273 274 274 /* Trigger creation of session keyring. */
+2 -2
tools/testing/selftests/bpf/test_maps.c
··· 535 535 static void test_queuemap(unsigned int task, void *data) 536 536 { 537 537 const int MAP_SIZE = 32; 538 - __u32 vals[MAP_SIZE + MAP_SIZE/2], val; 538 + __u32 vals[MAP_SIZE + MAP_SIZE/2], val = 0; 539 539 int fd, i; 540 540 541 541 /* Fill test values to be used */ ··· 591 591 static void test_stackmap(unsigned int task, void *data) 592 592 { 593 593 const int MAP_SIZE = 32; 594 - __u32 vals[MAP_SIZE + MAP_SIZE/2], val; 594 + __u32 vals[MAP_SIZE + MAP_SIZE/2], val = 0; 595 595 int fd, i; 596 596 597 597 /* Fill test values to be used */