diff mbox series

[2/2] powercap/drivers/dtpm: Save cpuhp dynamic state

Message ID 20220914162815.1954866-3-pierre.gondois@arm.com
State New
Headers show
Series Save cpuhp dynamic state | expand

Commit Message

Pierre Gondois Sept. 14, 2022, 4:28 p.m. UTC
Requesting a CPUHP_AP_ONLINE_DYN cpuhp state reserves a state
among the range [CPUHP_AP_ONLINE_DYN:CPUHP_AP_ONLINE_DYN_END].
The reserved state must be saved in order to remove it later.

Cf. __cpuhp_setup_state_cpuslocked() documentation:
Return:
  On success:
    Positive state number if @state is CPUHP_AP_ONLINE_DYN;
    0 for all other states

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
---
 drivers/powercap/dtpm_cpu.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/powercap/dtpm_cpu.c b/drivers/powercap/dtpm_cpu.c
index f5eced0842b3..1dfbfe54d3bf 100644
--- a/drivers/powercap/dtpm_cpu.c
+++ b/drivers/powercap/dtpm_cpu.c
@@ -33,6 +33,7 @@  struct dtpm_cpu {
 };
 
 static DEFINE_PER_CPU(struct dtpm_cpu *, dtpm_per_cpu);
+static int cpuhp_dtpm_cpu_online_state;
 
 static struct dtpm_cpu *to_dtpm_cpu(struct dtpm *dtpm)
 {
@@ -296,12 +297,16 @@  static int dtpm_cpu_init(void)
 	if (ret < 0)
 		return ret;
 
+	cpuhp_dtpm_cpu_online_state = ret;
 	return 0;
 }
 
 static void dtpm_cpu_exit(void)
 {
-	cpuhp_remove_state_nocalls(CPUHP_AP_ONLINE_DYN);
+	if (cpuhp_dtpm_cpu_online_state > 0) {
+		cpuhp_remove_state_nocalls(cpuhp_dtpm_cpu_online_state);
+		cpuhp_dtpm_cpu_online_state = 0;
+	}
 	cpuhp_remove_state_nocalls(CPUHP_AP_DTPM_CPU_DEAD);
 }