Skip to content

Commit e3ee4ab

Browse files
committed
Merge branch 'thermal-core'
Merge thermal core fixes and cleanups for 6.12: - Refuse to accept trip point temperature or hysteresis that would lead to an invalid threshold value when setting them via sysfs (Rafael Wysocki). - Adjust states of all uninitialized instances in the .manage() callback of the Bang-bang thermal governor (Rafael Wysocki). - Drop a couple of redundant checks along with the code depending on them from the thermal core (Rafael Wysocki). - Rearrange the thermal core to avoid redundant checks and simplify control flow in a couple of code paths (Rafael Wysocki). * thermal-core: thermal: core: Drop thermal_zone_device_is_enabled() thermal: core: Check passive delay in monitor_thermal_zone() thermal: core: Drop dead code from monitor_thermal_zone() thermal: core: Drop redundant lockdep_assert_held() thermal: gov_bang_bang: Adjust states of all uninitialized instances thermal: sysfs: Add sanity checks for trip temperature and hysteresis
2 parents f5c0597 + 54fccad commit e3ee4ab

File tree

4 files changed

+49
-52
lines changed

4 files changed

+49
-52
lines changed

drivers/thermal/gov_bang_bang.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,21 @@ static void bang_bang_manage(struct thermal_zone_device *tz)
9292

9393
for_each_trip_desc(tz, td) {
9494
const struct thermal_trip *trip = &td->trip;
95+
bool turn_on;
9596

96-
if (tz->temperature >= td->threshold ||
97-
trip->temperature == THERMAL_TEMP_INVALID ||
97+
if (trip->temperature == THERMAL_TEMP_INVALID ||
9898
trip->type == THERMAL_TRIP_CRITICAL ||
9999
trip->type == THERMAL_TRIP_HOT)
100100
continue;
101101

102102
/*
103-
* If the initial cooling device state is "on", but the zone
104-
* temperature is not above the trip point, the core will not
105-
* call bang_bang_control() until the zone temperature reaches
106-
* the trip point temperature which may be never. In those
107-
* cases, set the initial state of the cooling device to 0.
103+
* Adjust the target states for uninitialized thermal instances
104+
* to the thermal zone temperature and the trip point threshold.
108105
*/
106+
turn_on = tz->temperature >= td->threshold;
109107
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
110108
if (!instance->initialized && instance->trip == trip)
111-
bang_bang_set_instance_target(instance, 0);
109+
bang_bang_set_instance_target(instance, turn_on);
112110
}
113111
}
114112

