From: Arnaldo Carvalho de Melo acme@redhat.com
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@linaro.org Cc: Leo Yan leo.yan@arm.com Cc: Mike Leach mike.leach@arm.com Cc: Robert Walker robert.walker@arm.com Cc: Suzuki K Poulose suzuki.poulose@arm.com Cc: coresight@lists.linaro.org Cc: linux-arm-kernel@lists.infradead.org Signed-off-by: Arnaldo Carvalho de Melo acme@redhat.com --- 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