mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: "Rafael J . Wysocki" <rafael@kernel.org>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>,
	Amit Kucheria <amitk@kernel.org>, Zhang Rui <rui.zhang@intel.com>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Guenter Roeck <linux@roeck-us.net>
Subject: [PATCH 4/9] thermal/core: Move parameter validation from __thermal_zone_get_temp to thermal_zone_get_temp
Date: Mon, 17 Oct 2022 06:09:05 -0700	[thread overview]
Message-ID: <20221017130910.2307118-5-linux@roeck-us.net> (raw)
In-Reply-To: <20221017130910.2307118-1-linux@roeck-us.net>

All callers of __thermal_zone_get_temp() already validated the
thermal zone parameters. Move validation to thermal_zone_get_temp()
where it is actually needed.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/thermal/thermal_helpers.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/drivers/thermal/thermal_helpers.c b/drivers/thermal/thermal_helpers.c
index 3bac0b7a4c62..0161d5fb1cf2 100644
--- a/drivers/thermal/thermal_helpers.c
+++ b/drivers/thermal/thermal_helpers.c
@@ -64,6 +64,20 @@ get_thermal_instance(struct thermal_zone_device *tz,
 }
 EXPORT_SYMBOL(get_thermal_instance);
 
+/**
+ * __thermal_zone_get_temp() - returns the temperature of a thermal zone
+ * @tz: a valid pointer to a struct thermal_zone_device
+ * @temp: a valid pointer to where to store the resulting temperature.
+ *
+ * When a valid thermal zone reference is passed, it will fetch its
+ * temperature and fill @temp.
+ *
+ * Both tz and tz->ops must be valid pointers when calling this function,
+ * and the tz->ops->get_temp callback must be provided.
+ * The function must be called under tz->lock.
+ *
+ * Return: On success returns 0, an error code otherwise
+ */
 int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
 {
 	int ret = -EINVAL;
@@ -73,9 +87,6 @@ int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
 
 	lockdep_assert_held(&tz->lock);
 
-	if (!tz || IS_ERR(tz) || !tz->ops->get_temp)
-		return -EINVAL;
-
 	ret = tz->ops->get_temp(tz, temp);
 
 	if (IS_ENABLED(CONFIG_THERMAL_EMULATION) && tz->emul_temperature) {
@@ -114,7 +125,16 @@ int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
 {
 	int ret;
 
+	if (!tz || IS_ERR(tz))
+		return -EINVAL;
+
 	mutex_lock(&tz->lock);
+
+	if (!tz->ops->get_temp) {
+		ret = -EINVAL;
+		goto unlock;
+	}
+
 	if (!device_is_registered(&tz->device)) {
 		ret = -ENODEV;
 		goto unlock;
-- 
2.36.2


  parent reply	other threads:[~2022-10-17 13:09 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-17 13:09 [PATCH 0/9] thermal/core: Protect thermal device operations against removal Guenter Roeck
2022-10-17 13:09 ` [PATCH 1/9] thermal/core: Destroy thermal zone device mutex in release function Guenter Roeck
2022-10-17 13:09 ` [PATCH 2/9] thermal/core: Delete device under thermal device zone lock Guenter Roeck
2022-10-17 13:09 ` [PATCH 3/9] thermal/core: Ensure that thermal device is registered in thermal_zone_get_temp Guenter Roeck
2022-11-09 19:07   ` Rafael J. Wysocki
2022-11-10 14:13     ` Guenter Roeck
2022-10-17 13:09 ` Guenter Roeck [this message]
2022-11-09 19:12   ` [PATCH 4/9] thermal/core: Move parameter validation from __thermal_zone_get_temp to thermal_zone_get_temp Rafael J. Wysocki
2022-10-17 13:09 ` [PATCH 5/9] thermal/core: Introduce locked version of thermal_zone_device_update Guenter Roeck
2022-11-09 19:15   ` Rafael J. Wysocki
2022-11-10  0:25     ` Guenter Roeck
2022-11-10 13:01       ` Rafael J. Wysocki
2022-11-10 14:11         ` Guenter Roeck
2022-11-10 14:14           ` Rafael J. Wysocki
2022-10-17 13:09 ` [PATCH 6/9] thermal/core: Protect hwmon accesses to thermal operations with thermal zone mutex Guenter Roeck
2022-11-09 19:19   ` Rafael J. Wysocki
2022-11-10 14:21     ` Guenter Roeck
2022-11-10 14:24       ` Rafael J. Wysocki
2022-10-17 13:09 ` [PATCH 7/9] thermal/core: Protect sysfs " Guenter Roeck
2022-11-09 19:26   ` Rafael J. Wysocki
2022-10-17 13:09 ` [PATCH 8/9] thermal/core: Remove thermal_zone_set_trips() Guenter Roeck
2022-10-17 13:09 ` [PATCH 9/9] thermal/core: Protect thermal device operations against thermal device removal Guenter Roeck
2022-11-02 18:50 ` [PATCH 0/9] thermal/core: Protect thermal device operations against removal Guenter Roeck
2022-11-02 18:55   ` Daniel Lezcano
2022-11-09 19:30   ` Rafael J. Wysocki

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=20221017130910.2307118-5-linux@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=amitk@kernel.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --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

all inboxes | Powered by JetHome®