Skip to contentSkip to conversation

libbpf: Initialize err in probe_map_create

PATCH Applied Florian Fainelli 3 participants 4 messages Aug 1, 2022 – Aug 31, 2022

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

PATCH 1/1 libbpf: Initialize err in probe_map_create

GCC-11 warns about the possibly unitialized err variable in probe_map_create:

libbpf_probes.c: In function 'probe_map_create':
libbpf_probes.c:361:38: error: 'err' may be used uninitialized in this function [-Werror=maybe-uninitialized]

  361 |                 return fd < 0 && err == exp_err ? 1 : 0;
      |                                  ~~~~^~~~~~~~~~
Fixes 878d8def0603 ("libbpf: Rework feature-probing APIs")
---
 tools/lib/bpf/libbpf_probes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/libbpf_probes.c +1 -1
index 97b06cede56f..6cf44e61815d 100644
@@ -247,7 +247,7 @@ static int probe_map_create(enum bpf_map_type map_type, __u32 ifindex)
 	LIBBPF_OPTS(bpf_map_create_opts, opts);
 	int key_size, value_size, max_entries;
 	__u32 btf_key_type_id = 0, btf_value_type_id = 0;
-	int fd = -1, btf_fd = -1, fd_inner = -1, exp_err = 0, err;
+	int fd = -1, btf_fd = -1, fd_inner = -1, exp_err = 0, err = 0;
 
 	opts.map_ifindex = ifindex;
 
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Florian Fainelli

GCC-11 warns about the possibly unitialized err variable in probe_map_create:

libbpf_probes.c: In function 'probe_map_create':
libbpf_probes.c:361:38: error: 'err' may be used uninitialized in this function [-Werror=maybe-uninitialized]

  361 |                 return fd < 0 && err == exp_err ? 1 : 0;
      |                                  ~~~~^~~~~~~~~~
Fixes 878d8def0603 ("libbpf: Rework feature-probing APIs")

jirka

Quoted 20 lines
---
 tools/lib/bpf/libbpf_probes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/libbpf_probes.c +1 -1
index 97b06cede56f..6cf44e61815d 100644
@@ -247,7 +247,7 @@ static int probe_map_create(enum bpf_map_type map_type, __u32 ifindex)
 	LIBBPF_OPTS(bpf_map_create_opts, opts);
 	int key_size, value_size, max_entries;
 	__u32 btf_key_type_id = 0, btf_value_type_id = 0;
-	int fd = -1, btf_fd = -1, fd_inner = -1, exp_err = 0, err;
+	int fd = -1, btf_fd = -1, fd_inner = -1, exp_err = 0, err = 0;
 
 	opts.map_ifindex = ifindex;
 
Signature · 1 line
2.25.1
#2 lore raw
In reply to Florian Fainelli
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Hello:

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

Quoted 9 lines · On Sun, 31 Jul 2022 19:51:09 -0700 you wrote:

GCC-11 warns about the possibly unitialized err variable in probe_map_create:

libbpf_probes.c: In function 'probe_map_create':
libbpf_probes.c:361:38: error: 'err' may be used uninitialized in this function [-Werror=maybe-uninitialized]

  361 |                 return fd < 0 && err == exp_err ? 1 : 0;
      |                                  ~~~~^~~~~~~~~~

[...]

Here is the summary with links:
- libbpf: Initialize err in probe_map_create

    https://git.kernel.org/bpf/bpf-next/c/3045f42a6432

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#3 lore raw
Quoted 14 lines · On 8/4/2022 2:50 PM, [email protected] wrote:

Hello:

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

Quoted 8 lines · On Sun, 31 Jul 2022 19:51:09 -0700 you wrote:

GCC-11 warns about the possibly unitialized err variable in probe_map_create:

libbpf_probes.c: In function 'probe_map_create':
libbpf_probes.c:361:38: error: 'err' may be used uninitialized in this function [-Werror=maybe-uninitialized]

   361 |                 return fd < 0 && err == exp_err ? 1 : 0;
       |                                  ~~~~^~~~~~~~~~
Quoted 7 lines
Quoted 1 line

[...]

Here is the summary with links:
- libbpf: Initialize err in probe_map_create

     https://git.kernel.org/bpf/bpf-next/c/3045f42a6432

You are awesome, thank you!

Thanks for applying, I was sort of expecting this patch to land to Linus a bit quicker, as far as I can see it is still only in linux-next yet it does fix a build warning turned error. Any chance of fast tracking it?

Thanks!

Signature · 1 line
Florian