]> git.baikalelectronics.ru Git - kernel.git/commit
selftests/bpf: Fix a compilation warning
authorYonghong Song <yhs@fb.com>
Thu, 9 Dec 2021 05:04:03 +0000 (21:04 -0800)
committerAndrii Nakryiko <andrii@kernel.org>
Thu, 9 Dec 2021 07:05:26 +0000 (23:05 -0800)
commit0ef048e6d3c555e12575eee3b1af008560a9d4a2
tree31b77748a458c8fe9b4f5ad2e294907095ecd5b2
parent9d60cc2eacbb083bf25042b0bdda1179af5567bb
selftests/bpf: Fix a compilation warning

The following warning is triggered when I used clang compiler
to build the selftest.

  /.../prog_tests/btf_dedup_split.c:368:6: warning: variable 'btf2' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
        if (!ASSERT_OK(err, "btf_dedup"))
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
  /.../prog_tests/btf_dedup_split.c:424:12: note: uninitialized use occurs here
        btf__free(btf2);
                  ^~~~
  /.../prog_tests/btf_dedup_split.c:368:2: note: remove the 'if' if its condition is always false
        if (!ASSERT_OK(err, "btf_dedup"))
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  /.../prog_tests/btf_dedup_split.c:343:25: note: initialize the variable 'btf2' to silence this warning
        struct btf *btf1, *btf2;
                               ^
                                = NULL

Initialize local variable btf2 = NULL and the warning is gone.

Fixes: af32376dfbfa ("selftests/bpf: Add btf_dedup case with duplicated structs within CU")
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20211209050403.1770836-1-yhs@fb.com
tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c