]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf riscv: Fix discarded const qualifier in _get_field()
authorLi Guan <guanli.oerv@isrc.iscas.ac.cn>
Wed, 13 May 2026 18:07:21 +0000 (02:07 +0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Sat, 23 May 2026 22:45:39 +0000 (19:45 -0300)
The assignment of strrchr() return values to non-const char * variables
triggers a -Werror=discarded-qualifiers warning when building with GCC
14.

This happens because in newer glibc versions, strrchr() returns a 'const
char *' if the input string is const.

Properly declare 'line2' and 'nl' as const char * to match the glibc
function signature and ensure type safety. This avoids the need for
explicit type casting and aligns with the design pattern of not
modifying read-only memory in the perf tool.

Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Li Guan <guanli.oerv@isrc.iscas.ac.cn>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Paul Walmsley <pjw@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/arch/riscv/util/header.c

index 4b839203d4a54d78fbdc56474c95d21388c127cf..891984e909bd8f9e3f76c3a44ded2068c38e2603 100644 (file)
@@ -19,7 +19,7 @@
 
 static char *_get_field(const char *line)
 {
-       char *line2, *nl;
+       const char *line2, *nl;
 
        line2 = strrchr(line, ' ');
        if (!line2)