diff mbox series

[bpf-next] selftests/bpf: fix a compilation warning

Message ID 20211209050403.1770836-1-yhs@fb.com (mailing list archive)
State Accepted
Commit b540358e6c4d86eb450f3539aea198653e656641
Delegated to: BPF
Headers show
Series [bpf-next] selftests/bpf: fix a compilation warning | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 11 maintainers not CCed: netdev@vger.kernel.org kafai@fb.com shuah@kernel.org nathan@kernel.org songliubraving@fb.com linux-kselftest@vger.kernel.org john.fastabend@gmail.com ndesaulniers@google.com jolsa@kernel.org kpsingh@kernel.org llvm@lists.linux.dev
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-PR pending PR summary
bpf/vmtest-bpf-next pending VM_Test

Commit Message

Yonghong Song Dec. 9, 2021, 5:04 a.m. UTC
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.

Signed-off-by: Yonghong Song <yhs@fb.com>
---
 tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andrii Nakryiko Dec. 9, 2021, 7:06 a.m. UTC | #1
On Wed, Dec 8, 2021 at 9:04 PM Yonghong Song <yhs@fb.com> wrote:
>
> 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.
>
> Signed-off-by: Yonghong Song <yhs@fb.com>
> ---

Added:

Fixes: 9a49afe6f5a5 ("selftests/bpf: Add btf_dedup case with
duplicated structs within CU")

and pushed to bpf-next. Thanks.

>  tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c b/tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c
> index 878a864dae3b..90aac437576d 100644
> --- a/tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c
> +++ b/tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c
> @@ -340,7 +340,7 @@ static void btf_add_dup_struct_in_cu(struct btf *btf, int start_id)
>
>  static void test_split_dup_struct_in_cu()
>  {
> -       struct btf *btf1, *btf2;
> +       struct btf *btf1, *btf2 = NULL;
>         int err;
>
>         /* generate the base data.. */
> --
> 2.30.2
>
patchwork-bot+netdevbpf@kernel.org Dec. 9, 2021, 7:10 a.m. UTC | #2
Hello:

This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Wed, 8 Dec 2021 21:04:03 -0800 you wrote:
> 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
> 
> [...]

Here is the summary with links:
  - [bpf-next] selftests/bpf: fix a compilation warning
    https://git.kernel.org/bpf/bpf-next/c/b540358e6c4d

You are awesome, thank you!
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c b/tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c
index 878a864dae3b..90aac437576d 100644
--- a/tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c
+++ b/tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c
@@ -340,7 +340,7 @@  static void btf_add_dup_struct_in_cu(struct btf *btf, int start_id)
 
 static void test_split_dup_struct_in_cu()
 {
-	struct btf *btf1, *btf2;
+	struct btf *btf1, *btf2 = NULL;
 	int err;
 
 	/* generate the base data.. */