Re: [PATCH v2 2/6] perf arm_spe: Handle missing CPU IDs
From: Leo Yan
Date: Tue Apr 07 2026 - 11:31:56 EST
On Tue, Apr 07, 2026 at 03:05:16PM +0100, James Clark wrote:
> Don't call strtol() with a null pointer to avoid undefined behavior.
>
> I'm not sure of the exact scenario for missing CPU IDs but I don't think
> it happens in practice. SPE decoding can continue without them with
> reduced functionality, but print an error message anyway.
>
> Signed-off-by: James Clark <james.clark@xxxxxxxxxx>
Reviewed-by: Leo Yan <leo.yan@xxxxxxx>
> ---
> tools/perf/util/arm-spe.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
> index 7447b000f9cd..fc11f32e4911 100644
> --- a/tools/perf/util/arm-spe.c
> +++ b/tools/perf/util/arm-spe.c
> @@ -968,16 +968,23 @@ static int arm_spe__get_midr(struct arm_spe *spe, int cpu, u64 *midr)
>
> pr_warning_once("Old SPE metadata, re-record to improve decode accuracy\n");
> cpuid = perf_env__cpuid(perf_session__env(spe->session));
> + if (!cpuid)
> + goto err;
> +
> *midr = strtol(cpuid, NULL, 16);
> return 0;
> }
>
> metadata = arm_spe__get_metadata_by_cpu(spe, cpu);
> if (!metadata)
> - return -EINVAL;
> + goto err;
>
> *midr = metadata[ARM_SPE_CPU_MIDR];
> return 0;
> +
> +err:
> + pr_err("Failed to get MIDR for CPU %d\n", cpu);
> + return -EINVAL;
> }
>
> static void arm_spe__synth_ds(struct arm_spe_queue *speq,
>
> --
> 2.34.1
>
>