Skip to content

Commit 94eacc1

Browse files
committed
thermal: core: Fix list sorting in __thermal_zone_device_update()
The order in which lists are sorted in __thermal_zone_device_update() is reverse with respect to what it should be due to a mistake in thermal_trip_notify_cmp(). Fix it and observe that it is not necessary to sort the lists in different orders. They can both be sorted in ascending order if way_down_list is walked in reverse order which allows the code to be slightly more straightforward (and less prone to silly mistakes). Fixes: 7454f2c ("thermal: core: Sort trip point crossing notifications by temperature") Signed-off-by: Rafael J. Wysocki <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent a8a2617 commit 94eacc1

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

drivers/thermal/thermal_core.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -484,16 +484,14 @@ static void thermal_trip_crossed(struct thermal_zone_device *tz,
484484
thermal_governor_trip_crossed(governor, tz, trip, crossed_up);
485485
}
486486

487-
static int thermal_trip_notify_cmp(void *ascending, const struct list_head *a,
487+
static int thermal_trip_notify_cmp(void *not_used, const struct list_head *a,
488488
const struct list_head *b)
489489
{
490490
struct thermal_trip_desc *tda = container_of(a, struct thermal_trip_desc,
491491
notify_list_node);
492492
struct thermal_trip_desc *tdb = container_of(b, struct thermal_trip_desc,
493493
notify_list_node);
494-
int ret = tdb->notify_temp - tda->notify_temp;
495-
496-
return ascending ? ret : -ret;
494+
return tda->notify_temp - tdb->notify_temp;
497495
}
498496

499497
void __thermal_zone_device_update(struct thermal_zone_device *tz,
@@ -522,12 +520,12 @@ void __thermal_zone_device_update(struct thermal_zone_device *tz,
522520
for_each_trip_desc(tz, td)
523521
handle_thermal_trip(tz, td, &way_up_list, &way_down_list);
524522

525-
list_sort(&way_up_list, &way_up_list, thermal_trip_notify_cmp);
523+
list_sort(NULL, &way_up_list, thermal_trip_notify_cmp);
526524
list_for_each_entry(td, &way_up_list, notify_list_node)
527525
thermal_trip_crossed(tz, &td->trip, governor, true);
528526

529527
list_sort(NULL, &way_down_list, thermal_trip_notify_cmp);
530-
list_for_each_entry(td, &way_down_list, notify_list_node)
528+
list_for_each_entry_reverse(td, &way_down_list, notify_list_node)
531529
thermal_trip_crossed(tz, &td->trip, governor, false);
532530

533531
if (governor->manage)

0 commit comments

Comments
 (0)