All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf] libbpf: silence uninitialized warning/error in btf_dump_dump_type_data
@ 2021-11-29 10:00 Alan Maguire
  2021-11-29 17:39 ` Andrii Nakryiko
  2021-11-29 17:40 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Alan Maguire @ 2021-11-29 10:00 UTC (permalink / raw)
  To: ast, daniel, andrii
  Cc: kafai, songliubraving, yhs, john.fastabend, kpsingh, netdev, bpf,
	Alan Maguire

When compiling libbpf with gcc 4.8.5, we see:

  CC       staticobjs/btf_dump.o
btf_dump.c: In function ‘btf_dump_dump_type_data.isra.24’:
btf_dump.c:2296:5: error: ‘err’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  if (err < 0)
     ^
cc1: all warnings being treated as errors
make: *** [staticobjs/btf_dump.o] Error 1

While gcc 4.8.5 is too old to build the upstream kernel, it's possible it
could be used to build standalone libbpf which suffers from the same problem.
Silence the error by initializing 'err' to 0.  The warning/error seems to be
a false positive since err is set early in the function.  Regardless we
shouldn't prevent libbpf from building for this.

Fixes: 920d16af9b42 ("libbpf: BTF dumper support for typed data")

Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
---
 tools/lib/bpf/btf_dump.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index 17db62b..5cae716 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -2194,7 +2194,7 @@ static int btf_dump_dump_type_data(struct btf_dump *d,
 				   __u8 bits_offset,
 				   __u8 bit_sz)
 {
-	int size, err;
+	int size, err = 0;
 
 	size = btf_dump_type_data_check_overflow(d, t, id, data, bits_offset);
 	if (size < 0)
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf] libbpf: silence uninitialized warning/error in btf_dump_dump_type_data
  2021-11-29 10:00 [PATCH bpf] libbpf: silence uninitialized warning/error in btf_dump_dump_type_data Alan Maguire
@ 2021-11-29 17:39 ` Andrii Nakryiko
  2021-11-29 17:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2021-11-29 17:39 UTC (permalink / raw)
  To: Alan Maguire, Arnaldo Carvalho de Melo
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Martin Lau,
	Song Liu, Yonghong Song, john fastabend, KP Singh, Networking,
	bpf

On Mon, Nov 29, 2021 at 2:01 AM Alan Maguire <alan.maguire@oracle.com> wrote:
>
> When compiling libbpf with gcc 4.8.5, we see:
>
>   CC       staticobjs/btf_dump.o
> btf_dump.c: In function ‘btf_dump_dump_type_data.isra.24’:
> btf_dump.c:2296:5: error: ‘err’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
>   if (err < 0)
>      ^
> cc1: all warnings being treated as errors
> make: *** [staticobjs/btf_dump.o] Error 1
>
> While gcc 4.8.5 is too old to build the upstream kernel, it's possible it
> could be used to build standalone libbpf which suffers from the same problem.
> Silence the error by initializing 'err' to 0.  The warning/error seems to be
> a false positive since err is set early in the function.  Regardless we
> shouldn't prevent libbpf from building for this.
>
> Fixes: 920d16af9b42 ("libbpf: BTF dumper support for typed data")
>
> Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
> ---

Arnaldo also complained about this.

Applied to bpf-next, I don't think it needs to be in the bpf tree. Thanks.


>  tools/lib/bpf/btf_dump.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
> index 17db62b..5cae716 100644
> --- a/tools/lib/bpf/btf_dump.c
> +++ b/tools/lib/bpf/btf_dump.c
> @@ -2194,7 +2194,7 @@ static int btf_dump_dump_type_data(struct btf_dump *d,
>                                    __u8 bits_offset,
>                                    __u8 bit_sz)
>  {
> -       int size, err;
> +       int size, err = 0;
>
>         size = btf_dump_type_data_check_overflow(d, t, id, data, bits_offset);
>         if (size < 0)
> --
> 1.8.3.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf] libbpf: silence uninitialized warning/error in btf_dump_dump_type_data
  2021-11-29 10:00 [PATCH bpf] libbpf: silence uninitialized warning/error in btf_dump_dump_type_data Alan Maguire
  2021-11-29 17:39 ` Andrii Nakryiko
@ 2021-11-29 17:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-11-29 17:40 UTC (permalink / raw)
  To: Alan Maguire
  Cc: ast, daniel, andrii, kafai, songliubraving, yhs, john.fastabend,
	kpsingh, netdev, bpf

Hello:

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

On Mon, 29 Nov 2021 10:00:40 +0000 you wrote:
> When compiling libbpf with gcc 4.8.5, we see:
> 
>   CC       staticobjs/btf_dump.o
> btf_dump.c: In function ‘btf_dump_dump_type_data.isra.24’:
> btf_dump.c:2296:5: error: ‘err’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
>   if (err < 0)
>      ^
> cc1: all warnings being treated as errors
> make: *** [staticobjs/btf_dump.o] Error 1
> 
> [...]

Here is the summary with links:
  - [bpf] libbpf: silence uninitialized warning/error in btf_dump_dump_type_data
    https://git.kernel.org/bpf/bpf-next/c/43174f0d4597

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-29 22:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-29 10:00 [PATCH bpf] libbpf: silence uninitialized warning/error in btf_dump_dump_type_data Alan Maguire
2021-11-29 17:39 ` Andrii Nakryiko
2021-11-29 17:40 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.