* [PATCH 0/4] Fixes for gcc 16.0.1
@ 2026-01-20 22:08 Arnaldo Carvalho de Melo
2026-01-20 22:08 ` [PATCH 1/4] perf tests sw-clock: Mark the volatile tmp variable as __maybe_unused Arnaldo Carvalho de Melo
` (4 more replies)
0 siblings, 5 replies; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-01-20 22:08 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
linux-perf-users, Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Hi,
A bunch of fixes for recent gcc versions,
- Arnaldo
Arnaldo Carvalho de Melo (4):
perf tests sw-clock: Mark the volatile tmp variable as __maybe_unused
perf trace: Deal with compiler const checks
perf list: Don't write to const memory
perf list: Signal changing const memory is ok
tools/perf/builtin-trace.c | 2 +-
tools/perf/tests/sw-clock.c | 3 ++-
tools/perf/util/print-events.c | 15 ++++++---------
3 files changed, 9 insertions(+), 11 deletions(-)
--
2.52.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 1/4] perf tests sw-clock: Mark the volatile tmp variable as __maybe_unused
2026-01-20 22:08 [PATCH 0/4] Fixes for gcc 16.0.1 Arnaldo Carvalho de Melo
@ 2026-01-20 22:08 ` Arnaldo Carvalho de Melo
2026-01-20 22:08 ` [PATCH 2/4] perf trace: Deal with compiler const checks Arnaldo Carvalho de Melo
` (3 subsequent siblings)
4 siblings, 0 replies; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-01-20 22:08 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
linux-perf-users, Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
As it is just used to waste some cycles, not being used as all, to
silence some compilers.
Noticed with gcc version 16.0.1 20260115 on fedora 44:
tests/sw-clock.c: In function '__test__sw_clock_freq':
tests/sw-clock.c:31:22: error: variable 'tmp' set but not used [-Werror=unused-but-set-variable=]
31 | volatile int tmp = 0;
| ^~~
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/tests/sw-clock.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/perf/tests/sw-clock.c b/tools/perf/tests/sw-clock.c
index 4a2ad7176fa07be0..b6e46975379cd5ef 100644
--- a/tools/perf/tests/sw-clock.c
+++ b/tools/perf/tests/sw-clock.c
@@ -5,6 +5,7 @@
#include <stdlib.h>
#include <signal.h>
#include <sys/mman.h>
+#include <linux/compiler.h>
#include <linux/string.h>
#include "tests.h"
@@ -28,7 +29,7 @@
static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
{
int i, err = -1;
- volatile int tmp = 0;
+ volatile int tmp __maybe_unused = 0;
u64 total_periods = 0;
int nr_samples = 0;
char sbuf[STRERR_BUFSIZE];
--
2.52.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 2/4] perf trace: Deal with compiler const checks
2026-01-20 22:08 [PATCH 0/4] Fixes for gcc 16.0.1 Arnaldo Carvalho de Melo
2026-01-20 22:08 ` [PATCH 1/4] perf tests sw-clock: Mark the volatile tmp variable as __maybe_unused Arnaldo Carvalho de Melo
@ 2026-01-20 22:08 ` Arnaldo Carvalho de Melo
2026-01-20 22:08 ` [PATCH 3/4] perf list: Don't write to const memory Arnaldo Carvalho de Melo
` (2 subsequent siblings)
4 siblings, 0 replies; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-01-20 22:08 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
linux-perf-users, Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
The strchr() function these days return const/non-const based on the arg
it receives, and sometimes we need to use casts when we're dealing with
variables that are used in code that needs to safely change the returned
value and sometimes not (as it points to really const areas).
Tweak one such case.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-trace.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 58a32adafddff7f5..8df5ca44e4f91529 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -5190,7 +5190,7 @@ static int trace__parse_events_option(const struct option *opt, const char *str,
}
while (1) {
- if ((sep = strchr(s, ',')) != NULL)
+ if ((sep = strchr((char *)s, ',')) != NULL)
*sep = '\0';
list = 0;
--
2.52.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 3/4] perf list: Don't write to const memory
2026-01-20 22:08 [PATCH 0/4] Fixes for gcc 16.0.1 Arnaldo Carvalho de Melo
2026-01-20 22:08 ` [PATCH 1/4] perf tests sw-clock: Mark the volatile tmp variable as __maybe_unused Arnaldo Carvalho de Melo
2026-01-20 22:08 ` [PATCH 2/4] perf trace: Deal with compiler const checks Arnaldo Carvalho de Melo
@ 2026-01-20 22:08 ` Arnaldo Carvalho de Melo
2026-01-21 11:25 ` David Laight
2026-01-21 22:17 ` David Laight
2026-01-20 22:09 ` [PATCH 4/4] perf list: Signal changing const memory is ok Arnaldo Carvalho de Melo
2026-01-20 23:42 ` [PATCH 0/4] Fixes for gcc 16.0.1 Ian Rogers
4 siblings, 2 replies; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-01-20 22:08 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
linux-perf-users, Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Something now detected on fedora 44, where strchr() returns const if it
is passed a const pointer:
util/print-events.c: In function 'print_sdt_events':
util/print-events.c:89:29: error: initialization discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
89 | char *bid = strchr(sdt_name->s, '@');
| ^~~~~~
Fix it by using strnchr() if strchr finds the separator instead of
temporarily scrubbing it with '\0'.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/print-events.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
index 8f3ed83853a9e468..898cf426509790cd 100644
--- a/tools/perf/util/print-events.c
+++ b/tools/perf/util/print-events.c
@@ -97,14 +97,11 @@ void print_sdt_events(const struct print_callbacks *print_cb, void *print_state)
} else {
next_sdt_name = strlist__next(sdt_name);
if (next_sdt_name) {
- char *bid2 = strchr(next_sdt_name->s, '@');
-
- if (bid2)
- *bid2 = '\0';
- if (strcmp(sdt_name->s, next_sdt_name->s) == 0)
- show_detail = true;
- if (bid2)
- *bid2 = '@';
+ const char *bid2 = strchr(next_sdt_name->s, '@');
+
+ show_detail = bid2 ?
+ strncmp(sdt_name->s, next_sdt_name->s, bid2 - next_sdt_name->s) == 0 :
+ strcmp(sdt_name->s, next_sdt_name->s) == 0;
}
}
last_sdt_name = sdt_name->s;
--
2.52.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 4/4] perf list: Signal changing const memory is ok
2026-01-20 22:08 [PATCH 0/4] Fixes for gcc 16.0.1 Arnaldo Carvalho de Melo
` (2 preceding siblings ...)
2026-01-20 22:08 ` [PATCH 3/4] perf list: Don't write to const memory Arnaldo Carvalho de Melo
@ 2026-01-20 22:09 ` Arnaldo Carvalho de Melo
2026-01-20 23:42 ` [PATCH 0/4] Fixes for gcc 16.0.1 Ian Rogers
4 siblings, 0 replies; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-01-20 22:09 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
linux-perf-users, Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
In this case its a temp list that is created just for listing events and
will be deleted at the end, so just cast it to get rid of the compiler
warning.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/print-events.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
index 898cf426509790cd..57c06f6bca1fced6 100644
--- a/tools/perf/util/print-events.c
+++ b/tools/perf/util/print-events.c
@@ -86,7 +86,7 @@ void print_sdt_events(const struct print_callbacks *print_cb, void *print_state)
strlist__for_each_entry(sdt_name, sdtlist) {
bool show_detail = false;
- char *bid = strchr(sdt_name->s, '@');
+ char *bid = (char *)strchr(sdt_name->s, '@');
char *evt_name = NULL;
if (bid)
--
2.52.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH 0/4] Fixes for gcc 16.0.1
2026-01-20 22:08 [PATCH 0/4] Fixes for gcc 16.0.1 Arnaldo Carvalho de Melo
` (3 preceding siblings ...)
2026-01-20 22:09 ` [PATCH 4/4] perf list: Signal changing const memory is ok Arnaldo Carvalho de Melo
@ 2026-01-20 23:42 ` Ian Rogers
2026-01-20 23:50 ` Arnaldo Carvalho de Melo
4 siblings, 1 reply; 13+ messages in thread
From: Ian Rogers @ 2026-01-20 23:42 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Namhyung Kim, Ingo Molnar, Thomas Gleixner, James Clark,
Jiri Olsa, Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
linux-perf-users, Arnaldo Carvalho de Melo
On Tue, Jan 20, 2026 at 2:11 PM Arnaldo Carvalho de Melo
<acme@kernel.org> wrote:
>
> From: Arnaldo Carvalho de Melo <acme@redhat.com>
>
> Hi,
>
> A bunch of fixes for recent gcc versions,
>
> - Arnaldo
Reviewed-by: Ian Rogers <irogers@google.com>
These look like the least bad resolutions to the new warnings, thanks!
Ian
> Arnaldo Carvalho de Melo (4):
> perf tests sw-clock: Mark the volatile tmp variable as __maybe_unused
> perf trace: Deal with compiler const checks
> perf list: Don't write to const memory
> perf list: Signal changing const memory is ok
>
> tools/perf/builtin-trace.c | 2 +-
> tools/perf/tests/sw-clock.c | 3 ++-
> tools/perf/util/print-events.c | 15 ++++++---------
> 3 files changed, 9 insertions(+), 11 deletions(-)
>
> --
> 2.52.0
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 0/4] Fixes for gcc 16.0.1
2026-01-20 23:42 ` [PATCH 0/4] Fixes for gcc 16.0.1 Ian Rogers
@ 2026-01-20 23:50 ` Arnaldo Carvalho de Melo
0 siblings, 0 replies; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-01-20 23:50 UTC (permalink / raw)
To: Ian Rogers
Cc: Namhyung Kim, Ingo Molnar, Thomas Gleixner, James Clark,
Jiri Olsa, Adrian Hunter, Kan Liang, Clark Williams, linux-kernel,
linux-perf-users, Arnaldo Carvalho de Melo
On Tue, Jan 20, 2026 at 03:42:42PM -0800, Ian Rogers wrote:
> On Tue, Jan 20, 2026 at 2:11 PM Arnaldo Carvalho de Melo
> <acme@kernel.org> wrote:
> >
> > From: Arnaldo Carvalho de Melo <acme@redhat.com>
> >
> > Hi,
> >
> > A bunch of fixes for recent gcc versions,
> >
> > - Arnaldo
>
> Reviewed-by: Ian Rogers <irogers@google.com>
>
> These look like the least bad resolutions to the new warnings, thanks!
Thanks!
- Arnaldo
> Ian
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 3/4] perf list: Don't write to const memory
2026-01-20 22:08 ` [PATCH 3/4] perf list: Don't write to const memory Arnaldo Carvalho de Melo
@ 2026-01-21 11:25 ` David Laight
2026-01-21 18:40 ` Arnaldo Carvalho de Melo
2026-01-21 22:17 ` David Laight
1 sibling, 1 reply; 13+ messages in thread
From: David Laight @ 2026-01-21 11:25 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Namhyung Kim, Ingo Molnar, Thomas Gleixner, James Clark,
Jiri Olsa, Ian Rogers, Adrian Hunter, Kan Liang, Clark Williams,
linux-kernel, linux-perf-users, Arnaldo Carvalho de Melo
On Tue, 20 Jan 2026 19:08:59 -0300
Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> From: Arnaldo Carvalho de Melo <acme@redhat.com>
>
> Something now detected on fedora 44, where strchr() returns const if it
> is passed a const pointer:
>
> util/print-events.c: In function 'print_sdt_events':
> util/print-events.c:89:29: error: initialization discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
> 89 | char *bid = strchr(sdt_name->s, '@');
> | ^~~~~~
>
> Fix it by using strnchr() if strchr finds the separator instead of
> temporarily scrubbing it with '\0'.
>
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
> tools/perf/util/print-events.c | 13 +++++--------
> 1 file changed, 5 insertions(+), 8 deletions(-)
>
> diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
> index 8f3ed83853a9e468..898cf426509790cd 100644
> --- a/tools/perf/util/print-events.c
> +++ b/tools/perf/util/print-events.c
> @@ -97,14 +97,11 @@ void print_sdt_events(const struct print_callbacks *print_cb, void *print_state)
> } else {
> next_sdt_name = strlist__next(sdt_name);
> if (next_sdt_name) {
> - char *bid2 = strchr(next_sdt_name->s, '@');
> -
> - if (bid2)
> - *bid2 = '\0';
> - if (strcmp(sdt_name->s, next_sdt_name->s) == 0)
> - show_detail = true;
> - if (bid2)
> - *bid2 = '@';
> + const char *bid2 = strchr(next_sdt_name->s, '@');
> +
> + show_detail = bid2 ?
> + strncmp(sdt_name->s, next_sdt_name->s, bid2 - next_sdt_name->s) == 0 :
> + strcmp(sdt_name->s, next_sdt_name->s) == 0;
You could use:
show_detail = strncmp(sdt_name->s, next_sdt_name->s, strcspn(sdt_name->s, "@"));
strcspn() will be slower, but it is succinct.
I'm sure there is a function like strchr() that returns a pointer to the '\0'
when the character isn't found - but I can't remember what it is called :-(
David
> }
> }
> last_sdt_name = sdt_name->s;
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 3/4] perf list: Don't write to const memory
2026-01-21 11:25 ` David Laight
@ 2026-01-21 18:40 ` Arnaldo Carvalho de Melo
2026-01-21 18:44 ` Ian Rogers
0 siblings, 1 reply; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-01-21 18:40 UTC (permalink / raw)
To: David Laight
Cc: Namhyung Kim, Ingo Molnar, Thomas Gleixner, James Clark,
Jiri Olsa, Ian Rogers, Adrian Hunter, Kan Liang, Clark Williams,
linux-kernel, linux-perf-users, Arnaldo Carvalho de Melo
On Wed, Jan 21, 2026 at 11:25:36AM +0000, David Laight wrote:
> On Tue, 20 Jan 2026 19:08:59 -0300
> Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
>
> > From: Arnaldo Carvalho de Melo <acme@redhat.com>
> >
> > Something now detected on fedora 44, where strchr() returns const if it
> > is passed a const pointer:
> >
> > util/print-events.c: In function 'print_sdt_events':
> > util/print-events.c:89:29: error: initialization discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
> > 89 | char *bid = strchr(sdt_name->s, '@');
> > | ^~~~~~
> >
> > Fix it by using strnchr() if strchr finds the separator instead of
> > temporarily scrubbing it with '\0'.
> >
> > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> > ---
> > tools/perf/util/print-events.c | 13 +++++--------
> > 1 file changed, 5 insertions(+), 8 deletions(-)
> >
> > diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
> > index 8f3ed83853a9e468..898cf426509790cd 100644
> > --- a/tools/perf/util/print-events.c
> > +++ b/tools/perf/util/print-events.c
> > @@ -97,14 +97,11 @@ void print_sdt_events(const struct print_callbacks *print_cb, void *print_state)
> > } else {
> > next_sdt_name = strlist__next(sdt_name);
> > if (next_sdt_name) {
> > - char *bid2 = strchr(next_sdt_name->s, '@');
> > -
> > - if (bid2)
> > - *bid2 = '\0';
> > - if (strcmp(sdt_name->s, next_sdt_name->s) == 0)
> > - show_detail = true;
> > - if (bid2)
> > - *bid2 = '@';
> > + const char *bid2 = strchr(next_sdt_name->s, '@');
> > +
> > + show_detail = bid2 ?
> > + strncmp(sdt_name->s, next_sdt_name->s, bid2 - next_sdt_name->s) == 0 :
> > + strcmp(sdt_name->s, next_sdt_name->s) == 0;
>
> You could use:
> show_detail = strncmp(sdt_name->s, next_sdt_name->s, strcspn(sdt_name->s, "@"));
> strcspn() will be slower, but it is succinct.
That works.
> I'm sure there is a function like strchr() that returns a pointer to the '\0'
> when the character isn't found - but I can't remember what it is called :-(
strchrnull()
And this also works and I'll use it:
const char *bid2 = strchrnul(next_sdt_name->s, '@');
show_detail = strncmp(sdt_name->s, next_sdt_name->s, bid2 - next_sdt_name->s) == 0;
This way the patch ends up as below, thanks for the suggestion!
Ian, I think I can keep your Reviewed-by, ok?
Cheers,
- Arnaldo
From 02b160f200a2224e8ecf490cf2e316b1a994509a Mon Sep 17 00:00:00 2001
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Date: Tue, 20 Jan 2026 18:16:09 -0300
Subject: [PATCH 1/1] perf list: Don't write to const memory
Something now detected on fedora 44, where strchr() returns const if it
is passed a const pointer:
util/print-events.c: In function 'print_sdt_events':
util/print-events.c:89:29: error: initialization discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
89 | char *bid = strchr(sdt_name->s, '@');
| ^~~~~~
Fix it by using strncnmp() + strchrnul() instead of temporarily
scrubbing it with '\0'.
Reviewed-by: Ian Rogers <irogers@google.com>
Suggested-by: David Laight <david.laight.linux@gmail.com>
Link: https://lore.kernel.org/r/20260121112536.27fd5d11@pumpkin
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/print-events.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
index 4bbcdbf05b843302..cb27e2898aa0558f 100644
--- a/tools/perf/util/print-events.c
+++ b/tools/perf/util/print-events.c
@@ -97,14 +97,9 @@ void print_sdt_events(const struct print_callbacks *print_cb, void *print_state)
} else {
next_sdt_name = strlist__next(sdt_name);
if (next_sdt_name) {
- char *bid2 = strchr(next_sdt_name->s, '@');
-
- if (bid2)
- *bid2 = '\0';
- if (strcmp(sdt_name->s, next_sdt_name->s) == 0)
- show_detail = true;
- if (bid2)
- *bid2 = '@';
+ const char *bid2 = strchrnul(next_sdt_name->s, '@');
+
+ show_detail = strncmp(sdt_name->s, next_sdt_name->s, bid2 - next_sdt_name->s) == 0;
}
}
last_sdt_name = sdt_name->s;
--
2.52.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH 3/4] perf list: Don't write to const memory
2026-01-21 18:40 ` Arnaldo Carvalho de Melo
@ 2026-01-21 18:44 ` Ian Rogers
0 siblings, 0 replies; 13+ messages in thread
From: Ian Rogers @ 2026-01-21 18:44 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: David Laight, Namhyung Kim, Ingo Molnar, Thomas Gleixner,
James Clark, Jiri Olsa, Adrian Hunter, Kan Liang, Clark Williams,
linux-kernel, linux-perf-users, Arnaldo Carvalho de Melo
On Wed, Jan 21, 2026 at 10:40 AM Arnaldo Carvalho de Melo
<acme@kernel.org> wrote:
>
> On Wed, Jan 21, 2026 at 11:25:36AM +0000, David Laight wrote:
> > On Tue, 20 Jan 2026 19:08:59 -0300
> > Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> >
> > > From: Arnaldo Carvalho de Melo <acme@redhat.com>
> > >
> > > Something now detected on fedora 44, where strchr() returns const if it
> > > is passed a const pointer:
> > >
> > > util/print-events.c: In function 'print_sdt_events':
> > > util/print-events.c:89:29: error: initialization discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
> > > 89 | char *bid = strchr(sdt_name->s, '@');
> > > | ^~~~~~
> > >
> > > Fix it by using strnchr() if strchr finds the separator instead of
> > > temporarily scrubbing it with '\0'.
> > >
> > > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> > > ---
> > > tools/perf/util/print-events.c | 13 +++++--------
> > > 1 file changed, 5 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
> > > index 8f3ed83853a9e468..898cf426509790cd 100644
> > > --- a/tools/perf/util/print-events.c
> > > +++ b/tools/perf/util/print-events.c
> > > @@ -97,14 +97,11 @@ void print_sdt_events(const struct print_callbacks *print_cb, void *print_state)
> > > } else {
> > > next_sdt_name = strlist__next(sdt_name);
> > > if (next_sdt_name) {
> > > - char *bid2 = strchr(next_sdt_name->s, '@');
> > > -
> > > - if (bid2)
> > > - *bid2 = '\0';
> > > - if (strcmp(sdt_name->s, next_sdt_name->s) == 0)
> > > - show_detail = true;
> > > - if (bid2)
> > > - *bid2 = '@';
> > > + const char *bid2 = strchr(next_sdt_name->s, '@');
> > > +
> > > + show_detail = bid2 ?
> > > + strncmp(sdt_name->s, next_sdt_name->s, bid2 - next_sdt_name->s) == 0 :
> > > + strcmp(sdt_name->s, next_sdt_name->s) == 0;
> >
> > You could use:
> > show_detail = strncmp(sdt_name->s, next_sdt_name->s, strcspn(sdt_name->s, "@"));
> > strcspn() will be slower, but it is succinct.
>
> That works.
>
> > I'm sure there is a function like strchr() that returns a pointer to the '\0'
> > when the character isn't found - but I can't remember what it is called :-(
>
> strchrnull()
>
> And this also works and I'll use it:
>
> const char *bid2 = strchrnul(next_sdt_name->s, '@');
>
> show_detail = strncmp(sdt_name->s, next_sdt_name->s, bid2 - next_sdt_name->s) == 0;
>
> This way the patch ends up as below, thanks for the suggestion!
>
> Ian, I think I can keep your Reviewed-by, ok?
Yup.
Thanks,
Ian
> Cheers,
>
> - Arnaldo
>
> From 02b160f200a2224e8ecf490cf2e316b1a994509a Mon Sep 17 00:00:00 2001
> From: Arnaldo Carvalho de Melo <acme@redhat.com>
> Date: Tue, 20 Jan 2026 18:16:09 -0300
> Subject: [PATCH 1/1] perf list: Don't write to const memory
>
> Something now detected on fedora 44, where strchr() returns const if it
> is passed a const pointer:
>
> util/print-events.c: In function 'print_sdt_events':
> util/print-events.c:89:29: error: initialization discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
> 89 | char *bid = strchr(sdt_name->s, '@');
> | ^~~~~~
>
> Fix it by using strncnmp() + strchrnul() instead of temporarily
> scrubbing it with '\0'.
>
> Reviewed-by: Ian Rogers <irogers@google.com>
> Suggested-by: David Laight <david.laight.linux@gmail.com>
> Link: https://lore.kernel.org/r/20260121112536.27fd5d11@pumpkin
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
> tools/perf/util/print-events.c | 11 +++--------
> 1 file changed, 3 insertions(+), 8 deletions(-)
>
> diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
> index 4bbcdbf05b843302..cb27e2898aa0558f 100644
> --- a/tools/perf/util/print-events.c
> +++ b/tools/perf/util/print-events.c
> @@ -97,14 +97,9 @@ void print_sdt_events(const struct print_callbacks *print_cb, void *print_state)
> } else {
> next_sdt_name = strlist__next(sdt_name);
> if (next_sdt_name) {
> - char *bid2 = strchr(next_sdt_name->s, '@');
> -
> - if (bid2)
> - *bid2 = '\0';
> - if (strcmp(sdt_name->s, next_sdt_name->s) == 0)
> - show_detail = true;
> - if (bid2)
> - *bid2 = '@';
> + const char *bid2 = strchrnul(next_sdt_name->s, '@');
> +
> + show_detail = strncmp(sdt_name->s, next_sdt_name->s, bid2 - next_sdt_name->s) == 0;
> }
> }
> last_sdt_name = sdt_name->s;
> --
> 2.52.0
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 3/4] perf list: Don't write to const memory
2026-01-20 22:08 ` [PATCH 3/4] perf list: Don't write to const memory Arnaldo Carvalho de Melo
2026-01-21 11:25 ` David Laight
@ 2026-01-21 22:17 ` David Laight
2026-01-22 1:10 ` Arnaldo Carvalho de Melo
1 sibling, 1 reply; 13+ messages in thread
From: David Laight @ 2026-01-21 22:17 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Namhyung Kim, Ingo Molnar, Thomas Gleixner, James Clark,
Jiri Olsa, Ian Rogers, Adrian Hunter, Kan Liang, Clark Williams,
linux-kernel, linux-perf-users, Arnaldo Carvalho de Melo
On Tue, 20 Jan 2026 19:08:59 -0300
Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> From: Arnaldo Carvalho de Melo <acme@redhat.com>
>
> Something now detected on fedora 44, where strchr() returns const if it
> is passed a const pointer:
>
> util/print-events.c: In function 'print_sdt_events':
> util/print-events.c:89:29: error: initialization discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
> 89 | char *bid = strchr(sdt_name->s, '@');
> | ^~~~~~
>
> Fix it by using strnchr() if strchr finds the separator instead of
> temporarily scrubbing it with '\0'.
I've just looked at the full function to see WTF it is doing.
You've fixed the second strchr() not the one the compiler bleated about.
Line 89 is followed by:
if (bid)
*bid++ = 0;
but if it is NULL there is a fair chance the code will just explode a bit later on.
I suspect it is an error if the strings aren't "name@bar"
'show_detail' seems to be set if either the previous or next entries in the
list/tree have the same "name" - which seems strange to me.
The while thing needs more work :-(
David
>
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
> tools/perf/util/print-events.c | 13 +++++--------
> 1 file changed, 5 insertions(+), 8 deletions(-)
>
> diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
> index 8f3ed83853a9e468..898cf426509790cd 100644
> --- a/tools/perf/util/print-events.c
> +++ b/tools/perf/util/print-events.c
> @@ -97,14 +97,11 @@ void print_sdt_events(const struct print_callbacks *print_cb, void *print_state)
> } else {
> next_sdt_name = strlist__next(sdt_name);
> if (next_sdt_name) {
> - char *bid2 = strchr(next_sdt_name->s, '@');
> -
> - if (bid2)
> - *bid2 = '\0';
> - if (strcmp(sdt_name->s, next_sdt_name->s) == 0)
> - show_detail = true;
> - if (bid2)
> - *bid2 = '@';
> + const char *bid2 = strchr(next_sdt_name->s, '@');
> +
> + show_detail = bid2 ?
> + strncmp(sdt_name->s, next_sdt_name->s, bid2 - next_sdt_name->s) == 0 :
> + strcmp(sdt_name->s, next_sdt_name->s) == 0;
> }
> }
> last_sdt_name = sdt_name->s;
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 3/4] perf list: Don't write to const memory
2026-01-21 22:17 ` David Laight
@ 2026-01-22 1:10 ` Arnaldo Carvalho de Melo
2026-01-22 9:55 ` David Laight
0 siblings, 1 reply; 13+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-01-22 1:10 UTC (permalink / raw)
To: David Laight
Cc: Namhyung Kim, Ingo Molnar, Thomas Gleixner, James Clark,
Jiri Olsa, Ian Rogers, Adrian Hunter, Kan Liang, Clark Williams,
linux-kernel, linux-perf-users, Arnaldo Carvalho de Melo
On Wed, Jan 21, 2026 at 10:17:13PM +0000, David Laight wrote:
> On Tue, 20 Jan 2026 19:08:59 -0300
> Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
>
> > From: Arnaldo Carvalho de Melo <acme@redhat.com>
> >
> > Something now detected on fedora 44, where strchr() returns const if it
> > is passed a const pointer:
> >
> > util/print-events.c: In function 'print_sdt_events':
> > util/print-events.c:89:29: error: initialization discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
> > 89 | char *bid = strchr(sdt_name->s, '@');
> > | ^~~~~~
> >
> > Fix it by using strnchr() if strchr finds the separator instead of
> > temporarily scrubbing it with '\0'.
>
> I've just looked at the full function to see WTF it is doing.
> You've fixed the second strchr() not the one the compiler bleated about.
It complained about both, no?
> Line 89 is followed by:
> if (bid)
> *bid++ = 0;
> but if it is NULL there is a fair chance the code will just explode a bit later on.
Why, can you elaborate?
> I suspect it is an error if the strings aren't "name@bar"
> 'show_detail' seems to be set if either the previous or next entries in the
> list/tree have the same "name" - which seems strange to me.
All this is strange, a corner case, it looks as if we may have multiple
binaries, differentiated by buildids, that would have different SDTs.
The code seems to be trying to reduce the amount of info (not showing
the buildid if there are no more at that point multiple versions of a
DSO with SDTs in place).
Further analysis of the changesets that put all this in place is needed
to clarify, but looking just at fixing what the compiler is complaining,
do you think the patches are bad?
- Arnaldo
> The while thing needs more work :-(
>
> David
>
> >
> > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> > ---
> > tools/perf/util/print-events.c | 13 +++++--------
> > 1 file changed, 5 insertions(+), 8 deletions(-)
> >
> > diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
> > index 8f3ed83853a9e468..898cf426509790cd 100644
> > --- a/tools/perf/util/print-events.c
> > +++ b/tools/perf/util/print-events.c
> > @@ -97,14 +97,11 @@ void print_sdt_events(const struct print_callbacks *print_cb, void *print_state)
> > } else {
> > next_sdt_name = strlist__next(sdt_name);
> > if (next_sdt_name) {
> > - char *bid2 = strchr(next_sdt_name->s, '@');
> > -
> > - if (bid2)
> > - *bid2 = '\0';
> > - if (strcmp(sdt_name->s, next_sdt_name->s) == 0)
> > - show_detail = true;
> > - if (bid2)
> > - *bid2 = '@';
> > + const char *bid2 = strchr(next_sdt_name->s, '@');
> > +
> > + show_detail = bid2 ?
> > + strncmp(sdt_name->s, next_sdt_name->s, bid2 - next_sdt_name->s) == 0 :
> > + strcmp(sdt_name->s, next_sdt_name->s) == 0;
> > }
> > }
> > last_sdt_name = sdt_name->s;
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 3/4] perf list: Don't write to const memory
2026-01-22 1:10 ` Arnaldo Carvalho de Melo
@ 2026-01-22 9:55 ` David Laight
0 siblings, 0 replies; 13+ messages in thread
From: David Laight @ 2026-01-22 9:55 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Namhyung Kim, Ingo Molnar, Thomas Gleixner, James Clark,
Jiri Olsa, Ian Rogers, Adrian Hunter, Kan Liang, Clark Williams,
linux-kernel, linux-perf-users, Arnaldo Carvalho de Melo
On Wed, 21 Jan 2026 22:10:18 -0300
Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> On Wed, Jan 21, 2026 at 10:17:13PM +0000, David Laight wrote:
> > On Tue, 20 Jan 2026 19:08:59 -0300
> > Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> >
> > > From: Arnaldo Carvalho de Melo <acme@redhat.com>
> > >
> > > Something now detected on fedora 44, where strchr() returns const if it
> > > is passed a const pointer:
> > >
> > > util/print-events.c: In function 'print_sdt_events':
> > > util/print-events.c:89:29: error: initialization discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
> > > 89 | char *bid = strchr(sdt_name->s, '@');
> > > | ^~~~~~
> > >
> > > Fix it by using strnchr() if strchr finds the separator instead of
> > > temporarily scrubbing it with '\0'.
> >
> > I've just looked at the full function to see WTF it is doing.
> > You've fixed the second strchr() not the one the compiler bleated about.
>
> It complained about both, no?
>
> > Line 89 is followed by:
> > if (bid)
> > *bid++ = 0;
> > but if it is NULL there is a fair chance the code will just explode a bit later on.
>
> Why, can you elaborate?
I don't see why it can't end up in:
if (show_detail) {
char *path = build_id_cache__origname(bid);
with 'bid == NULL' and the function just dereferences it.
>
> > I suspect it is an error if the strings aren't "name@bar"
>
> > 'show_detail' seems to be set if either the previous or next entries in the
> > list/tree have the same "name" - which seems strange to me.
>
> All this is strange, a corner case, it looks as if we may have multiple
> binaries, differentiated by buildids, that would have different SDTs.
>
> The code seems to be trying to reduce the amount of info (not showing
> the buildid if there are no more at that point multiple versions of a
> DSO with SDTs in place).
>
> Further analysis of the changesets that put all this in place is needed
> to clarify, but looking just at fixing what the compiler is complaining,
> do you think the patches are bad?
I didn't see a patch to fix the first one.
But can you just change the structure so that 's' is 'char *'?
David
>
> - Arnaldo
>
> > The while thing needs more work :-(
> >
> > David
> >
> > >
> > > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> > > ---
> > > tools/perf/util/print-events.c | 13 +++++--------
> > > 1 file changed, 5 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
> > > index 8f3ed83853a9e468..898cf426509790cd 100644
> > > --- a/tools/perf/util/print-events.c
> > > +++ b/tools/perf/util/print-events.c
> > > @@ -97,14 +97,11 @@ void print_sdt_events(const struct print_callbacks *print_cb, void *print_state)
> > > } else {
> > > next_sdt_name = strlist__next(sdt_name);
> > > if (next_sdt_name) {
> > > - char *bid2 = strchr(next_sdt_name->s, '@');
> > > -
> > > - if (bid2)
> > > - *bid2 = '\0';
> > > - if (strcmp(sdt_name->s, next_sdt_name->s) == 0)
> > > - show_detail = true;
> > > - if (bid2)
> > > - *bid2 = '@';
> > > + const char *bid2 = strchr(next_sdt_name->s, '@');
> > > +
> > > + show_detail = bid2 ?
> > > + strncmp(sdt_name->s, next_sdt_name->s, bid2 - next_sdt_name->s) == 0 :
> > > + strcmp(sdt_name->s, next_sdt_name->s) == 0;
> > > }
> > > }
> > > last_sdt_name = sdt_name->s;
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2026-01-22 9:56 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-20 22:08 [PATCH 0/4] Fixes for gcc 16.0.1 Arnaldo Carvalho de Melo
2026-01-20 22:08 ` [PATCH 1/4] perf tests sw-clock: Mark the volatile tmp variable as __maybe_unused Arnaldo Carvalho de Melo
2026-01-20 22:08 ` [PATCH 2/4] perf trace: Deal with compiler const checks Arnaldo Carvalho de Melo
2026-01-20 22:08 ` [PATCH 3/4] perf list: Don't write to const memory Arnaldo Carvalho de Melo
2026-01-21 11:25 ` David Laight
2026-01-21 18:40 ` Arnaldo Carvalho de Melo
2026-01-21 18:44 ` Ian Rogers
2026-01-21 22:17 ` David Laight
2026-01-22 1:10 ` Arnaldo Carvalho de Melo
2026-01-22 9:55 ` David Laight
2026-01-20 22:09 ` [PATCH 4/4] perf list: Signal changing const memory is ok Arnaldo Carvalho de Melo
2026-01-20 23:42 ` [PATCH 0/4] Fixes for gcc 16.0.1 Ian Rogers
2026-01-20 23:50 ` Arnaldo Carvalho de Melo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox