Skip to content

Commit 8a3f14b

Browse files
thesamesamanakryiko
authored andcommitted
libbpf: Workaround (another) -Wmaybe-uninitialized false positive
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 (fab45b9). Signed-off-by: Sam James <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://bugs.gentoo.org/939106 Link: https://lore.kernel.org/bpf/f6962729197ae7cdf4f6d1512625bd92f2322d31.1725630494.git.sam@gentoo.org
1 parent f8c6b79 commit 8a3f14b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ find_struct_ops_kern_types(struct bpf_object *obj, const char *tname_raw,
986986
{
987987
const struct btf_type *kern_type, *kern_vtype;
988988
const struct btf_member *kern_data_member;
989-
struct btf *btf;
989+
struct btf *btf = NULL;
990990
__s32 kern_vtype_id, kern_type_id;
991991
char tname[256];
992992
__u32 i;
@@ -1116,7 +1116,7 @@ static int bpf_map__init_kern_struct_ops(struct bpf_map *map)
11161116
const struct btf *btf = obj->btf;
11171117
struct bpf_struct_ops *st_ops;
11181118
const struct btf *kern_btf;
1119-
struct module_btf *mod_btf;
1119+
struct module_btf *mod_btf = NULL;
11201120
void *data, *kern_data;
11211121
const char *tname;
11221122
int err;

0 commit comments

Comments
 (0)