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

From: Li Guan

Date: Wed May 13 2026 - 12:12:11 EST


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@xxxxxxxxxxxxxxxx>
---
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