[PATCH 2/3] perf riscv: Fix discarded const qualifier error in _get_field()

Li Guan guanli.oerv at isrc.iscas.ac.cn
Wed May 13 08:48:50 PDT 2026


When building perf for the RISC-V architecture (e.g., with GCC 14), the
build fails due to strict type checking on pointer assignments. The
compiler flags the return value of strrchr() being assigned to a
non-const pointer while processing a const string, triggering
-Werror=discarded-qualifiers:

    arch/riscv/util/header.c:24:15: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
       24 |          line2 = strrchr(line, ' ');
          |                ^
    arch/riscv/util/header.c:29:12: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
       29 |          nl = strrchr(line, '\n');
          |             ^

Resolve this by adding an explicit (char *) cast to the strrchr()
return values, which satisfies the compiler's qualifier checks
without altering the runtime behavior.

Signed-off-by: Li Guan <guanli.oerv at isrc.iscas.ac.cn>
---
 tools/perf/arch/riscv/util/header.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/arch/riscv/util/header.c b/tools/perf/arch/riscv/util/header.c
index 4b839203d4..d01ba64aec 100644
--- a/tools/perf/arch/riscv/util/header.c
+++ b/tools/perf/arch/riscv/util/header.c
@@ -21,12 +21,12 @@ static char *_get_field(const char *line)
 {
 	char *line2, *nl;
 
-	line2 = strrchr(line, ' ');
+	line2 = (char *)strrchr(line, ' ');
 	if (!line2)
 		return NULL;
 
 	line2++;
-	nl = strrchr(line, '\n');
+	nl = (char *)strrchr(line, '\n');
 	if (!nl)
 		return NULL;
 
-- 
2.54.0




More information about the linux-riscv mailing list