diff options
author | Thomas Gleixner <[email protected]> | 2016-02-22 22:19:21 +0000 |
---|---|---|
committer | Ingo Molnar <[email protected]> | 2016-02-29 09:35:22 +0100 |
commit | 55f2890f0726fe4a1f41a3a0e72ca1a263f095c3 (patch) | |
tree | 936e8d322037b448031783013352124a9a32e143 | |
parent | 4d120c535d638a952e644817ba3cbef30deedb2b (diff) |
perf/x86/intel/rapl: Add proper error handling
Like uncore the rapl driver lacks error handling. It leaks memory and leaves
the hotplug notifier registered.
Add the proper error checks, cleanup the memory and register the hotplug
notifier only on success.
Signed-off-by: Thomas Gleixner <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Harish Chegondi <[email protected]>
Cc: Jacob Pan <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Kan Liang <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Cc: Vince Weaver <[email protected]>
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
-rw-r--r-- | arch/x86/events/intel/rapl.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/arch/x86/events/intel/rapl.c b/arch/x86/events/intel/rapl.c index 536f0cebba8f..98b04d202760 100644 --- a/arch/x86/events/intel/rapl.c +++ b/arch/x86/events/intel/rapl.c @@ -686,6 +686,14 @@ static int rapl_check_hw_unit(void) return 0; } +static void __init cleanup_rapl_pmus(void) +{ + int cpu; + + for_each_online_cpu(cpu) + kfree(per_cpu(rapl_pmu, cpu)); +} + static const struct x86_cpu_id rapl_cpu_match[] = { [0] = { .vendor = X86_VENDOR_INTEL, .family = 6 }, [1] = {}, @@ -702,7 +710,7 @@ static int __init rapl_pmu_init(void) * check for Intel processor family 6 */ if (!x86_match_cpu(rapl_cpu_match)) - return 0; + return -ENODEV; /* check supported CPU */ switch (boot_cpu_data.x86_model) { @@ -734,8 +742,9 @@ static int __init rapl_pmu_init(void) break; default: /* unsupported */ - return 0; + return -ENODEV; } + ret = rapl_check_hw_unit(); if (ret) return ret; @@ -743,6 +752,7 @@ static int __init rapl_pmu_init(void) /* run cpu model quirks */ for (quirk = rapl_quirks; quirk; quirk = quirk->next) quirk->func(); + cpu_notifier_register_begin(); for_each_online_cpu(cpu) { @@ -752,15 +762,14 @@ static int __init rapl_pmu_init(void) rapl_cpu_init(cpu); } - __perf_cpu_notifier(rapl_cpu_notifier); - ret = perf_pmu_register(&rapl_pmu_class, "power", -1); if (WARN_ON(ret)) { pr_info("RAPL PMU detected, registration failed (%d), RAPL PMU disabled\n", ret); - cpu_notifier_register_done(); - return -1; + goto out; } + __perf_cpu_notifier(rapl_cpu_notifier); + pmu = __this_cpu_read(rapl_pmu); pr_info("RAPL PMU detected," @@ -775,9 +784,13 @@ static int __init rapl_pmu_init(void) rapl_domain_names[i], rapl_hw_unit[i]); } } -out: - cpu_notifier_register_done(); + cpu_notifier_register_done(); return 0; + +out: + cleanup_rapl_pmus(); + cpu_notifier_register_done(); + return ret; } device_initcall(rapl_pmu_init); |