linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH perf-next 0/4] glibc str functions const return fixes
@ 2025-12-11 22:17 Arnaldo Carvalho de Melo
  2025-12-11 22:17 ` [PATCH 1/4] perf list: Remove unused 'sep' variable Arnaldo Carvalho de Melo
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Arnaldo Carvalho de Melo @ 2025-12-11 22:17 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

Hi,

	While building with Fedora 44 I noticed so interesting warnings
about touching const memory, fix some of them in this series,

- Arnaldo

Arnaldo Carvalho de Melo (4):
  perf list: Remove unused 'sep' variable
  perf diff: Constify strchr() return variables
  perf tools: Use const for variables receiving str{str,r?chr}() returns
  perf trace: Don't change const char strings

 tools/perf/builtin-diff.c       | 12 +++++-------
 tools/perf/builtin-list.c       |  4 ++--
 tools/perf/builtin-trace.c      | 11 +++++++----
 tools/perf/jvmti/libjvmti.c     |  2 +-
 tools/perf/tests/parse-events.c |  4 ++--
 tools/perf/util/evlist.c        |  3 ++-
 6 files changed, 19 insertions(+), 17 deletions(-)

-- 
2.52.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] perf list: Remove unused 'sep' variable
  2025-12-11 22:17 [PATCH perf-next 0/4] glibc str functions const return fixes Arnaldo Carvalho de Melo
@ 2025-12-11 22:17 ` Arnaldo Carvalho de Melo
  2025-12-11 22:17 ` [PATCH 2/4] perf diff: Constify strchr() return variables Arnaldo Carvalho de Melo
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Arnaldo Carvalho de Melo @ 2025-12-11 22:17 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,
	Arnaldo Carvalho de Melo

It is just being set to the return of strchr() but never used, just
ditch it and with it get rid of a warning about it not being const on
fedora 44.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-list.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index 5cbca0bacd35237e..ac7bd0e41aa1d5d6 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -648,7 +648,7 @@ int cmd_list(int argc, const char **argv)
 	}
 
 	for (i = 0; i < argc; ++i) {
-		char *sep, *s;
+		char *s;
 
 		if (strcmp(argv[i], "tracepoint") == 0) {
 			char *old_pmu_glob = default_ps.pmu_glob;
@@ -720,7 +720,7 @@ int cmd_list(int argc, const char **argv)
 		else if (strcmp(argv[i], "pfm") == 0)
 			print_libpfm_events(&print_cb, ps);
 #endif
-		else if ((sep = strchr(argv[i], ':')) != NULL) {
+		else if (strchr(argv[i], ':') != NULL) {
 			char *old_pmu_glob = ps->pmu_glob;
 			char *old_event_glob = ps->event_glob;
 
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] perf diff: Constify strchr() return variables
  2025-12-11 22:17 [PATCH perf-next 0/4] glibc str functions const return fixes Arnaldo Carvalho de Melo
  2025-12-11 22:17 ` [PATCH 1/4] perf list: Remove unused 'sep' variable Arnaldo Carvalho de Melo
@ 2025-12-11 22:17 ` Arnaldo Carvalho de Melo
  2025-12-11 22:17 ` [PATCH 3/4] perf tools: Use const for variables receiving str{str,r?chr}() returns Arnaldo Carvalho de Melo
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Arnaldo Carvalho de Melo @ 2025-12-11 22:17 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,
	Arnaldo Carvalho de Melo

Newer glibc versions return const char for strchr() when the 's' arg is
const, change the return variable to const to match that.

Also we don't need to turn that ',' into a '\0', as strtol will stop in
the first invalid char. No need to touch read only memory.

First noticed with fedora 44.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-diff.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 53d5ea4a6a4f7b54..59bf1f72d12e226a 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -178,10 +178,9 @@ static struct header_column {
 	}
 };
 
-static int setup_compute_opt_wdiff(char *opt)
+static int setup_compute_opt_wdiff(const char *opt)
 {
-	char *w1_str = opt;
-	char *w2_str;
+	const char *w1_str = opt, *w2_str;
 
 	int ret = -EINVAL;
 
@@ -192,8 +191,7 @@ static int setup_compute_opt_wdiff(char *opt)
 	if (!w2_str)
 		goto out;
 
-	*w2_str++ = 0x0;
-	if (!*w2_str)
+	if (!*++w2_str)
 		goto out;
 
 	compute_wdiff_w1 = strtol(w1_str, NULL, 10);
@@ -214,7 +212,7 @@ static int setup_compute_opt_wdiff(char *opt)
 	return ret;
 }
 
