Skip to content

Commit e271f99

Browse files
committed
thermal/debugfs: Clean up thermal_debug_update_temp()
Notice that it is not necessary to compute tze in every iteration of the for () loop in thermal_debug_update_temp() because it is the same for all trips, so compute it once before the loop starts. Also use a trip_stats local variable to make the code in that loop easier to follow and move the trip_id variable definition into that loop because it is not used elsewhere in the function. While at it, change to order of local variable definitions in the function to follow the reverse-xmas-tree pattern. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Lukasz Luba <[email protected]> Acked-by: Daniel Lezcano <[email protected]>
1 parent 0a293c7 commit e271f99

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

drivers/thermal/thermal_debugfs.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -679,9 +679,9 @@ void thermal_debug_tz_trip_down(struct thermal_zone_device *tz,
679679
void thermal_debug_update_temp(struct thermal_zone_device *tz)
680680
{
681681
struct thermal_debugfs *thermal_dbg = tz->debugfs;
682-
struct tz_episode *tze;
683682
struct tz_debugfs *tz_dbg;
684-
int trip_id, i;
683+
struct tz_episode *tze;
684+
int i;
685685

686686
if (!thermal_dbg)
687687
return;
@@ -693,15 +693,16 @@ void thermal_debug_update_temp(struct thermal_zone_device *tz)
693693
if (!tz_dbg->nr_trips)
694694
goto out;
695695

696+
tze = list_first_entry(&tz_dbg->tz_episodes, struct tz_episode, node);
697+
696698
for (i = 0; i < tz_dbg->nr_trips; i++) {
697-
trip_id = tz_dbg->trips_crossed[i];
698-
tze = list_first_entry(&tz_dbg->tz_episodes, struct tz_episode, node);
699-
tze->trip_stats[trip_id].count++;
700-
tze->trip_stats[trip_id].max = max(tze->trip_stats[trip_id].max, tz->temperature);
701-
tze->trip_stats[trip_id].min = min(tze->trip_stats[trip_id].min, tz->temperature);
702-
tze->trip_stats[trip_id].avg = tze->trip_stats[trip_id].avg +
703-
(tz->temperature - tze->trip_stats[trip_id].avg) /
704-
tze->trip_stats[trip_id].count;
699+
int trip_id = tz_dbg->trips_crossed[i];
700+
struct trip_stats *trip_stats = &tze->trip_stats[trip_id];
701+
702+
trip_stats->max = max(trip_stats->max, tz->temperature);
703+
trip_stats->min = min(trip_stats->min, tz->temperature);
704+
trip_stats->avg += (tz->temperature - trip_stats->avg) /
705+
++trip_stats->count;
705706
}
706707
out:
707708
mutex_unlock(&thermal_dbg->lock);

0 commit comments

Comments
 (0)