ARM: perf: handle armpmu_register failing
authorMark Rutland <Mark.Rutland@arm.com>
Fri, 18 Jan 2013 13:42:58 +0000 (13:42 +0000)
committerWill Deacon <will.deacon@arm.com>
Fri, 18 Jan 2013 13:46:09 +0000 (13:46 +0000)
Currently perf_pmu_register may fail for several reasons (e.g. being
unable to allocate memory for the struct device it associates with each
PMU), and while any error is propagated by armpmu_register, it is
ignored by cpu_pmu_device_probe and not propagated to the caller.  This
also results in a leak of a struct arm_pmu.

This patch adds cleanup if armpmu_register fails, and updates the info
messages to better differentiate this type of failure from a failure to
probe the PMU type from the hardware or dt.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
arch/arm/kernel/perf_event_cpu.c

index 43496f600569f1a83bfd62cdbc4c9c64d20cb856..1f2740e3dbc028c062c134d58ceb6344f2045d36 100644 (file)
@@ -277,17 +277,22 @@ static int cpu_pmu_device_probe(struct platform_device *pdev)
        }
 
        if (ret) {
-               pr_info("failed to register PMU devices!");
-               kfree(pmu);
-               return ret;
+               pr_info("failed to probe PMU!");
+               goto out_free;
        }
 
        cpu_pmu = pmu;
        cpu_pmu->plat_device = pdev;
        cpu_pmu_init(cpu_pmu);
-       armpmu_register(cpu_pmu, PERF_TYPE_RAW);
+       ret = armpmu_register(cpu_pmu, PERF_TYPE_RAW);
 
-       return 0;
+       if (!ret)
+               return 0;
+
+out_free:
+       pr_info("failed to register PMU devices!");
+       kfree(pmu);
+       return ret;
 }
 
 static struct platform_driver cpu_pmu_driver = {