[2/5] cpuidle: governor: Encapsulate the cpuidle on/off switch

Message ID 20201015144431.9979-2-daniel.lezcano@linaro.org
State New
Headers show
Series
  • [1/5] cpuidle: Remove pointless stub
Related show

Commit Message

Daniel Lezcano Oct. 15, 2020, 2:44 p.m.
The next patch will introduce the ability to unregister a governor
which will share part of the register function code. Instead of
duplicating, let's encapuslate the common parts into functions, so
they can be called from different places.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>

---
 drivers/cpuidle/governor.c | 39 ++++++++++++++++++++++++--------------
 1 file changed, 25 insertions(+), 14 deletions(-)

-- 
2.17.1

Patch

diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
index 29acaf48e575..d46ab8ec2dd7 100644
--- a/drivers/cpuidle/governor.c
+++ b/drivers/cpuidle/governor.c
@@ -39,6 +39,27 @@  struct cpuidle_governor *cpuidle_find_governor(const char *str)
 	return NULL;
 }
 
+static void cpuidle_switch_off(void)
+{
+	struct cpuidle_device *dev;
+
+	cpuidle_uninstall_idle_handler();
+
+	if (cpuidle_curr_governor) {
+		list_for_each_entry(dev, &cpuidle_detected_devices, device_list)
+			cpuidle_disable_device(dev);
+	}
+}
+
+static void cpuidle_switch_on(void)
+{
+	struct cpuidle_device *dev;
+
+	list_for_each_entry(dev, &cpuidle_detected_devices, device_list)
+		cpuidle_enable_device(dev);
+	cpuidle_install_idle_handler();
+}
+
 /**
  * cpuidle_switch_governor - changes the governor
  * @gov: the new target governor
@@ -46,29 +67,19 @@  struct cpuidle_governor *cpuidle_find_governor(const char *str)
  */
 int cpuidle_switch_governor(struct cpuidle_governor *gov)
 {
-	struct cpuidle_device *dev;
-
 	if (!gov)
 		return -EINVAL;
 
 	if (gov == cpuidle_curr_governor)
 		return 0;
 
-	cpuidle_uninstall_idle_handler();
-
-	if (cpuidle_curr_governor) {
-		list_for_each_entry(dev, &cpuidle_detected_devices, device_list)
-			cpuidle_disable_device(dev);
-	}
+	cpuidle_switch_off();
 
 	cpuidle_curr_governor = gov;
 
-	if (gov) {
-		list_for_each_entry(dev, &cpuidle_detected_devices, device_list)
-			cpuidle_enable_device(dev);
-		cpuidle_install_idle_handler();
-		printk(KERN_INFO "cpuidle: using governor %s\n", gov->name);
-	}
+	cpuidle_switch_on();
+
+	printk(KERN_INFO "cpuidle: using governor %s\n", gov->name);
 
 	return 0;
 }