Subject: [PATCH 23/36] perf pmu: Add check for valid cpuid in perf_pmu__find_map()

From: [email-masked] (Arnaldo Carvalho de Melo)
Date: Wed, 6 Dec 2017 11:41:02 -0300

From: Ganapatrao Kulkarni <[email-masked]>

On some platforms(arm/arm64) which uses cpus map to get corresponding
cpuid string, cpuid can be NULL for PMUs other than CORE PMUs.  Adding
check for NULL cpuid in function perf_pmu__find_map to avoid
segmentation fault.

Signed-off-by: Ganapatrao Kulkarni <[email-masked]>
Cc: Alexander Shishkin <[email-masked]>
Cc: Catalin Marinas <[email-masked]>
Cc: Ganapatrao Kulkarni <[email-masked]>
Cc: Jayachandran C <[email-masked]>
Cc: Jonathan Cameron <[email-masked]>
Cc: Mark Rutland <[email-masked]>
Cc: Peter Zijlstra <[email-masked]>
Cc: Robert Richter <[email-masked]>
Cc: Shaokun Zhang <[email-masked]>
Cc: Will Deacon <[email-masked]>
Cc: linux-arm-kernel at lists.infradead.org
Link: http://lkml.kernel.org/r/20171016183222.25750-6-ganapatrao.kulkarni at cavium.com
Signed-off-by: Arnaldo Carvalho de Melo <[email-masked]>
---
 tools/perf/util/pmu.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 732ff579ec65..8b7c151579c0 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -601,6 +601,12 @@ struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu)
 	char *cpuid = perf_pmu__getcpuid(pmu);
 	int i;
 
+	/* on some platforms which uses cpus map, cpuid can be NULL for
+	 * PMUs other than CORE PMUs.
+	 */
+	if (!cpuid)
+		return NULL;
+
 	i = 0;
 	for (;;) {
 		map = &pmu_events_map[i++];
-- 
2.13.6