From: James Clark Date: Tue, 14 Apr 2026 12:48:00 +0000 (+0100) Subject: perf arm_spe: Handle missing CPU IDs X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0c7e4d11fb8d490c8f64ea98d05e441c9e26c6ee;p=thirdparty%2Flinux.git perf arm_spe: Handle missing CPU IDs 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. Reviewed-by: Leo Yan Signed-off-by: James Clark Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Ian Rogers Cc: Ingo Molnar Cc: Jiri Olsa Cc: John Garry Cc: Leo Yan Cc: Mark Rutland Cc: Mike Leach Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Will Deacon Cc: linux-arm-kernel@lists.infradead.org Signed-off-by: Arnaldo Carvalho de Melo --- diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c index 39046033e1433..037c7aa150c1e 100644 --- a/tools/perf/util/arm-spe.c +++ b/tools/perf/util/arm-spe.c @@ -982,16 +982,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_warning_once("Failed to get MIDR for CPU %d\n", cpu); + return -EINVAL; } static void arm_spe__synth_ds(struct arm_spe_queue *speq,