Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 463b86f

Browse files
committed
thermal: helpers: Introduce thermal_trip_is_bound_to_cdev()
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
1 parent d05374d commit 463b86f

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed

drivers/thermal/thermal_helpers.c

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,53 @@ int get_tz_trend(struct thermal_zone_device *tz, const struct thermal_trip *trip
3939
return trend;
4040
}
4141

42+
static struct thermal_instance *get_instance(struct thermal_zone_device *tz,
43+
struct thermal_cooling_device *cdev,
44+
const struct thermal_trip *trip)
45+
{
46+
struct thermal_instance *ti;
47+
48+
list_for_each_entry(ti, &tz->thermal_instances, tz_node) {
49+
if (ti->trip == trip && ti->cdev == cdev)
50+
return ti;
51+
}
52+
53+
return NULL;
54+
}
55+
56+
bool thermal_trip_is_bound_to_cdev(struct thermal_zone_device *tz,
57+
const struct thermal_trip *trip,
58+
struct thermal_cooling_device *cdev)
59+
{
60+
bool ret;
61+
62+
mutex_lock(&tz->lock);
63+
mutex_lock(&cdev->lock);
64+
65+
ret = !!get_instance(tz, cdev, trip);
66+
67+
mutex_unlock(&cdev->lock);
68+
mutex_unlock(&tz->lock);
69+
70+
return ret;
71+
}
72+
EXPORT_SYMBOL_GPL(thermal_trip_is_bound_to_cdev);
73+
4274
struct thermal_instance *
4375
get_thermal_instance(struct thermal_zone_device *tz,
4476
struct thermal_cooling_device *cdev, int trip_index)
4577
{
46-
struct thermal_instance *pos = NULL;
47-
struct thermal_instance *target_instance = NULL;
48-
const struct thermal_trip *trip;
78+
struct thermal_instance *ti;
4979

5080
mutex_lock(&tz->lock);
5181
mutex_lock(&cdev->lock);
5282

53-
trip = &tz->trips[trip_index].trip;
54-
55-
list_for_each_entry(pos, &tz->thermal_instances, tz_node) {
56-
if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
57-
target_instance = pos;
58-
break;
59-
}
60-
}
83+
ti = get_instance(tz, cdev, &tz->trips[trip_index].trip);
6184

6285
mutex_unlock(&cdev->lock);
6386
mutex_unlock(&tz->lock);
6487

65-
return target_instance;
88+
return ti;
6689
}
6790
EXPORT_SYMBOL(get_thermal_instance);
6891

include/linux/thermal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name);
270270
int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp);
271271
int thermal_zone_get_slope(struct thermal_zone_device *tz);
272272
int thermal_zone_get_offset(struct thermal_zone_device *tz);
273+
bool thermal_trip_is_bound_to_cdev(struct thermal_zone_device *tz,
274+
const struct thermal_trip *trip,
275+
struct thermal_cooling_device *cdev);
273276

274277
int thermal_zone_device_enable(struct thermal_zone_device *tz);
275278
int thermal_zone_device_disable(struct thermal_zone_device *tz);

0 commit comments

Comments
 (0)