selftests/bpf: fix a few clang compilation errors
Subsystems (3)
PATCH 1/1 selftests/bpf: fix a few clang compilation errors
With latest clang, I got the following compilation errors:
.../prog_tests/test_tunnel.c:291:6: error: variable 'local_ip_map_fd' is used uninitialized
whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
if (attach_tc_prog(&tc_hook, -1, set_dst_prog_fd))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../bpf/prog_tests/test_tunnel.c:312:6: note: uninitialized use occurs here
if (local_ip_map_fd >= 0)
^~~~~~~~~~~~~~~
...
.../prog_tests/kprobe_multi_test.c:346:6: error: variable 'err' is used uninitialized
whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
if (IS_ERR(map))
^~~~~~~~~~~
.../prog_tests/kprobe_multi_test.c:388:6: note: uninitialized use occurs here
if (err) {
^~~This patch fixed the above compilation errors.
--- tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c | 4 +++- tools/testing/selftests/bpf/prog_tests/test_tunnel.c | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c +3 -1
@@ -343,8 +343,10 @@ static int get_syms(char ***symsp, size_t *cntp)return -EINVAL ; map =hashmap__new (symbol_hash, symbol_equal,NULL ); -if (IS_ERR (map)) +if (IS_ERR (map)) { + err =libbpf_get_error (map); goto error; + }while (fgets (buf,sizeof (buf), f)) {/* skip modules */
tools/testing/selftests/bpf/prog_tests/test_tunnel.c +2 -2
@@ -246,7 +246,7 @@ static void test_vxlan_tunnel(void) {struct test_tunnel_kern *skel =NULL ;struct nstoken *nstoken; -int local_ip_map_fd; +int local_ip_map_fd =-1 ;int set_src_prog_fd, get_src_prog_fd;int set_dst_prog_fd;int key =0 , ifindex =-1 ;
@@ -319,7 +319,7 @@ static void test_ip6vxlan_tunnel(void) {struct test_tunnel_kern *skel =NULL ;struct nstoken *nstoken; -int local_ip_map_fd; +int local_ip_map_fd =-1 ;int set_src_prog_fd, get_src_prog_fd;int set_dst_prog_fd;int key =0 , ifindex =-1 ;
Signature · 1 line
2.30.2
Quoted 17 lines · Yonghong Song
With latest clang, I got the following compilation errors:
.../prog_tests/test_tunnel.c:291:6: error: variable 'local_ip_map_fd' is used uninitializedwhenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (attach_tc_prog(&tc_hook, -1, set_dst_prog_fd)) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .../bpf/prog_tests/test_tunnel.c:312:6: note: uninitialized use occurs here if (local_ip_map_fd >= 0) ^~~~~~~~~~~~~~~ ... .../prog_tests/kprobe_multi_test.c:346:6: error: variable 'err' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (IS_ERR(map)) ^~~~~~~~~~~ .../prog_tests/kprobe_multi_test.c:388:6: note: uninitialized use occurs here if (err) { ^~~
Quoted 1 line
This patch fixed the above compilation errors.
I'd argue that these are real bugs that the compiler happens to have caught, and that the patch should perhaps be framed as fixing them rather than as avoiding compilation failures, but that might be unnecessarily nit-picky and I don't feel strongly about it.
Quoted 48 lines
Signed-off-by Yonghong Song <[email protected]>--- tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c | 4 +++- tools/testing/selftests/bpf/prog_tests/test_tunnel.c | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-)tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c +3
-1@@ -343,8 +343,10 @@ static int get_syms(char ***symsp, size_t *cntp)return -EINVAL ; map =hashmap__new (symbol_hash, symbol_equal,NULL ); -if (IS_ERR (map)) +if (IS_ERR (map)) { + err =libbpf_get_error (map); goto error; + }while (fgets (buf,sizeof (buf), f)) {/* skip modules */ tools/testing/selftests/bpf/prog_tests/test_tunnel.c +2
-2@@ -246,7 +246,7 @@ static void test_vxlan_tunnel(void) {struct test_tunnel_kern *skel =NULL ;struct nstoken *nstoken; -int local_ip_map_fd; +int local_ip_map_fd =-1 ;int set_src_prog_fd, get_src_prog_fd;int set_dst_prog_fd;int key =0 , ifindex =-1 ;@@ -319,7 +319,7 @@ static void test_ip6vxlan_tunnel(void) {struct test_tunnel_kern *skel =NULL ;struct nstoken *nstoken; -int local_ip_map_fd; +int local_ip_map_fd =-1 ;int set_src_prog_fd, get_src_prog_fd;int set_dst_prog_fd;int key =0 , ifindex =-1 ;Signature · 1 line
2.30.2
I'm a bit surprised this ever successfully compiled. What version of clang did you have to upgrade to in order to see this error? IIRC I've used -Wsometimes-uninitialized on much older versions of clang.
Anyways, looks good to me.
Quoted 69 lines · David Vernet
Quoted 17 lines · Yonghong Song
With latest clang, I got the following compilation errors:
.../prog_tests/test_tunnel.c:291:6: error: variable 'local_ip_map_fd' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (attach_tc_prog(&tc_hook, -1, set_dst_prog_fd)) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .../bpf/prog_tests/test_tunnel.c:312:6: note: uninitialized use occurs here if (local_ip_map_fd >= 0) ^~~~~~~~~~~~~~~ ... .../prog_tests/kprobe_multi_test.c:346:6: error: variable 'err' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (IS_ERR(map)) ^~~~~~~~~~~ .../prog_tests/kprobe_multi_test.c:388:6: note: uninitialized use occurs here if (err) { ^~~Quoted 1 line
This patch fixed the above compilation errors.
I'd argue that these are real bugs that the compiler happens to have caught, and that the patch should perhaps be framed as fixing them rather than as avoiding compilation failures, but that might be unnecessarily nit-picky and I don't feel strongly about it.
Quoted 44 lines
Signed-off-by Yonghong Song <[email protected]>--- tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c | 4 +++- tools/testing/selftests/bpf/prog_tests/test_tunnel.c | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-)tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c +3
-1@@ -343,8 +343,10 @@ static int get_syms(char ***symsp, size_t *cntp)return -EINVAL ; map =hashmap__new (symbol_hash, symbol_equal,NULL ); -if (IS_ERR (map)) +if (IS_ERR (map)) { + err =libbpf_get_error (map); goto error; + }while (fgets (buf,sizeof (buf), f)) {/* skip modules */ tools/testing/selftests/bpf/prog_tests/test_tunnel.c +2
-2@@ -246,7 +246,7 @@ static void test_vxlan_tunnel(void) {struct test_tunnel_kern *skel =NULL ;struct nstoken *nstoken; -int local_ip_map_fd; +int local_ip_map_fd =-1 ;int set_src_prog_fd, get_src_prog_fd;int set_dst_prog_fd;int key =0 , ifindex =-1 ;@@ -319,7 +319,7 @@ static void test_ip6vxlan_tunnel(void) {struct test_tunnel_kern *skel =NULL ;struct nstoken *nstoken; -int local_ip_map_fd; +int local_ip_map_fd =-1 ;int set_src_prog_fd, get_src_prog_fd;int set_dst_prog_fd;
Quoted 8 lines
Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/test_tunnel.c +0
-0int key =0 , ifindex =-1 ;Signature · 1 line
2.30.2I'm a bit surprised this ever successfully compiled. What version of clang did you have to upgrade to in order to see this error? IIRC I've used -Wsometimes-uninitialized on much older versions of clang.
I compiled with latest llvm-project source (llvm15 main branch).
Since latest pahole (built from source) by default will do parallel
dwarf parsing and btf generation when build vmlinux, you might need this patch as well for pahole:
https://lore.kernel.org/bpf/[email protected]/
Quoted 4 lines
Anyways, looks good to me.
Acked-by David Vernet <[email protected]>
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 17 lines · On Wed, 11 May 2022 11:47:35 -0700 you wrote:
With latest clang, I got the following compilation errors:
.../prog_tests/test_tunnel.c:291:6: error: variable 'local_ip_map_fd' is used uninitializedwhenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (attach_tc_prog(&tc_hook, -1, set_dst_prog_fd)) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .../bpf/prog_tests/test_tunnel.c:312:6: note: uninitialized use occurs here if (local_ip_map_fd >= 0) ^~~~~~~~~~~~~~~ ... .../prog_tests/kprobe_multi_test.c:346:6: error: variable 'err' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized] if (IS_ERR(map)) ^~~~~~~~~~~ .../prog_tests/kprobe_multi_test.c:388:6: note: uninitialized use occurs here if (err) { ^~~
Quoted 1 line
[...]
Here is the summary with links:
- [bpf-next] selftests/bpf: fix a few clang compilation errors
https://git.kernel.org/bpf/bpf-next/c/fd0ad6f1d10c
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html