[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251206080556.685835-1-mikhail.v.gavrilov@gmail.com>
Date: Sat, 6 Dec 2025 13:05:56 +0500
From: Mikhail Gavrilov <mikhail.v.gavrilov@...il.com>
To: bpf@...r.kernel.org
Cc: andrii@...nel.org,
ast@...nel.org,
daniel@...earbox.net,
netdev@...r.kernel.org,
fweimer@...hat.com,
andrii.nakryiko@...il.com,
Mikhail Gavrilov <mikhail.v.gavrilov@...il.com>
Subject: [PATCH v3] tools/lib/bpf: fix -Wdiscarded-qualifiers under C23
glibc ≥ 2.42 (GCC 15) defaults to -std=gnu23, which promotes
-Wdiscarded-qualifiers to an error.
In C23, strstr() and strchr() return "const char *".
Declare `res` and `next_path` as const char * — they are never modified.
Keep `sym_sfx` as char * because it is advanced in a loop.
Suggested-by: Florian Weimer <fweimer@...hat.com>
Suggested-by: Andrii Nakryiko <andrii.nakryiko@...il.com>
Signed-off-by: Mikhail Gavrilov <mikhail.v.gavrilov@...il.com>
---
v2: use const char * where possible (Florian, Andrii)
v3: declare res/next_path as const char * (never modified)
keep cast for sym_sfx (advanced in loop)
---
tools/lib/bpf/libbpf.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 3dc8a8078815..81782471f1d0 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -8484,7 +8484,7 @@ static int kallsyms_cb(unsigned long long sym_addr, char sym_type,
struct bpf_object *obj = ctx;
const struct btf_type *t;
struct extern_desc *ext;
- char *res;
+ const char *res;
res = strstr(sym_name, ".llvm.");
if (sym_type == 'd' && res)
@@ -11820,7 +11820,7 @@ static int avail_kallsyms_cb(unsigned long long sym_addr, char sym_type,
*/
char sym_trim[256], *psym_trim = sym_trim, *sym_sfx;
- if (!(sym_sfx = strstr(sym_name, ".llvm.")))
+ if (!(sym_sfx = (char *)strstr(sym_name, ".llvm."))) /* needs mutation */
return 0;
/* psym_trim vs sym_trim dance is done to avoid pointer vs array
@@ -12401,7 +12401,7 @@ static int resolve_full_path(const char *file, char *result, size_t result_sz)
if (!search_paths[i])
continue;
for (s = search_paths[i]; s != NULL; s = strchr(s, ':')) {
- char *next_path;
+ const char *next_path;
int seg_len;
if (s[0] == ':')
--
2.52.0
Powered by blists - more mailing lists