]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf tools: Use const for variables receiving str{str,r?chr}() returns
authorArnaldo Carvalho de Melo <acme@kernel.org>
Thu, 11 Dec 2025 22:17:55 +0000 (19:17 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 17 Dec 2025 12:30:37 +0000 (09:30 -0300)
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.");

Reviewed-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20251211221756.96294-4-acme@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/jvmti/libjvmti.c
tools/perf/tests/parse-events.c
tools/perf/util/evlist.c

index 82514e6532b8c3afdea1aa4fe961a589cd9c60c3..87bfd4781003a331781923d192da1f0875269abd 100644 (file)
@@ -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++)
index 128d21dc389f869bb142bcf0e13968a7830001bd..2bd6229721145e429096b3fc892228a8ff856b1c 100644 (file)
@@ -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;
index 03674d2cbd015e4f75cfe8d86300aa28f862396f..64951962854104a5e63f329a99a70ad4a7f7de7c 100644 (file)
@@ -1945,7 +1945,8 @@ out_free:
 
 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;