Skip to contentSkip to conversation

libbpf: Fix uninitialized warning in btf_dump_dump_type_data

PATCH Applied David Michael 4 participants 4 messages Nov 13, 2022 – Nov 14, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libbpf: Fix uninitialized warning in btf_dump_dump_type_data

GCC 11.3.0 fails to compile btf_dump.c due to the following error, which seems to originate in btf_dump_struct_data where the returned value would be uninitialized if btf_vlen returns zero.

btf_dump.c: In function ‘btf_dump_dump_type_data’:
btf_dump.c:2363:12: error: ‘err’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
2363 | if (err < 0)
| ^

Fixes 43174f0d4597 ("libbpf: Silence uninitialized warning/error in btf_dump_dump_type_data")

---

Hi,

I encountered this build failure when using Gentoo's hardened profile to build sys-kernel/gentoo-kernel (at least some 5.19 and 6.0 versions). The following patch fixes it. Can this be applied?

Thanks.

David

 tools/lib/bpf/btf_dump.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/btf_dump.c +1 -1
index 12f7039e0..e9f849d82 100644
@@ -1989,7 +1989,7 @@ static int btf_dump_struct_data(struct btf_dump *d,
 {
 	const struct btf_member *m = btf_members(t);
 	__u16 n = btf_vlen(t);
-	int i, err;
+	int i, err = 0;
 
 	/* note that we increment depth before calling btf_dump_print() below;
 	 * this is intentional.  btf_dump_data_newline() will not print a
Signature · 1 line
2.38.1
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · David Michael

GCC 11.3.0 fails to compile btf_dump.c due to the following error, which seems to originate in btf_dump_struct_data where the returned value would be uninitialized if btf_vlen returns zero.

btf_dump.c: In function ‘btf_dump_dump_type_data’:
btf_dump.c:2363:12: error: ‘err’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
2363 | if (err < 0)
| ^

Fixes 43174f0d4597 ("libbpf: Silence uninitialized warning/error in btf_dump_dump_type_data")

Probably better to reference the original patch?

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

---

Hi,

I encountered this build failure when using Gentoo's hardened profile to build sys-kernel/gentoo-kernel (at least some 5.19 and 6.0 versions). The following patch fixes it. Can this be applied?

Thanks.

David

  tools/lib/bpf/btf_dump.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/btf_dump.c +1 -2
index 12f7039e0..e9f849d82 100644
@@ -1989,7 +1989,7 @@ static int btf_dump_struct_data(struct btf_dump *d,
  {
  	const struct btf_member *m = btf_members(t);
  	__u16 n = btf_vlen(t);
-	int i, err;
+	int i, err = 0;
 
  	/* note that we increment depth before calling btf_dump_print() below;
  	 * this is intentional.  btf_dump_data_newline() will not print a
--

2.38.1

Acked-by
#2 lore raw
Quoted 10 lines · On 14/11/2022 17:21, [email protected] wrote:
Quoted 8 lines · David Michael

GCC 11.3.0 fails to compile btf_dump.c due to the following error, which seems to originate in btf_dump_struct_data where the returned value would be uninitialized if btf_vlen returns zero.

btf_dump.c: In function ‘btf_dump_dump_type_data’:
btf_dump.c:2363:12: error: ‘err’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2363 |         if (err < 0)
       |            ^

Quoted 7 lines
Quoted 1 line
Fixes 43174f0d4597 ("libbpf: Silence uninitialized warning/error in btf_dump_dump_type_data")

Probably better to reference the original patch?

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

Thanks for fixing!

Quoted 31 lines
Quoted 31 lines

---

Hi,

I encountered this build failure when using Gentoo's hardened profile to build sys-kernel/gentoo-kernel (at least some 5.19 and 6.0 versions). The following patch fixes it.  Can this be applied?

Thanks.

David

  tools/lib/bpf/btf_dump.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/btf_dump.c +1 -1
index 12f7039e0..e9f849d82 100644
@@ -1989,7 +1989,7 @@ static int btf_dump_struct_data(struct btf_dump *d,
   {
       const struct btf_member *m = btf_members(t);
       __u16 n = btf_vlen(t);
-    int i, err;
+    int i, err = 0;
 
       /* note that we increment depth before calling btf_dump_print() below;
        * this is intentional.  btf_dump_data_newline() will not print a
Signature · 1 line
2.38.1
#3 lore raw
In reply to David Michael
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Quoted 10 lines · On Sun, 13 Nov 2022 15:52:17 -0500 you wrote:

GCC 11.3.0 fails to compile btf_dump.c due to the following error, which seems to originate in btf_dump_struct_data where the returned value would be uninitialized if btf_vlen returns zero.

btf_dump.c: In function ‘btf_dump_dump_type_data’:
btf_dump.c:2363:12: error: ‘err’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
2363 | if (err < 0)
| ^

[...]

Here is the summary with links:
- libbpf: Fix uninitialized warning in btf_dump_dump_type_data

    https://git.kernel.org/bpf/bpf-next/c/dfd0afbf151d

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html