summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Mc Guire <hofrat@osadl.org>2018-11-28 12:24:47 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-02-12 19:47:03 +0100
commit68b4512ca6fcd474a8e144863f03410ed186232b (patch)
tree3d0e6fba9b94f4531134c39d7bcd835bf589d2ba
parentaf6db7e751ff0858be7ba6953140fbf4eb217a37 (diff)
downloadlinux-rpi3-68b4512ca6fcd474a8e144863f03410ed186232b.tar.gz
linux-rpi3-68b4512ca6fcd474a8e144863f03410ed186232b.tar.bz2
linux-rpi3-68b4512ca6fcd474a8e144863f03410ed186232b.zip
perf: arm_spe: handle devm_kasprintf() failure
[ Upstream commit 754a58db6a556e6e5f5e32f3e84e7d67b5bf9c8e ] devm_kasprintf() may return NULL on failure of internal allocation thus the assignment to 'name' is not safe if unchecked. If NULL is passed in for name then perf_pmu_register() would not fail but rather silently jump to skip_type which is not the intent here. As perf_pmu_register() may also return -ENOMEM returning -ENOMEM in the (unlikely) failure case of devm_kasprintf() should be fine here as well. Acked-by: Mark Rutland <mark.rutland@arm.com> Fixes: d5d9696b0380 ("drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension") Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org> [will: reworded error message] Signed-off-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--drivers/perf/arm_spe_pmu.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c
index 54ec278d2fc4..e1a77b2de78a 100644
--- a/drivers/perf/arm_spe_pmu.c
+++ b/drivers/perf/arm_spe_pmu.c
@@ -927,6 +927,11 @@ static int arm_spe_pmu_perf_init(struct arm_spe_pmu *spe_pmu)
idx = atomic_inc_return(&pmu_idx);
name = devm_kasprintf(dev, GFP_KERNEL, "%s_%d", PMUNAME, idx);
+ if (!name) {
+ dev_err(dev, "failed to allocate name for pmu %d\n", idx);
+ return -ENOMEM;
+ }
+
return perf_pmu_register(&spe_pmu->pmu, name, -1);
}