Skip to content

Commit

Permalink
selftests/bpf: fix a few clang compilation errors
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Yonghong Song <yhs@fb.com>
Acked-by: David Vernet <void@manifault.com>
Link: https://lore.kernel.org/r/20220511184735.3670214-1-yhs@fb.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
  • Loading branch information
Yonghong Song authored and Alexei Starovoitov committed May 11, 2022
1 parent 998e186 commit fd0ad6f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions tools/testing/selftests/bpf/prog_tests/test_tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit fd0ad6f

Please sign in to comment.