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

Pierre Gondois pierre.gondois at arm.com
Wed Sep 14 09:28:15 PDT 2022


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 at arm.com>
---
 drivers/powercap/dtpm_cpu.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

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);
 }
 
-- 
2.25.1




More information about the linux-arm-kernel mailing list