linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: daniel.lezcano@linaro.org, rafael@kernel.org
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	quic_manafm@quicinc.com, Amit Kucheria <amitk@kernel.org>,
	Zhang Rui <rui.zhang@intel.com>
Subject: [PATCH 1/3] thermal/core: Encapsulate the set_cur_state function
Date: Wed,  1 Jun 2022 17:14:39 +0200	[thread overview]
Message-ID: <20220601151441.9128-1-daniel.lezcano@linaro.org> (raw)

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


             reply	other threads:[~2022-06-01 15:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-01 15:14 Daniel Lezcano [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220601151441.9128-1-daniel.lezcano@linaro.org \
    --to=daniel.lezcano@linaro.org \
    --cc=amitk@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=quic_manafm@quicinc.com \
    --cc=rafael@kernel.org \
    --cc=rui.zhang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).