Skip to content

Commit ca70d55

Browse files
committed
thermal: core: Prepare for moving trips between sorted lists
Subsequently, trips will be moved between sorted lists in multiple places, so replace add_trip_to_sorted_list() with an analogous function, move_trip_to_sorted_list(), that will move a given trip to a given sorted list. To allow list_del() used in the new function to work, initialize the list_node fields in trip descriptors where applicable so they are always valid. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Lukasz Luba <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent bd32eac commit ca70d55

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

drivers/thermal/thermal_core.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,17 @@ static void handle_critical_trips(struct thermal_zone_device *tz,
408408
tz->ops.hot(tz);
409409
}
410410

411-
static void add_trip_to_sorted_list(struct thermal_trip_desc *td,
412-
struct list_head *list)
411+
static void move_trip_to_sorted_list(struct thermal_trip_desc *td,
412+
struct list_head *list)
413413
{
414414
struct thermal_trip_desc *entry;
415415

416+
/*
417+
* Delete upfront and then add to make relocation within the same list
418+
* work.
419+
*/
420+
list_del(&td->list_node);
421+
416422
/* Assume that the new entry is likely to be the last one. */
417423
list_for_each_entry_reverse(entry, list, list_node) {
418424
if (entry->notify_temp <= td->notify_temp) {
@@ -453,7 +459,7 @@ static void handle_thermal_trip(struct thermal_zone_device *tz,
453459
*/
454460
if (tz->temperature < trip->temperature - trip->hysteresis) {
455461
td->notify_temp = trip->temperature - trip->hysteresis;
456-
add_trip_to_sorted_list(td, way_down_list);
462+
move_trip_to_sorted_list(td, way_down_list);
457463

458464
if (trip->type == THERMAL_TRIP_PASSIVE) {
459465
tz->passive--;
@@ -469,7 +475,7 @@ static void handle_thermal_trip(struct thermal_zone_device *tz,
469475
* threshold is then set to the low temperature of the trip.
470476
*/
471477
td->notify_temp = trip->temperature;
472-
add_trip_to_sorted_list(td, way_up_list);
478+
move_trip_to_sorted_list(td, way_up_list);
473479

474480
td->threshold -= trip->hysteresis;
475481

@@ -538,7 +544,7 @@ void __thermal_zone_device_update(struct thermal_zone_device *tz,
538544
enum thermal_notify_event event)
539545
{
540546
struct thermal_governor *governor = thermal_get_tz_governor(tz);
541-
struct thermal_trip_desc *td;
547+
struct thermal_trip_desc *td, *next;
542548
LIST_HEAD(way_down_list);
543549
LIST_HEAD(way_up_list);
544550
int low = -INT_MAX, high = INT_MAX;
@@ -586,11 +592,15 @@ void __thermal_zone_device_update(struct thermal_zone_device *tz,
586592

587593
thermal_zone_set_trips(tz, low, high);
588594

589-
list_for_each_entry(td, &way_up_list, list_node)
595+
list_for_each_entry_safe(td, next, &way_up_list, list_node) {
590596
thermal_trip_crossed(tz, &td->trip, governor, true);
597+
list_del_init(&td->list_node);
598+
}
591599

592-
list_for_each_entry_reverse(td, &way_down_list, list_node)
600+
list_for_each_entry_safe_reverse(td, next, &way_down_list, list_node) {
593601
thermal_trip_crossed(tz, &td->trip, governor, false);
602+
list_del_init(&td->list_node);
603+
}
594604

595605
if (governor->manage)
596606
governor->manage(tz);
@@ -1484,6 +1494,7 @@ thermal_zone_device_register_with_trips(const char *type,
14841494
for_each_trip_desc(tz, td) {
14851495
td->trip = *trip++;
14861496
INIT_LIST_HEAD(&td->thermal_instances);
1497+
INIT_LIST_HEAD(&td->list_node);
14871498
/*
14881499
* Mark all thresholds as invalid to start with even though
14891500
* this only matters for the trips that start as invalid and

0 commit comments

Comments
 (0)