]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
thermal: helpers: Introduce thermal_trip_is_bound_to_cdev()
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 2 Jul 2024 14:39:55 +0000 (16:39 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 9 Jul 2024 16:22:59 +0000 (18:22 +0200)
Introduce a new helper function thermal_trip_is_bound_to_cdev() for
checking whether or not a given trip point has been bound to a given
cooling device.

The primary user of it will be the Tegra thermal driver.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://patch.msgid.link/13545762.uLZWGnKmhe@rjwysocki.net
drivers/thermal/thermal_helpers.c
include/linux/thermal.h

index d9f4e26ec1257c82f5d7a69ad6fb979c2cec145f..81e019493557f00493720e1cee8a25828cac65c2 100644 (file)
@@ -39,30 +39,53 @@ int get_tz_trend(struct thermal_zone_device *tz, const struct thermal_trip *trip
        return trend;
 }
 
+static struct thermal_instance *get_instance(struct thermal_zone_device *tz,
+                                            struct thermal_cooling_device *cdev,
+                                            const struct thermal_trip *trip)
+{
+       struct thermal_instance *ti;
+
+       list_for_each_entry(ti, &tz->thermal_instances, tz_node) {
+               if (ti->trip == trip && ti->cdev == cdev)
+                       return ti;
+       }
+
+       return NULL;
+}
+
+bool thermal_trip_is_bound_to_cdev(struct thermal_zone_device *tz,
+                                  const struct thermal_trip *trip,
+                                  struct thermal_cooling_device *cdev)
+{
+       bool ret;
+
+       mutex_lock(&tz->lock);
+       mutex_lock(&cdev->lock);
+
+       ret = !!get_instance(tz, cdev, trip);
+
+       mutex_unlock(&cdev->lock);
+       mutex_unlock(&tz->lock);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(thermal_trip_is_bound_to_cdev);
+
 struct thermal_instance *
 get_thermal_instance(struct thermal_zone_device *tz,
                     struct thermal_cooling_device *cdev, int trip_index)
 {
-       struct thermal_instance *pos = NULL;
-       struct thermal_instance *target_instance = NULL;
-       const struct thermal_trip *trip;
+       struct thermal_instance *ti;
 
        mutex_lock(&tz->lock);
        mutex_lock(&cdev->lock);
 
-       trip = &tz->trips[trip_index].trip;
-
-       list_for_each_entry(pos, &tz->thermal_instances, tz_node) {
-               if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
-                       target_instance = pos;
-                       break;
-               }
-       }
+       ti = get_instance(tz, cdev, &tz->trips[trip_index].trip);
 
        mutex_unlock(&cdev->lock);
        mutex_unlock(&tz->lock);
 
-       return target_instance;
+       return ti;
 }
 EXPORT_SYMBOL(get_thermal_instance);
 
index cd0045915af50fd22f912754652454aba0e9fa11..5a0b66bd34f0aaf3a8b1493f783c5055cf5645ca 100644 (file)
@@ -270,6 +270,9 @@ struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name);
 int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp);
 int thermal_zone_get_slope(struct thermal_zone_device *tz);
 int thermal_zone_get_offset(struct thermal_zone_device *tz);
+bool thermal_trip_is_bound_to_cdev(struct thermal_zone_device *tz,
+                                  const struct thermal_trip *trip,
+                                  struct thermal_cooling_device *cdev);
 
 int thermal_zone_device_enable(struct thermal_zone_device *tz);
 int thermal_zone_device_disable(struct thermal_zone_device *tz);