drivers/thermal/thermal_core.c

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,6 @@ static void thermal_zone_broken_disable(struct thermal_zone_device *tz)
323323
static void thermal_zone_device_set_polling(struct thermal_zone_device *tz,
324324
unsigned long delay)
325325
{
326-
if (!delay) {
327-
cancel_delayed_work(&tz->poll_queue);
328-
return;
329-
}
330-
331326
if (delay > HZ)
332327
delay = round_jiffies_relative(delay);
333328

@@ -364,9 +359,7 @@ static void thermal_zone_recheck(struct thermal_zone_device *tz, int error)
364359

365360
static void monitor_thermal_zone(struct thermal_zone_device *tz)
366361
{
367-
if (tz->mode != THERMAL_DEVICE_ENABLED)
368-
thermal_zone_device_set_polling(tz, 0);
369-
else if (tz->passive > 0)
362+
if (tz->passive > 0 && tz->passive_delay_jiffies)
370363
thermal_zone_device_set_polling(tz, tz->passive_delay_jiffies);
371364
else if (tz->polling_delay_jiffies)
372365
thermal_zone_device_set_polling(tz, tz->polling_delay_jiffies);
@@ -554,10 +547,7 @@ void __thermal_zone_device_update(struct thermal_zone_device *tz,
554547
int low = -INT_MAX, high = INT_MAX;
555548
int temp, ret;
556549

557-
if (tz->suspended)
558-
return;
559-
560-
if (!thermal_zone_device_is_enabled(tz))
550+
if (tz->suspended || tz->mode != THERMAL_DEVICE_ENABLED)
561551
return;
562552

563553
ret = __thermal_zone_get_temp(tz, &temp);
@@ -659,13 +649,6 @@ int thermal_zone_device_disable(struct thermal_zone_device *tz)
659649
}
660650
EXPORT_SYMBOL_GPL(thermal_zone_device_disable);
661651

662-
int thermal_zone_device_is_enabled(struct thermal_zone_device *tz)
663-
{
664-
lockdep_assert_held(&tz->lock);
665-
666-
return tz->mode == THERMAL_DEVICE_ENABLED;
667-
}
668-
669652
static bool thermal_zone_is_present(struct thermal_zone_device *tz)
670653
{
671654
return !list_empty(&tz->node);
@@ -891,8 +874,6 @@ static void thermal_unbind_cdev_from_trip(struct thermal_zone_device *tz,
891874
{
892875
struct thermal_instance *pos, *next;
893876

894-
lockdep_assert_held(&tz->lock);
895-
896877
mutex_lock(&cdev->lock);
897878
list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) {
898879
if (pos->trip == trip && pos->cdev == cdev) {
@@ -1415,13 +1396,8 @@ thermal_zone_device_register_with_trips(const char *type,
14151396
if (num_trips > 0 && !trips)
14161397
return ERR_PTR(-EINVAL);
14171398

1418-
if (polling_delay) {
1419-
if (passive_delay > polling_delay)
1420-
return ERR_PTR(-EINVAL);
1421-
1422-
if (!passive_delay)
1423-
passive_delay = polling_delay;
1424-
}
1399+
if (polling_delay && passive_delay > polling_delay)
1400+
return ERR_PTR(-EINVAL);
14251401

14261402
if (!thermal_class)
14271403
return ERR_PTR(-ENODEV);

drivers/thermal/thermal_core.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,4 @@ thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
284284
unsigned long new_state) {}
285285
#endif /* CONFIG_THERMAL_STATISTICS */
286286

287-
/* device tree support */
288-
int thermal_zone_device_is_enabled(struct thermal_zone_device *tz);
289-
290287
#endif /* __THERMAL_CORE_H__ */

drivers/thermal/thermal_sysfs.c

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf)
5353
int enabled;
5454

5555
mutex_lock(&tz->lock);
56-
enabled = thermal_zone_device_is_enabled(tz);
56+
enabled = tz->mode == THERMAL_DEVICE_ENABLED;
5757
mutex_unlock(&tz->lock);
5858

5959
return sprintf(buf, "%s\n", enabled ? "enabled" : "disabled");
@@ -111,18 +111,26 @@ trip_point_temp_store(struct device *dev, struct device_attribute *attr,
111111

112112
mutex_lock(&tz->lock);
113113

114-
if (temp != trip->temperature) {
115-
if (tz->ops.set_trip_temp) {
116-
ret = tz->ops.set_trip_temp(tz, trip, temp);
117-
if (ret)
118-
goto unlock;
119-
}
114+
if (temp == trip->temperature)
115+
goto unlock;
120116

121-
thermal_zone_set_trip_temp(tz, trip, temp);
117+
/* Arrange the condition to avoid integer overflows. */
118+
if (temp != THERMAL_TEMP_INVALID &&
119+
temp <= trip->hysteresis + THERMAL_TEMP_INVALID) {
120+
ret = -EINVAL;
121+
goto unlock;
122+
}
122123

123-
__thermal_zone_device_update(tz, THERMAL_TRIP_CHANGED);
124+
if (tz->ops.set_trip_temp) {
125+
ret = tz->ops.set_trip_temp(tz, trip, temp);
126+
if (ret)
127+
goto unlock;
124128
}
125129

130+
thermal_zone_set_trip_temp(tz, trip, temp);
131+
132+
__thermal_zone_device_update(tz, THERMAL_TRIP_CHANGED);
133+
126134
unlock:
127135
mutex_unlock(&tz->lock);
128136

@@ -152,15 +160,33 @@ trip_point_hyst_store(struct device *dev, struct device_attribute *attr,
152160

153161
mutex_lock(&tz->lock);
154162

155-
if (hyst != trip->hysteresis) {
156-
thermal_zone_set_trip_hyst(tz, trip, hyst);
163+
if (hyst == trip->hysteresis)
164+
goto unlock;
165+
166+
/*
167+
* Allow the hysteresis to be updated when the temperature is invalid
168+
* to allow user space to avoid having to adjust hysteresis after a
169+
* valid temperature has been set, but in that case just change the
170+
* value and do nothing else.
171+
*/
172+
if (trip->temperature == THERMAL_TEMP_INVALID) {
173+
WRITE_ONCE(trip->hysteresis, hyst);
174+
goto unlock;
175+
}
157176

158-
__thermal_zone_device_update(tz, THERMAL_TRIP_CHANGED);
177+
if (trip->temperature - hyst <= THERMAL_TEMP_INVALID) {
178+
ret = -EINVAL;
179+
goto unlock;
159180
}
160181

182+
thermal_zone_set_trip_hyst(tz, trip, hyst);
183+
184+
__thermal_zone_device_update(tz, THERMAL_TRIP_CHANGED);
185+
186+
unlock:
161187
mutex_unlock(&tz->lock);
162188

163-
return count;
189+
return ret ? ret : count;
164190
}
165191

166192
static ssize_t

0 commit comments

Comments
 (0)