-static int setup_compute_opt(char *opt)
+static int setup_compute_opt(const char *opt)
 {
 	if (compute == COMPUTE_WEIGHTED_DIFF)
 		return setup_compute_opt_wdiff(opt);
@@ -234,7 +232,7 @@ static int setup_compute(const struct option *opt, const char *str,
 	char *cstr = (char *) str;
 	char buf[50];
 	unsigned i;
-	char *option;
+	const char *option;
 
 	if (!str) {
 		*cp = COMPUTE_DELTA;
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] perf tools: Use const for variables receiving str{str,r?chr}() returns
  2025-12-11 22:17 [PATCH perf-next 0/4] glibc str functions const return fixes Arnaldo Carvalho de Melo
  2025-12-11 22:17 ` [PATCH 1/4] perf list: Remove unused 'sep' variable Arnaldo Carvalho de Melo
  2025-12-11 22:17 ` [PATCH 2/4] perf diff: Constify strchr() return variables Arnaldo Carvalho de Melo
@ 2025-12-11 22:17 ` Arnaldo Carvalho de Melo
  2025-12-11 22:17 ` [PATCH 4/4] perf trace: Don't change const char strings Arnaldo Carvalho de Melo
  2025-12-12  5:23 ` [PATCH perf-next 0/4] glibc str functions const return fixes Ian Rogers
  4 siblings, 0 replies; 6+ messages in thread
From: Arnaldo Carvalho de Melo @ 2025-12-11 22:17 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,
	Arnaldo Carvalho de Melo

Newer glibc versions return const char for str{str,chr}() where the
haystack/s is const so to avoid warnings like these on fedora 44 change
some variables to const:

  36     8.17 fedora:44                     : FAIL gcc version 15.2.1 20251111 (Red Hat 15.2.1-4) (GCC)
    libbpf.c: In function 'kallsyms_cb':
    libbpf.c:8489:13: error: assignment discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
     8489 |         res = strstr(sym_name, ".llvm.");

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/jvmti/libjvmti.c     | 2 +-
 tools/perf/tests/parse-events.c | 4 ++--
 tools/perf/util/evlist.c        | 3 ++-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/perf/jvmti/libjvmti.c b/tools/perf/jvmti/libjvmti.c
index 82514e6532b8c3af..87bfd4781003a331 100644
--- a/tools/perf/jvmti/libjvmti.c
+++ b/tools/perf/jvmti/libjvmti.c
@@ -142,7 +142,7 @@ copy_class_filename(const char * class_sign, const char * file_name, char * resu
 	*/
 	if (*class_sign == 'L') {
 		size_t j, i = 0;
-		char *p = strrchr(class_sign, '/');
+		const char *p = strrchr(class_sign, '/');
 		if (p) {
 			/* drop the 'L' prefix and copy up to the final '/' */
 			for (i = 0; i < (size_t)(p - class_sign); i++)
diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index 128d21dc389f869b..2bd6229721145e42 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -2609,8 +2609,8 @@ static int test_events(const struct evlist_test *events, int cnt)
 	for (int i = 0; i < cnt; i++) {
 		struct evlist_test e = events[i];
 		int test_ret;
-		const char *pos = e.name;
-		char buf[1024], *buf_pos = buf, *end;
+		const char *pos = e.name, *end;
+		char buf[1024], *buf_pos = buf;
 
 		while ((end = strstr(pos, "default_core"))) {
 			size_t len = end - pos;
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 03674d2cbd015e4f..64951962854104a5 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1945,7 +1945,8 @@ static int evlist__parse_control_fifo(const char *str, int *ctl_fd, int *ctl_fd_
 
 int evlist__parse_control(const char *str, int *ctl_fd, int *ctl_fd_ack, bool *ctl_fd_close)
 {
-	char *comma = NULL, *endptr = NULL;
+	const char *comma = NULL;
+	char *endptr = NULL;
 
 	*ctl_fd_close = false;
 
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] perf trace: Don't change const char strings
  2025-12-11 22:17 [PATCH perf-next 0/4] glibc str functions const return fixes Arnaldo Carvalho de Melo
                   ` (2 preceding siblings ...)
  2025-12-11 22:17 ` [PATCH 3/4] perf tools: Use const for variables receiving str{str,r?chr}() returns Arnaldo Carvalho de Melo
@ 2025-12-11 22:17 ` Arnaldo Carvalho de Melo
  2025-12-12  5:23 ` [PATCH perf-next 0/4] glibc str functions const return fixes Ian Rogers
  4 siblings, 0 replies; 6+ messages in thread
From: Arnaldo Carvalho de Melo @ 2025-12-11 22:17 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,
	Arnaldo Carvalho de Melo

We got away with this so far but now with fedora 44 complaining about
the return value of strchr et all, lets use strdup for good measure.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-trace.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index baee1f6956001d86..d49c1ae409d77df1 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -5173,8 +5173,8 @@ static int trace__parse_events_option(const struct option *opt, const char *str,
 				      int unset __maybe_unused)
 {
 	struct trace *trace = (struct trace *)opt->value;
-	const char *s = str;
-	char *sep = NULL, *lists[2] = { NULL, NULL, };
+	const char *s;
+	char *strd, *sep = NULL, *lists[2] = { NULL, NULL, };
 	int len = strlen(str) + 1, err = -1, list, idx;
 	char *strace_groups_dir = system_path(STRACE_GROUPS_DIR);
 	char group_name[PATH_MAX];
@@ -5183,6 +5183,10 @@ static int trace__parse_events_option(const struct option *opt, const char *str,
 	if (strace_groups_dir == NULL)
 		return -1;
 
+	s = strd = strdup(str);
+	if (strd == NULL)
+		return -1;
+
 	if (*s == '!') {
 		++s;
 		trace->not_ev_qualifier = true;
@@ -5257,8 +5261,7 @@ static int trace__parse_events_option(const struct option *opt, const char *str,
 	free(strace_groups_dir);
 	free(lists[0]);
 	free(lists[1]);
-	if (sep)
-		*sep = ',';
+	free(strd);
 
 	return err;
 }
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH perf-next 0/4] glibc str functions const return fixes
  2025-12-11 22:17 [PATCH perf-next 0/4] glibc str functions const return fixes Arnaldo Carvalho de Melo
                   ` (3 preceding siblings ...)
  2025-12-11 22:17 ` [PATCH 4/4] perf trace: Don't change const char strings Arnaldo Carvalho de Melo
@ 2025-12-12  5:23 ` Ian Rogers
  4 siblings, 0 replies; 6+ messages in thread
From: Ian Rogers @ 2025-12-12  5:23 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

On Thu, Dec 11, 2025 at 2:18 PM Arnaldo Carvalho de Melo
<acme@kernel.org> wrote:
>
> Hi,
>
>         While building with Fedora 44 I noticed so interesting warnings
> about touching const memory, fix some of them in this series,
>
> - Arnaldo

For the series:

Reviewed-by: Ian Rogers <irogers@google.com>

Thanks,
Ian

>
> Arnaldo Carvalho de Melo (4):
>   perf list: Remove unused 'sep' variable
>   perf diff: Constify strchr() return variables
>   perf tools: Use const for variables receiving str{str,r?chr}() returns
>   perf trace: Don't change const char strings
>
>  tools/perf/builtin-diff.c       | 12 +++++-------
>  tools/perf/builtin-list.c       |  4 ++--
>  tools/perf/builtin-trace.c      | 11 +++++++----
>  tools/perf/jvmti/libjvmti.c     |  2 +-
>  tools/perf/tests/parse-events.c |  4 ++--
>  tools/perf/util/evlist.c        |  3 ++-
>  6 files changed, 19 insertions(+), 17 deletions(-)
>
> --
> 2.52.0
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-12-12  5:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-11 22:17 [PATCH perf-next 0/4] glibc str functions const return fixes Arnaldo Carvalho de Melo
2025-12-11 22:17 ` [PATCH 1/4] perf list: Remove unused 'sep' variable Arnaldo Carvalho de Melo
2025-12-11 22:17 ` [PATCH 2/4] perf diff: Constify strchr() return variables Arnaldo Carvalho de Melo
2025-12-11 22:17 ` [PATCH 3/4] perf tools: Use const for variables receiving str{str,r?chr}() returns Arnaldo Carvalho de Melo
2025-12-11 22:17 ` [PATCH 4/4] perf trace: Don't change const char strings Arnaldo Carvalho de Melo
2025-12-12  5:23 ` [PATCH perf-next 0/4] glibc str functions const return fixes Ian Rogers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).