Re: [PATCH 1/3] perf cs-etm: Initialize the Thumb instruction buffer
From: Ian Rogers
Date: Fri Nov 13 2026 - 13:47:38 EST
On Fri, Nov 13, 2026 at 2:55 AM Leo Yan <leo.yan@xxxxxxx> wrote:
>
> cs_etm__frontend_mem_access() can return zero or a short read without
> fully initializing instrBytes. cs_etm__t32_instr_size() nevertheless
> inspects its second byte. With CORESIGHT=1 and -O3, GCC 15.2.0 reports:
>
> error: 'instrBytes' may be used uninitialized
>
> Zero-initialize the buffer to avoid reading uninitialized stack data
> when instruction memory is unavailable and fix the build failure.
>
> Reported-by: Ian Rogers <irogers@xxxxxxxxxx>
> Closes: https://lore.kernel.org/linux-perf-users/20261030-perf_cs_etm_fix_non_taken-v3-0-7629b52ab047@xxxxxxx/T/#m64fb81c665214b79883d9be815b40ac5f6669628
> Fixes: a7ee4d625ede ("perf cs-etm: Support for ARM A32/T32 instruction sets in CoreSight trace")
> Signed-off-by: Leo Yan <leo.yan@xxxxxxx>
Reviewed-by: Ian Rogers <irogers@xxxxxxxxxx>
Thanks!
Ian
> ---
> tools/perf/util/cs-etm.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
> index 3e01b401ca6f3a08f44bb69204317efaf2fa18d0..25f12bd110934a204d79244f45317085b7a81666 100644
> --- a/tools/perf/util/cs-etm.c
> +++ b/tools/perf/util/cs-etm.c
> @@ -1369,7 +1369,7 @@ static inline int cs_etm__t32_instr_size(struct cs_etm_queue *etmq,
> struct cs_etm_traceid_queue *tidq,
> struct cs_etm_packet *packet, u64 addr)
> {
> - u8 instrBytes[2];
> + u8 instrBytes[2] = { 0 };
>
> cs_etm__frontend_mem_access(etmq, tidq, packet, addr,
> ARRAY_SIZE(instrBytes), instrBytes);
>
> --
> 2.34.1
>