linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] thermal/core: Encapsulate the set_cur_state function
@ 2022-06-01 15:14 Daniel Lezcano
  2022-06-01 15:14 ` [PATCH 2/3] thermal/debugfs: Add debugfs information Daniel Lezcano
  2022-06-01 15:14 ` [PATCH 3/3] thermal/sysfs: Remove cooling device sysfs statistics Daniel Lezcano
  0 siblings, 2 replies; 13+ messages in thread
From: Daniel Lezcano @ 2022-06-01 15:14 UTC (permalink / raw)
  To: daniel.lezcano, rafael
  Cc: linux-pm, linux-kernel, quic_manafm, Amit Kucheria, Zhang Rui

Concentrate the actions in a single place when a cooling device state
is changed. Provide a function to do that instead of calling the
underlying ops.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 drivers/thermal/thermal_core.h    |  1 +
 drivers/thermal/thermal_helpers.c | 32 ++++++++++++++++++++++++-------
 drivers/thermal/thermal_sysfs.c   |  7 ++-----
 3 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h
index 726e327b4205..4689f6cf898f 100644
--- a/drivers/thermal/thermal_core.h
+++ b/drivers/thermal/thermal_core.h
@@ -65,6 +65,7 @@ static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev)
 		cdev->ops->power2state;
 }
 
+int thermal_cdev_set_state(struct thermal_cooling_device *cdev, int state);
 void thermal_cdev_update(struct thermal_cooling_device *);
 void __thermal_cdev_update(struct thermal_cooling_device *cdev);
 
diff --git a/drivers/thermal/thermal_helpers.c b/drivers/thermal/thermal_helpers.c
index 3edd047e144f..d5f162fad1ab 100644
--- a/drivers/thermal/thermal_helpers.c
+++ b/drivers/thermal/thermal_helpers.c
@@ -182,14 +182,32 @@ void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms)
 		*delay_jiffies = round_jiffies(*delay_jiffies);
 }
 
-static void thermal_cdev_set_cur_state(struct thermal_cooling_device *cdev,
-				       int target)
+/**
+ * thermal_cdev_set_state - set the cooling device state
+ * @cdev: a pointer to a thermal_cooling_device
+ * @state: the target state
+ *
+ * Set the state of the cooling device passed as parameter. The
+ * cooling device lock must be held when calling this function.
+ *
+ * Return: 0 in case of success, otherwise the return value is the one
+ * returned by the backend for the ops
+ */
+int thermal_cdev_set_state(struct thermal_cooling_device *cdev, int state)
 {
-	if (cdev->ops->set_cur_state(cdev, target))
-		return;
+	int ret;
 
-	thermal_notify_cdev_state_update(cdev->id, target);
-	thermal_cooling_device_stats_update(cdev, target);
+	/*
+	 * No check is needed for the ops->set_cur_state as the
+	 * registering function checked the ops are correctly set
+	 */
+	ret = cdev->ops->set_cur_state(cdev, state);
+	if (!ret) {
+		thermal_notify_cdev_state_update(cdev->id, state);
+		thermal_cooling_device_stats_update(cdev, state);
+	}
+
+	return ret;
 }
 
 void __thermal_cdev_update(struct thermal_cooling_device *cdev)
@@ -207,7 +225,7 @@ void __thermal_cdev_update(struct thermal_cooling_device *cdev)
 			target = instance->target;
 	}
 
-	thermal_cdev_set_cur_state(cdev, target);
+	thermal_cdev_set_state(cdev, target);
 
 	trace_cdev_update(cdev, target);
 	dev_dbg(&cdev->device, "set to state %lu\n", target);
diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
index 1c4aac8464a7..935e79909121 100644
--- a/drivers/thermal/thermal_sysfs.c
+++ b/drivers/thermal/thermal_sysfs.c
@@ -617,12 +617,9 @@ cur_state_store(struct device *dev, struct device_attribute *attr,
 		return -EINVAL;
 
 	mutex_lock(&cdev->lock);
-
-	result = cdev->ops->set_cur_state(cdev, state);
-	if (!result)
-		thermal_cooling_device_stats_update(cdev, state);
-
+	result = thermal_cdev_set_state(cdev, state);
 	mutex_unlock(&cdev->lock);
+
 	return result ? result : count;
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-06-28 15:26 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-01 15:14 [PATCH 1/3] thermal/core: Encapsulate the set_cur_state function Daniel Lezcano
2022-06-01 15:14 ` [PATCH 2/3] thermal/debugfs: Add debugfs information Daniel Lezcano
2022-06-01 22:55   ` kernel test robot
2022-06-02  0:39   ` kernel test robot
2022-06-02 20:20   ` kernel test robot
2022-06-01 15:14 ` [PATCH 3/3] thermal/sysfs: Remove cooling device sysfs statistics Daniel Lezcano
2022-06-01 15:33   ` Lukasz Luba
2022-06-02  8:37     ` Daniel Lezcano
2022-06-02  9:16       ` Lukasz Luba
2022-06-02 19:02         ` Todd Kjos
2022-06-03 11:04           ` Daniel Lezcano
2022-06-24  6:02             ` Wei Wang
2022-06-28 15:26               ` Daniel Lezcano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).