Commit 834fcd29 authored by Thomas Gleixner's avatar Thomas Gleixner

perf/x86/intel/cstate: Prevent hotplug callback leak

If the pmu registration fails the registered hotplug callbacks are not
removed. Wrong in any case, but fatal in case of a modular driver.

Replace the nonsensical state names with proper ones while at it.

Fixes: 77c34ef1 ("perf/x86/intel/cstate: Convert Intel CSTATE to hotplug state machine")
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Cc: Sebastian Siewior <bigeasy@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: stable@vger.kernel.org
parent a051f220
...@@ -594,6 +594,9 @@ static int __init cstate_probe(const struct cstate_model *cm) ...@@ -594,6 +594,9 @@ static int __init cstate_probe(const struct cstate_model *cm)
static inline void cstate_cleanup(void) static inline void cstate_cleanup(void)
{ {
cpuhp_remove_state_nocalls(CPUHP_AP_PERF_X86_CSTATE_ONLINE);
cpuhp_remove_state_nocalls(CPUHP_AP_PERF_X86_CSTATE_STARTING);
if (has_cstate_core) if (has_cstate_core)
perf_pmu_unregister(&cstate_core_pmu); perf_pmu_unregister(&cstate_core_pmu);
...@@ -606,16 +609,16 @@ static int __init cstate_init(void) ...@@ -606,16 +609,16 @@ static int __init cstate_init(void)
int err; int err;
cpuhp_setup_state(CPUHP_AP_PERF_X86_CSTATE_STARTING, cpuhp_setup_state(CPUHP_AP_PERF_X86_CSTATE_STARTING,
"AP_PERF_X86_CSTATE_STARTING", cstate_cpu_init, "perf/x86/cstate:starting", cstate_cpu_init, NULL);
NULL);
cpuhp_setup_state(CPUHP_AP_PERF_X86_CSTATE_ONLINE, cpuhp_setup_state(CPUHP_AP_PERF_X86_CSTATE_ONLINE,
"AP_PERF_X86_CSTATE_ONLINE", NULL, cstate_cpu_exit); "perf/x86/cstate:online", NULL, cstate_cpu_exit);
if (has_cstate_core) { if (has_cstate_core) {
err = perf_pmu_register(&cstate_core_pmu, cstate_core_pmu.name, -1); err = perf_pmu_register(&cstate_core_pmu, cstate_core_pmu.name, -1);
if (err) { if (err) {
has_cstate_core = false; has_cstate_core = false;
pr_info("Failed to register cstate core pmu\n"); pr_info("Failed to register cstate core pmu\n");
cstate_cleanup();
return err; return err;
} }
} }
...@@ -629,8 +632,7 @@ static int __init cstate_init(void) ...@@ -629,8 +632,7 @@ static int __init cstate_init(void)
return err; return err;
} }
} }
return 0;
return err;
} }
static int __init cstate_pmu_init(void) static int __init cstate_pmu_init(void)
...@@ -655,8 +657,6 @@ module_init(cstate_pmu_init); ...@@ -655,8 +657,6 @@ module_init(cstate_pmu_init);
static void __exit cstate_pmu_exit(void) static void __exit cstate_pmu_exit(void)
{ {
cpuhp_remove_state_nocalls(CPUHP_AP_PERF_X86_CSTATE_ONLINE);
cpuhp_remove_state_nocalls(CPUHP_AP_PERF_X86_CSTATE_STARTING);
cstate_cleanup(); cstate_cleanup();
} }
module_exit(cstate_pmu_exit); module_exit(cstate_pmu_exit);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment