]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf arm_spe: Handle missing CPU IDs
authorJames Clark <james.clark@linaro.org>
Tue, 14 Apr 2026 12:48:00 +0000 (13:48 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 6 May 2026 01:03:05 +0000 (22:03 -0300)
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 <leo.yan@arm.com>
Signed-off-by: James Clark <james.clark@linaro.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Leo Yan <leo.yan@linux.dev>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/arm-spe.c

index 39046033e1433cff82ef0668074867aba4a462a4..037c7aa150c1efeda6e8e956a5b1db733e6ea74a 100644 (file)
@@ -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,