[PATCH v1 09/12] perf cs-etm: Fall back to the recorded instruction size on a failed read

From: Arnaldo Carvalho de Melo

Date: Fri Nov 13 2026 - 10:15:48 EST


From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>

cs_etm__t32_instr_size() reads the instruction bytes from the traced
program's memory to tell a 16-bit from a 32-bit T32 instruction, but it
ignores cs_etm__frontend_mem_access() failing, which happens when the
DSO or its debug data is missing, and then reads the uninitialized
buffer. GCC 16 warns about it and build-test fails with -Werror.

Use the instruction size recorded by the decoder, as the A32/A64 path
already does, when the read doesn't return the full two bytes.

Fixes: a7ee4d625ede4f62 ("perf cs-etm: Support for ARM A32/T32 instruction sets in CoreSight trace")
Cc: James Clark <james.clark@xxxxxxxxxx>
Cc: Leo Yan <leo.yan@xxxxxxx>
Cc: Mike Leach <mike.leach@xxxxxxx>
Cc: Robert Walker <robert.walker@xxxxxxx>
Cc: Suzuki K Poulose <suzuki.poulose@xxxxxxx>
Cc: coresight@xxxxxxxxxxxxxxxx
Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/util/cs-etm.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 3e01b401ca6f3a08..5d53ed74ae8835a9 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -1370,9 +1370,12 @@ static inline int cs_etm__t32_instr_size(struct cs_etm_queue *etmq,
struct cs_etm_packet *packet, u64 addr)
{
u8 instrBytes[2];
+ u32 len;

- cs_etm__frontend_mem_access(etmq, tidq, packet, addr,
- ARRAY_SIZE(instrBytes), instrBytes);
+ len = cs_etm__frontend_mem_access(etmq, tidq, packet, addr,
+ ARRAY_SIZE(instrBytes), instrBytes);
+ if (len != ARRAY_SIZE(instrBytes))
+ return packet->last_instr_size;
/*
* T32 instruction size is indicated by bits[15:11] of the first
* 16-bit word of the instruction: 0b11101, 0b11110 and 0b11111
--
2.56.0