[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20260123182208.2229670-3-linux@roeck-us.net>
Date: Fri, 23 Jan 2026 10:22:05 -0800
From: Guenter Roeck <linux@...ck-us.net>
To: linux-hwmon@...r.kernel.org
Cc: linux-doc@...r.kernel.org,
linux-kernel@...r.kernel.org,
Jaroslav Pulchart <jaroslav.pulchart@...ddata.com>,
"Rafael J . Wysocki" <rafael@...nel.org>,
lihuisong <lihuisong@...wei.com>,
Guenter Roeck <linux@...ck-us.net>
Subject: [PATCH RFT 2/5] hwmon: Provide helper function to find thermal zones
Provide a helper function to find registered thermal zones
and use it in the thermal notification function.
Signed-off-by: Guenter Roeck <linux@...ck-us.net>
---
drivers/hwmon/hwmon.c | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 9e9ad42b6d7d..1f35285ca7a0 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -261,6 +261,21 @@ static int hwmon_thermal_add_sensor(struct device *dev, int index)
return 0;
}
+static struct hwmon_thermal_data *hwmon_thermal_find_tz(struct device *dev, int index)
+{
+ struct hwmon_device *hwdev = to_hwmon_device(dev);
+ struct hwmon_thermal_data *tzdata;
+
+ if (!IS_ENABLED(CONFIG_THERMAL_OF))
+ return NULL;
+
+ list_for_each_entry(tzdata, &hwdev->tzdata, node) {
+ if (tzdata->index == index)
+ return tzdata;
+ }
+ return NULL;
+}
+
static int hwmon_thermal_register_sensors(struct device *dev)
{
struct hwmon_device *hwdev = to_hwmon_device(dev);
@@ -297,18 +312,10 @@ static int hwmon_thermal_register_sensors(struct device *dev)
static void hwmon_thermal_notify(struct device *dev, int index)
{
- struct hwmon_device *hwdev = to_hwmon_device(dev);
- struct hwmon_thermal_data *tzdata;
+ struct hwmon_thermal_data *tzdata = hwmon_thermal_find_tz(dev, index);
- if (!IS_ENABLED(CONFIG_THERMAL_OF))
- return;
-
- list_for_each_entry(tzdata, &hwdev->tzdata, node) {
- if (tzdata->index == index) {
- thermal_zone_device_update(tzdata->tzd,
- THERMAL_EVENT_UNSPECIFIED);
- }
- }
+ if (tzdata)
+ thermal_zone_device_update(tzdata->tzd, THERMAL_EVENT_UNSPECIFIED);
}
static int hwmon_attr_base(enum hwmon_sensor_types type)
--
2.45.2
Powered by blists - more mailing lists