[PATCH 6/6][SRU Artful] perf pmu: Add check for valid cpuid in perf_pmu__find_map()

dann frazier dann.frazier at canonical.com
Wed Feb 7 00:07:44 UTC 2018


From: Ganapatrao Kulkarni <ganapatrao.kulkarni at cavium.com>

BugLink: https://bugs.launchpad.net/bugs/1747523

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 <ganapatrao.kulkarni at cavium.com>
Cc: Alexander Shishkin <alexander.shishkin at linux.intel.com>
Cc: Catalin Marinas <catalin.marinas at arm.com>
Cc: Ganapatrao Kulkarni <gklkml16 at gmail.com>
Cc: Jayachandran C <jnair at caviumnetworks.com>
Cc: Jonathan Cameron <jonathan.cameron at huawei.com>
Cc: Mark Rutland <mark.rutland at arm.com>
Cc: Peter Zijlstra <peterz at infradead.org>
Cc: Robert Richter <robert.richter at cavium.com>
Cc: Shaokun Zhang <zhangshaokun at hisilicon.com>
Cc: Will Deacon <will.deacon at arm.com>
Cc: linux-arm-kernel at lists.infradead.org
Link: http://lkml.kernel.org/r/20171016183222.25750-6-ganapatrao.kulkarni@cavium.com
Signed-off-by: Arnaldo Carvalho de Melo <acme at redhat.com>
(cherry picked from commit de3d0f12be476271d03f1ddb5a7c241c2f07f126)
Signed-off-by: dann frazier <dann.frazier at canonical.com>
---
 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 3fb59dbf68ef..e0cb981c391d 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -594,6 +594,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.16.1





More information about the kernel-team mailing list