commit:     de599559deffc5a4a19abb41233177322aff11bd
Author:     Mike Pagano <mpagano <AT> gentoo <DOT> org>
AuthorDate: Fri Oct  4 22:52:15 2024 +0000
Commit:     Mike Pagano <mpagano <AT> gentoo <DOT> org>
CommitDate: Fri Oct  4 22:52:15 2024 +0000
URL:        https://gitweb.gentoo.org/proj/linux-patches.git/commit/?id=de599559

libbpf: workaround (another) -Wmaybe-uninitialized false positive

Bug: https://bugs.gentoo.org/939106
Signed-off-by: Sam James <sam <AT> gentoo.org>
Signed-off-by: Mike Pagano <mpagano <AT> gentoo.org>

 0000_README                                        |  4 ++
 ...workaround-Wmaybe-uninitialized-false-pos.patch | 64 ++++++++++++++++++++++
 2 files changed, 68 insertions(+)

diff --git a/0000_README b/0000_README
index 5383d35f..17f65fb8 100644
--- a/0000_README
+++ b/0000_README
@@ -87,6 +87,10 @@ Patch:  
2990_libbpf-v2-workaround-Wmaybe-uninitialized-false-pos.patch
 From:   https://lore.kernel.org/bpf/
 Desc:   libbpf: workaround -Wmaybe-uninitialized false positive
 
+Patch:  2991_libbpf-workaround-Wmaybe-uninitialized-false-pos.patch
+From:   
https://lore.kernel.org/bpf/f6962729197ae7cdf4f6d1512625bd92f2322d31.1725630494.git....@gentoo.org/
+Desc:   libbpf: workaround (another) -Wmaybe-uninitialized false positive
+
 Patch:  2995_dtrace-6.11_p1.patch
 From:   https://github.com/thesamesam/linux/tree/dtrace-sam/v2/6.11-flat
 Desc:   dtrace patch for 6.11.X (CTF, modules.builtin.objs)

diff --git a/2991_libbpf-workaround-Wmaybe-uninitialized-false-pos.patch 
b/2991_libbpf-workaround-Wmaybe-uninitialized-false-pos.patch
new file mode 100644
index 00000000..f01221c7
--- /dev/null
+++ b/2991_libbpf-workaround-Wmaybe-uninitialized-false-pos.patch
@@ -0,0 +1,64 @@
+From git@z Thu Jan  1 00:00:00 1970
+Subject: [PATCH] libbpf: workaround (another) -Wmaybe-uninitialized false
+ positive
+From: Sam James <[email protected]>
+Date: Fri, 06 Sep 2024 14:48:14 +0100
+Message-Id: 
<f6962729197ae7cdf4f6d1512625bd92f2322d31.1725630494.git....@gentoo.org>
+MIME-Version: 1.0
+Content-Type: text/plain; charset="utf-8"
+Content-Transfer-Encoding: 8bit
+
+We get this with GCC 15 -O3 (at least):
+```
+libbpf.c: In function ‘bpf_map__init_kern_struct_ops’:
+libbpf.c:1109:18: error: ‘mod_btf’ may be used uninitialized 
[-Werror=maybe-uninitialized]
+ 1109 |         kern_btf = mod_btf ? mod_btf->btf : obj->btf_vmlinux;
+      |         ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+libbpf.c:1094:28: note: ‘mod_btf’ was declared here
+ 1094 |         struct module_btf *mod_btf;
+      |                            ^~~~~~~
+In function ‘find_struct_ops_kern_types’,
+    inlined from ‘bpf_map__init_kern_struct_ops’ at libbpf.c:1102:8:
+libbpf.c:982:21: error: ‘btf’ may be used uninitialized 
[-Werror=maybe-uninitialized]
+  982 |         kern_type = btf__type_by_id(btf, kern_type_id);
+      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+libbpf.c: In function ‘bpf_map__init_kern_struct_ops’:
+libbpf.c:967:21: note: ‘btf’ was declared here
+  967 |         struct btf *btf;
+      |                     ^~~
+```
+
+This is similar to the other libbpf fix from a few weeks ago for
+the same modelling-errno issue (fab45b962749184e1a1a57c7c583782b78fad539).
+
+Link: https://bugs.gentoo.org/939106
+Signed-off-by: Sam James <[email protected]>
+---
+ tools/lib/bpf/libbpf.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
+index a3be6f8fac09e..7315120574c29 100644
+--- a/tools/lib/bpf/libbpf.c
++++ b/tools/lib/bpf/libbpf.c
+@@ -988,7 +988,7 @@ find_struct_ops_kern_types(struct bpf_object *obj, const 
char *tname_raw,
+ {
+       const struct btf_type *kern_type, *kern_vtype;
+       const struct btf_member *kern_data_member;
+-      struct btf *btf;
++      struct btf *btf = NULL;
+       __s32 kern_vtype_id, kern_type_id;
+       char tname[256];
+       __u32 i;
+@@ -1115,7 +1115,7 @@ static int bpf_map__init_kern_struct_ops(struct bpf_map 
*map)
+       const struct btf *btf = obj->btf;
+       struct bpf_struct_ops *st_ops;
+       const struct btf *kern_btf;
+-      struct module_btf *mod_btf;
++      struct module_btf *mod_btf = NULL;
+       void *data, *kern_data;
+       const char *tname;
+       int err;
+-- 
+2.46.0
+

Reply via email to