Skip to contentSkip to conversation

bpftool: Fix -Wuninitialized-const-pointer warnings with clang >= 21

PATCH In review Tom Stellard 3 participants 5 messages Sep 17, 2025 – Sep 19, 2025

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

PATCH 1/1 bpftool: Fix -Wuninitialized-const-pointer warnings with clang >= 21

This fixes the build with -Werror -Wall.

btf_dumper.c:71:31: error: variable 'finfo' is uninitialized when passed as a const pointer argument here [-Werror,-Wuninitialized-const-pointer]
71 | info.func_info = ptr_to_u64(&finfo);
| ^~~~~

prog.c:2294:31: error: variable 'func_info' is uninitialized when passed as a const pointer argument here [-Werror,-Wuninitialized-const-pointer]

 2294 |         info.func_info = ptr_to_u64(&func_info);
      |
---
 tools/bpf/bpftool/btf_dumper.c | 2 ++
 tools/bpf/bpftool/prog.c       | 2 ++
 2 files changed, 4 insertions(+)
tools/bpf/bpftool/btf_dumper.c +2 -0
index 4e896d8a2416..363d3e592ce2 100644
@@ -68,6 +68,8 @@ static int dump_prog_id_as_func_ptr(const struct btf_dumper *d,
 	memset(&info, 0, sizeof(info));
 	info.nr_func_info = 1;
 	info.func_info_rec_size = finfo_rec_size;
+	/* Silence -Wuninitialized-const-pointer warning in clang >= 21. */
+	memset(&finfo,  0, sizeof(finfo));
 	info.func_info = ptr_to_u64(&finfo);
 
 	err = bpf_prog_get_info_by_fd(prog_fd, &info, &info_len);
tools/bpf/bpftool/prog.c +2 -0
index 96eea8a67225..b56427a838aa 100644
@@ -2245,6 +2245,8 @@ static char *profile_target_name(int tgt_fd)
 	memset(&info, 0, sizeof(info));
 	info.nr_func_info = 1;
 	info.func_info_rec_size = func_info_rec_size;
+	/* Silence -Wuninitialized-const-pointer warning in clang >= 21. */
+	memset(&func_info,  0, sizeof(func_info));
 	info.func_info = ptr_to_u64(&func_info);
 
 	err = bpf_prog_get_info_by_fd(tgt_fd, &info, &info_len);
Signature · 1 line
2.51.0
maintainer
#1 lore raw

2025-09-17 06:57 UTC-0700 ~ Tom Stellard <[email protected]>

Quoted 21 lines

This fixes the build with -Werror -Wall.

btf_dumper.c:71:31: error: variable 'finfo' is uninitialized when passed as a const pointer argument here [-Werror,-Wuninitialized-const-pointer]
71 | info.func_info = ptr_to_u64(&finfo);
| ^~~~~

prog.c:2294:31: error: variable 'func_info' is uninitialized when passed as a const pointer argument here [-Werror,-Wuninitialized-const-pointer]

 2294 |         info.func_info = ptr_to_u64(&func_info);
      |
---
 tools/bpf/bpftool/btf_dumper.c | 2 ++
 tools/bpf/bpftool/prog.c       | 2 ++
 2 files changed, 4 insertions(+)
tools/bpf/bpftool/btf_dumper.c +0 -0
index 4e896d8a2416..363d3e592ce2 100644

tools/bpf/bpftool/btf_dumper.c static int dump_prog_id_as_func_ptr(const struct btf_dumper *d, · line 72

Quoted 5 lines
tools/bpf/bpftool/btf_dumper.c +2 -0
@@ -68,6 +68,8 @@ static int dump_prog_id_as_func_ptr(const struct btf_dumper *d,
 	memset(&info, 0, sizeof(info));
 	info.nr_func_info = 1;
 	info.func_info_rec_size = finfo_rec_size;
+	/* Silence -Wuninitialized-const-pointer warning in clang >= 21. */
+	memset(&finfo,  0, sizeof(finfo));

Thanks for this! How about simply initialising the variable when we declare it, instead?

	struct bpf_func_info finfo = {};

This would avoid adding the memset() and comment in the middle of the function, and keep it slightly more readable?

Thanks,
Quentin

#2 lore raw

PATCH 1/1 bpftool: Fix -Wuninitialized-const-pointer warnings with clang >= 21 v2

This fixes the build with -Werror -Wall.

btf_dumper.c:71:31: error: variable 'finfo' is uninitialized when passed as a const pointer argument here [-Werror,-Wuninitialized-const-pointer]
71 | info.func_info = ptr_to_u64(&finfo);
| ^~~~~

prog.c:2294:31: error: variable 'func_info' is uninitialized when passed as a const pointer argument here [-Werror,-Wuninitialized-const-pointer]

 2294 |         info.func_info = ptr_to_u64(&func_info);
      |

v2:
- Initialize instead of using memset.

---
 tools/bpf/bpftool/btf_dumper.c | 4 +++-
 tools/bpf/bpftool/prog.c       | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)
tools/bpf/bpftool/btf_dumper.c +3 -1
index 4e896d8a2416..89715c32a1a3 100644
@@ -38,7 +38,9 @@ static int dump_prog_id_as_func_ptr(const struct btf_dumper *d,
 	__u32 info_len = sizeof(info);
 	const char *prog_name = NULL;
 	struct btf *prog_btf = NULL;
-	struct bpf_func_info finfo;
+	/* Initialize finfo to silence -Wuninitialized-const-pointer warning
+	 * in clang >= 21. */
+	struct bpf_func_info finfo = {};
 	__u32 finfo_rec_size;
 	char prog_str[1024];
 	int err;
tools/bpf/bpftool/prog.c +3 -1
index 96eea8a67225..2540f570a38b 100644
@@ -2216,7 +2216,9 @@ static void profile_print_readings(void)
 
 static char *profile_target_name(int tgt_fd)
 {
-	struct bpf_func_info func_info;
+	/* Initialize func_info to silence -Wuninitialized-const-pointer
+	 * warning in clang >= 21. */
+	struct bpf_func_info func_info = {};
 	struct bpf_prog_info info = {};
 	__u32 info_len = sizeof(info);
 	const struct btf_type *t;
Signature · 1 line
2.51.0
maintainer Acked-by on v1 1/1
#3 lore raw

Re: [PATCH] bpftool: Fix -Wuninitialized-const-pointer warnings with clang >= 21 v2

2025-09-17 11:38 UTC-0700 ~ Tom Stellard <[email protected]>

Quoted 6 lines

This fixes the build with -Werror -Wall.

btf_dumper.c:71:31: error: variable 'finfo' is uninitialized when passed as a const pointer argument here [-Werror,-Wuninitialized-const-pointer]
71 | info.func_info = ptr_to_u64(&finfo);
| ^~~~~

Quoted 8 lines

prog.c:2294:31: error: variable 'func_info' is uninitialized when passed as a const pointer argument here [-Werror,-Wuninitialized-const-pointer]

 2294 |         info.func_info = ptr_to_u64(&func_info);
      |

v2:
- Initialize instead of using memset.

Thank you!

Suggestion for next time, the "v2" should go in the prefix of your email's subject ("[PATCH bpf-next v2] bpftool: ..."), or it risks ending up in the commit title. But no need to resend for that.

Quentin

#4 lore raw

Re: [PATCH] bpftool: Fix -Wuninitialized-const-pointer warnings with clang >= 21 v2

In reply to Tom Stellard
Quoted 25 lines · Tom Stellard

This fixes the build with -Werror -Wall.

btf_dumper.c:71:31: error: variable 'finfo' is uninitialized when passed as a const pointer argument here [-Werror,-Wuninitialized-const-pointer]
71 | info.func_info = ptr_to_u64(&finfo);
| ^~~~~

prog.c:2294:31: error: variable 'func_info' is uninitialized when passed as a const pointer argument here [-Werror,-Wuninitialized-const-pointer]

 2294 |         info.func_info = ptr_to_u64(&func_info);
      |

v2:
- Initialize instead of using memset.

---
 tools/bpf/bpftool/btf_dumper.c | 4 +++-
 tools/bpf/bpftool/prog.c       | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)
tools/bpf/bpftool/btf_dumper.c +0 -0
index 4e896d8a2416..89715c32a1a3 100644

tools/bpf/bpftool/btf_dumper.c static int dump_prog_id_as_func_ptr(const struct btf_dumper *d, · line 42

Quoted 6 lines
tools/bpf/bpftool/btf_dumper.c +2 -1
@@ -38,7 +38,9 @@ static int dump_prog_id_as_func_ptr(const struct btf_dumper *d,
        __u32 info_len = sizeof(info);
        const char *prog_name = NULL;
        struct btf *prog_btf = NULL;
-       struct bpf_func_info finfo;
+       /* Initialize finfo to silence -Wuninitialized-const-pointer warning
+        * in clang >= 21. */

incorrectly formatted comments, but also I'm not sure they add much useful information. So I just dropped them

Also I dropped "v2" suffix from the commit header, as mentioned earlier, v2 should go into the [PATCH ...] part.

Applied to bpf-next, thanks.

Quoted 23 lines
tools/bpf/bpftool/btf_dumper.c +1 -0
+       struct bpf_func_info finfo = {};
        __u32 finfo_rec_size;
        char prog_str[1024];
        int err;
tools/bpf/bpftool/prog.c +3 -2
index 96eea8a67225..2540f570a38b 100644
@@ -2216,7 +2216,9 @@ static void profile_print_readings(void)
 
 static char *profile_target_name(int tgt_fd)
 {
-       struct bpf_func_info func_info;
+       /* Initialize func_info to silence -Wuninitialized-const-pointer
+        * warning in clang >= 21. */
+       struct bpf_func_info func_info = {};
        struct bpf_prog_info info = {};
        __u32 info_len = sizeof(info);
        const struct btf_type *t;
--

2.51.0