1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright 2023 Linaro Limited
7 * Thermal subsystem debug support
9 #include <linux/debugfs.h>
10 #include <linux/ktime.h>
11 #include <linux/list.h>
12 #include <linux/minmax.h>
13 #include <linux/mutex.h>
14 #include <linux/thermal.h>
16 #include "thermal_core.h"
18 static struct dentry *d_root;
19 static struct dentry *d_cdev;
20 static struct dentry *d_tz;
23 * Length of the string containing the thermal zone id or the cooling
24 * device id, including the ending nul character. We can reasonably
25 * assume there won't be more than 256 thermal zones as the maximum
26 * observed today is around 32.
31 * The cooling device transition list is stored in a hash table where
32 * the size is CDEVSTATS_HASH_SIZE. The majority of cooling devices
33 * have dozen of states but some can have much more, so a hash table
34 * is more adequate in this case, because the cost of browsing the entire
35 * list when storing the transitions may not be negligible.
37 #define CDEVSTATS_HASH_SIZE 16
40 * struct cdev_debugfs - per cooling device statistics structure
41 * A cooling device can have a high number of states. Showing the
42 * transitions on a matrix based representation can be overkill given
43 * most of the transitions won't happen and we end up with a matrix
44 * filled with zero. Instead, we show the transitions which actually
47 * Every transition updates the current_state and the timestamp. The
48 * transitions and the durations are stored in lists.
50 * @total: the number of transitions for this cooling device
51 * @current_state: the current cooling device state
52 * @timestamp: the state change timestamp
53 * @transitions: an array of lists containing the state transitions
54 * @durations: an array of lists containing the residencies of each state
60 struct list_head transitions[CDEVSTATS_HASH_SIZE];
61 struct list_head durations[CDEVSTATS_HASH_SIZE];
65 * struct cdev_record - Common structure for cooling device entry
67 * The following common structure allows to store the information
68 * related to the transitions and to the state residencies. They are
69 * identified with a id which is associated to a value. It is used as
70 * nodes for the "transitions" and "durations" above.
72 * @node: node to insert the structure in a list
73 * @id: identifier of the value which can be a state or a transition
74 * @residency: a ktime_t representing a state residency duration
75 * @count: a number of occurrences
78 struct list_head node;
87 * struct trip_stats - Thermal trip statistics
89 * The trip_stats structure has the relevant information to show the
90 * statistics related to temperature going above a trip point.
92 * @timestamp: the trip crossing timestamp
93 * @duration: total time when the zone temperature was above the trip point
94 * @count: the number of times the zone temperature was above the trip point
95 * @max: maximum recorded temperature above the trip point
96 * @min: minimum recorded temperature above the trip point
97 * @avg: average temperature above the trip point
109 * struct tz_episode - A mitigation episode information
111 * The tz_episode structure describes a mitigation episode. A
112 * mitigation episode begins the trip point with the lower temperature
113 * is crossed the way up and ends when it is crossed the way
114 * down. During this episode we can have multiple trip points crossed
115 * the way up and down if there are multiple trip described in the
116 * firmware after the lowest temperature trip point.
118 * @timestamp: first trip point crossed the way up
119 * @duration: total duration of the mitigation episode
120 * @node: a list element to be added to the list of tz events
121 * @trip_stats: per trip point statistics, flexible array
126 struct list_head node;
127 struct trip_stats trip_stats[];
131 * struct tz_debugfs - Store all mitigation episodes for a thermal zone
133 * The tz_debugfs structure contains the list of the mitigation
134 * episodes and has to track which trip point has been crossed in
135 * order to handle correctly nested trip point mitigation episodes.
137 * We keep the history of the trip point crossed in an array and as we
138 * can go back and forth inside this history, eg. trip 0,1,2,1,2,1,0,
139 * we keep track of the current position in the history array.
141 * @tz_episodes: a list of thermal mitigation episodes
142 * @tz: thermal zone this object belongs to
143 * @trips_crossed: an array of trip points crossed by id
144 * @nr_trips: the number of trip points currently being crossed
147 struct list_head tz_episodes;
148 struct thermal_zone_device *tz;
154 * struct thermal_debugfs - High level structure for a thermal object in debugfs
156 * The thermal_debugfs structure is the common structure used by the
157 * cooling device or the thermal zone to store the statistics.
159 * @d_top: top directory of the thermal object directory
160 * @lock: per object lock to protect the internals
162 * @cdev_dbg: a cooling device debug structure
163 * @tz_dbg: a thermal zone debug structure
165 struct thermal_debugfs {
166 struct dentry *d_top;
169 struct cdev_debugfs cdev_dbg;
170 struct tz_debugfs tz_dbg;
174 void thermal_debug_init(void)
176 d_root = debugfs_create_dir("thermal", NULL);
180 d_cdev = debugfs_create_dir("cooling_devices", d_root);
184 d_tz = debugfs_create_dir("thermal_zones", d_root);
187 static struct thermal_debugfs *thermal_debugfs_add_id(struct dentry *d, int id)
189 struct thermal_debugfs *thermal_dbg;
192 thermal_dbg = kzalloc(sizeof(*thermal_dbg), GFP_KERNEL);
196 mutex_init(&thermal_dbg->lock);
198 snprintf(ids, IDSLENGTH, "%d", id);
200 thermal_dbg->d_top = debugfs_create_dir(ids, d);
201 if (!thermal_dbg->d_top) {
209 static void thermal_debugfs_remove_id(struct thermal_debugfs *thermal_dbg)
214 debugfs_remove(thermal_dbg->d_top);
219 static struct cdev_record *
220 thermal_debugfs_cdev_record_alloc(struct thermal_debugfs *thermal_dbg,
221 struct list_head *lists, int id)
223 struct cdev_record *cdev_record;
225 cdev_record = kzalloc(sizeof(*cdev_record), GFP_KERNEL);
229 cdev_record->id = id;
230 INIT_LIST_HEAD(&cdev_record->node);
231 list_add_tail(&cdev_record->node,
232 &lists[cdev_record->id % CDEVSTATS_HASH_SIZE]);
237 static struct cdev_record *
238 thermal_debugfs_cdev_record_find(struct thermal_debugfs *thermal_dbg,
239 struct list_head *lists, int id)
241 struct cdev_record *entry;
243 list_for_each_entry(entry, &lists[id % CDEVSTATS_HASH_SIZE], node)
250 static struct cdev_record *
251 thermal_debugfs_cdev_record_get(struct thermal_debugfs *thermal_dbg,
252 struct list_head *lists, int id)
254 struct cdev_record *cdev_record;
256 cdev_record = thermal_debugfs_cdev_record_find(thermal_dbg, lists, id);
260 return thermal_debugfs_cdev_record_alloc(thermal_dbg, lists, id);
263 static void thermal_debugfs_cdev_clear(struct cdev_debugfs *cdev_dbg)
266 struct cdev_record *entry, *tmp;
268 for (i = 0; i < CDEVSTATS_HASH_SIZE; i++) {
270 list_for_each_entry_safe(entry, tmp,
271 &cdev_dbg->transitions[i], node) {
272 list_del(&entry->node);
276 list_for_each_entry_safe(entry, tmp,
277 &cdev_dbg->durations[i], node) {
278 list_del(&entry->node);
286 static void *cdev_seq_start(struct seq_file *s, loff_t *pos)
288 struct thermal_debugfs *thermal_dbg = s->private;
290 mutex_lock(&thermal_dbg->lock);
292 return (*pos < CDEVSTATS_HASH_SIZE) ? pos : NULL;
295 static void *cdev_seq_next(struct seq_file *s, void *v, loff_t *pos)
299 return (*pos < CDEVSTATS_HASH_SIZE) ? pos : NULL;
302 static void cdev_seq_stop(struct seq_file *s, void *v)
304 struct thermal_debugfs *thermal_dbg = s->private;
306 mutex_unlock(&thermal_dbg->lock);
309 static int cdev_tt_seq_show(struct seq_file *s, void *v)
311 struct thermal_debugfs *thermal_dbg = s->private;
312 struct cdev_debugfs *cdev_dbg = &thermal_dbg->cdev_dbg;
313 struct list_head *transitions = cdev_dbg->transitions;
314 struct cdev_record *entry;
315 int i = *(loff_t *)v;
318 seq_puts(s, "Transition\tOccurences\n");
320 list_for_each_entry(entry, &transitions[i], node) {
322 * Assuming maximum cdev states is 1024, the longer
323 * string for a transition would be "1024->1024\0"
327 snprintf(buffer, ARRAY_SIZE(buffer), "%d->%d",
328 entry->id >> 16, entry->id & 0xFFFF);
330 seq_printf(s, "%-10s\t%-10llu\n", buffer, entry->count);
336 static const struct seq_operations tt_sops = {
337 .start = cdev_seq_start,
338 .next = cdev_seq_next,
339 .stop = cdev_seq_stop,
340 .show = cdev_tt_seq_show,
343 DEFINE_SEQ_ATTRIBUTE(tt);
345 static int cdev_dt_seq_show(struct seq_file *s, void *v)
347 struct thermal_debugfs *thermal_dbg = s->private;
348 struct cdev_debugfs *cdev_dbg = &thermal_dbg->cdev_dbg;
349 struct list_head *durations = cdev_dbg->durations;
350 struct cdev_record *entry;
351 int i = *(loff_t *)v;
354 seq_puts(s, "State\tResidency\n");
356 list_for_each_entry(entry, &durations[i], node) {
357 s64 duration = ktime_to_ms(entry->residency);
359 if (entry->id == cdev_dbg->current_state)
360 duration += ktime_ms_delta(ktime_get(),
361 cdev_dbg->timestamp);
363 seq_printf(s, "%-5d\t%-10llu\n", entry->id, duration);
369 static const struct seq_operations dt_sops = {
370 .start = cdev_seq_start,
371 .next = cdev_seq_next,
372 .stop = cdev_seq_stop,
373 .show = cdev_dt_seq_show,
376 DEFINE_SEQ_ATTRIBUTE(dt);
378 static int cdev_clear_set(void *data, u64 val)
380 struct thermal_debugfs *thermal_dbg = data;
385 mutex_lock(&thermal_dbg->lock);
387 thermal_debugfs_cdev_clear(&thermal_dbg->cdev_dbg);
389 mutex_unlock(&thermal_dbg->lock);
394 DEFINE_DEBUGFS_ATTRIBUTE(cdev_clear_fops, NULL, cdev_clear_set, "%llu\n");
397 * thermal_debug_cdev_state_update - Update a cooling device state change
399 * Computes a transition and the duration of the previous state residency.
401 * @cdev : a pointer to a cooling device
402 * @new_state: an integer corresponding to the new cooling device state
404 void thermal_debug_cdev_state_update(const struct thermal_cooling_device *cdev,
407 struct thermal_debugfs *thermal_dbg = cdev->debugfs;
408 struct cdev_debugfs *cdev_dbg;
409 struct cdev_record *cdev_record;
410 int transition, old_state;
412 if (!thermal_dbg || (thermal_dbg->cdev_dbg.current_state == new_state))
415 mutex_lock(&thermal_dbg->lock);
417 cdev_dbg = &thermal_dbg->cdev_dbg;
419 old_state = cdev_dbg->current_state;
422 * Get the old state information in the durations list. If
423 * this one does not exist, a new allocated one will be
424 * returned. Recompute the total duration in the old state and
425 * get a new timestamp for the new state.
427 cdev_record = thermal_debugfs_cdev_record_get(thermal_dbg,
431 ktime_t now = ktime_get();
432 ktime_t delta = ktime_sub(now, cdev_dbg->timestamp);
433 cdev_record->residency = ktime_add(cdev_record->residency, delta);
434 cdev_dbg->timestamp = now;
437 cdev_dbg->current_state = new_state;
440 * Create a record for the new state if it is not there, so its
441 * duration will be printed by cdev_dt_seq_show() as expected if it
442 * runs before the next state transition.
444 thermal_debugfs_cdev_record_get(thermal_dbg, cdev_dbg->durations, new_state);
446 transition = (old_state << 16) | new_state;
449 * Get the transition in the transitions list. If this one
450 * does not exist, a new allocated one will be returned.
451 * Increment the occurrence of this transition which is stored
452 * in the value field.
454 cdev_record = thermal_debugfs_cdev_record_get(thermal_dbg,
455 cdev_dbg->transitions,
458 cdev_record->count++;
462 mutex_unlock(&thermal_dbg->lock);
466 * thermal_debug_cdev_add - Add a cooling device debugfs entry
468 * Allocates a cooling device object for debug, initializes the
469 * statistics and create the entries in sysfs.
470 * @cdev: a pointer to a cooling device
471 * @state: current state of the cooling device
473 void thermal_debug_cdev_add(struct thermal_cooling_device *cdev, int state)
475 struct thermal_debugfs *thermal_dbg;
476 struct cdev_debugfs *cdev_dbg;
479 thermal_dbg = thermal_debugfs_add_id(d_cdev, cdev->id);
483 cdev_dbg = &thermal_dbg->cdev_dbg;
485 for (i = 0; i < CDEVSTATS_HASH_SIZE; i++) {
486 INIT_LIST_HEAD(&cdev_dbg->transitions[i]);
487 INIT_LIST_HEAD(&cdev_dbg->durations[i]);
490 cdev_dbg->current_state = state;
491 cdev_dbg->timestamp = ktime_get();
494 * Create a record for the initial cooling device state, so its
495 * duration will be printed by cdev_dt_seq_show() as expected if it
496 * runs before the first state transition.
498 thermal_debugfs_cdev_record_get(thermal_dbg, cdev_dbg->durations, state);
500 debugfs_create_file("trans_table", 0400, thermal_dbg->d_top,
501 thermal_dbg, &tt_fops);
503 debugfs_create_file("time_in_state_ms", 0400, thermal_dbg->d_top,
504 thermal_dbg, &dt_fops);
506 debugfs_create_file("clear", 0200, thermal_dbg->d_top,
507 thermal_dbg, &cdev_clear_fops);
509 debugfs_create_u32("total_trans", 0400, thermal_dbg->d_top,
512 cdev->debugfs = thermal_dbg;
516 * thermal_debug_cdev_remove - Remove a cooling device debugfs entry
518 * Frees the statistics memory data and remove the debugfs entry
520 * @cdev: a pointer to a cooling device
522 void thermal_debug_cdev_remove(struct thermal_cooling_device *cdev)
524 struct thermal_debugfs *thermal_dbg;
526 mutex_lock(&cdev->lock);
528 thermal_dbg = cdev->debugfs;
530 mutex_unlock(&cdev->lock);
534 cdev->debugfs = NULL;
536 mutex_unlock(&cdev->lock);
538 mutex_lock(&thermal_dbg->lock);
540 thermal_debugfs_cdev_clear(&thermal_dbg->cdev_dbg);
542 mutex_unlock(&thermal_dbg->lock);
544 thermal_debugfs_remove_id(thermal_dbg);
547 static struct tz_episode *thermal_debugfs_tz_event_alloc(struct thermal_zone_device *tz,
550 struct tz_episode *tze;
553 tze = kzalloc(struct_size(tze, trip_stats, tz->num_trips), GFP_KERNEL);
557 INIT_LIST_HEAD(&tze->node);
558 tze->timestamp = now;
559 tze->duration = KTIME_MIN;
561 for (i = 0; i < tz->num_trips; i++) {
562 tze->trip_stats[i].min = INT_MAX;
563 tze->trip_stats[i].max = INT_MIN;
569 void thermal_debug_tz_trip_up(struct thermal_zone_device *tz,
570 const struct thermal_trip *trip)
572 struct tz_episode *tze;
573 struct tz_debugfs *tz_dbg;
574 struct thermal_debugfs *thermal_dbg = tz->debugfs;
575 int trip_id = thermal_zone_trip_id(tz, trip);
576 ktime_t now = ktime_get();
581 mutex_lock(&thermal_dbg->lock);
583 tz_dbg = &thermal_dbg->tz_dbg;
586 * The mitigation is starting. A mitigation can contain
587 * several episodes where each of them is related to a
588 * temperature crossing a trip point. The episodes are
589 * nested. That means when the temperature is crossing the
590 * first trip point, the duration begins to be measured. If
591 * the temperature continues to increase and reaches the
592 * second trip point, the duration of the first trip must be
602 * trip 1 / | | `---- | | \
604 * trip 0 / | | | | | | \
605 * | /| | | | | | | |\
606 * | / | | | | | | | | `--
607 * | / | | | | | | | |
608 * |----- | | | | | | | |
610 * --------|-|-|--------|--------|------|-|-|------------------> time
611 * | | |<--t2-->| |<-t2'>| | |
613 * | |<------------t1------------>| |
615 * |<-------------t0--------------->|
618 if (!tz_dbg->nr_trips) {
619 tze = thermal_debugfs_tz_event_alloc(tz, now);
623 list_add(&tze->node, &tz_dbg->tz_episodes);
627 * Each time a trip point is crossed the way up, the trip_id
628 * is stored in the trip_crossed array and the nr_trips is
629 * incremented. A nr_trips equal to zero means we are entering
630 * a mitigation episode.
632 * The trip ids may not be in the ascending order but the
633 * result in the array trips_crossed will be in the ascending
634 * temperature order. The function detecting when a trip point
635 * is crossed the way down will handle the very rare case when
636 * the trip points may have been reordered during this
637 * mitigation episode.
639 tz_dbg->trips_crossed[tz_dbg->nr_trips++] = trip_id;
641 tze = list_first_entry(&tz_dbg->tz_episodes, struct tz_episode, node);
642 tze->trip_stats[trip_id].timestamp = now;
645 mutex_unlock(&thermal_dbg->lock);
648 void thermal_debug_tz_trip_down(struct thermal_zone_device *tz,
649 const struct thermal_trip *trip)
651 struct thermal_debugfs *thermal_dbg = tz->debugfs;
652 struct tz_episode *tze;
653 struct tz_debugfs *tz_dbg;
654 ktime_t delta, now = ktime_get();
655 int trip_id = thermal_zone_trip_id(tz, trip);
661 mutex_lock(&thermal_dbg->lock);
663 tz_dbg = &thermal_dbg->tz_dbg;
666 * The temperature crosses the way down but there was not
667 * mitigation detected before. That may happen when the
668 * temperature is greater than a trip point when registering a
669 * thermal zone, which is a common use case as the kernel has
670 * no mitigation mechanism yet at boot time.
672 if (!tz_dbg->nr_trips)
675 for (i = tz_dbg->nr_trips - 1; i >= 0; i--) {
676 if (tz_dbg->trips_crossed[i] == trip_id)
685 if (i < tz_dbg->nr_trips)
686 tz_dbg->trips_crossed[i] = tz_dbg->trips_crossed[tz_dbg->nr_trips];
688 tze = list_first_entry(&tz_dbg->tz_episodes, struct tz_episode, node);
690 delta = ktime_sub(now, tze->trip_stats[trip_id].timestamp);
692 tze->trip_stats[trip_id].duration =
693 ktime_add(delta, tze->trip_stats[trip_id].duration);
695 /* Mark the end of mitigation for this trip point. */
696 tze->trip_stats[trip_id].timestamp = KTIME_MAX;
699 * This event closes the mitigation as we are crossing the
700 * last trip point the way down.
702 if (!tz_dbg->nr_trips)
703 tze->duration = ktime_sub(now, tze->timestamp);
706 mutex_unlock(&thermal_dbg->lock);
709 void thermal_debug_update_trip_stats(struct thermal_zone_device *tz)
711 struct thermal_debugfs *thermal_dbg = tz->debugfs;
712 struct tz_debugfs *tz_dbg;
713 struct tz_episode *tze;
719 mutex_lock(&thermal_dbg->lock);
721 tz_dbg = &thermal_dbg->tz_dbg;
723 if (!tz_dbg->nr_trips)
726 tze = list_first_entry(&tz_dbg->tz_episodes, struct tz_episode, node);
728 for (i = 0; i < tz_dbg->nr_trips; i++) {
729 int trip_id = tz_dbg->trips_crossed[i];
730 struct trip_stats *trip_stats = &tze->trip_stats[trip_id];
732 trip_stats->max = max(trip_stats->max, tz->temperature);
733 trip_stats->min = min(trip_stats->min, tz->temperature);
734 trip_stats->avg += (tz->temperature - trip_stats->avg) /
738 mutex_unlock(&thermal_dbg->lock);
741 static void *tze_seq_start(struct seq_file *s, loff_t *pos)
743 struct thermal_debugfs *thermal_dbg = s->private;
744 struct tz_debugfs *tz_dbg = &thermal_dbg->tz_dbg;
746 mutex_lock(&thermal_dbg->lock);
748 return seq_list_start(&tz_dbg->tz_episodes, *pos);
751 static void *tze_seq_next(struct seq_file *s, void *v, loff_t *pos)
753 struct thermal_debugfs *thermal_dbg = s->private;
754 struct tz_debugfs *tz_dbg = &thermal_dbg->tz_dbg;
756 return seq_list_next(v, &tz_dbg->tz_episodes, pos);
759 static void tze_seq_stop(struct seq_file *s, void *v)
761 struct thermal_debugfs *thermal_dbg = s->private;
763 mutex_unlock(&thermal_dbg->lock);
766 static int tze_seq_show(struct seq_file *s, void *v)
768 struct thermal_debugfs *thermal_dbg = s->private;
769 struct thermal_zone_device *tz = thermal_dbg->tz_dbg.tz;
770 struct thermal_trip_desc *td;
771 struct tz_episode *tze;
777 tze = list_entry((struct list_head *)v, struct tz_episode, node);
779 if (tze->duration == KTIME_MIN) {
780 /* Mitigation in progress. */
781 duration_ms = ktime_to_ms(ktime_sub(ktime_get(), tze->timestamp));
784 duration_ms = ktime_to_ms(tze->duration);
788 seq_printf(s, ",-Mitigation at %lluus, duration%c%llums\n",
789 ktime_to_us(tze->timestamp), c, duration_ms);
791 seq_printf(s, "| trip | type | temp(°mC) | hyst(°mC) | duration | avg(°mC) | min(°mC) | max(°mC) |\n");
793 for_each_trip_desc(tz, td) {
794 const struct thermal_trip *trip = &td->trip;
795 struct trip_stats *trip_stats;
797 /* Skip invalid trips. */
798 if (trip->temperature == THERMAL_TEMP_INVALID)
802 * There is no possible mitigation happening at the
803 * critical trip point, so the stats will be always
804 * zero, skip this trip point
806 if (trip->type == THERMAL_TRIP_CRITICAL)
809 trip_id = thermal_zone_trip_id(tz, trip);
810 trip_stats = &tze->trip_stats[trip_id];
812 /* Skip trips without any stats. */
813 if (trip_stats->min > trip_stats->max)
816 if (trip->type == THERMAL_TRIP_PASSIVE)
818 else if (trip->type == THERMAL_TRIP_ACTIVE)
823 if (trip_stats->timestamp != KTIME_MAX) {
824 /* Mitigation in progress. */
825 ktime_t delta = ktime_sub(ktime_get(),
826 trip_stats->timestamp);
828 delta = ktime_add(delta, trip_stats->duration);
829 duration_ms = ktime_to_ms(delta);
832 duration_ms = ktime_to_ms(trip_stats->duration);
836 seq_printf(s, "| %*d | %*s | %*d | %*d | %c%*lld | %*d | %*d | %*d |\n",
839 9, trip->temperature,
850 static const struct seq_operations tze_sops = {
851 .start = tze_seq_start,
852 .next = tze_seq_next,
853 .stop = tze_seq_stop,
854 .show = tze_seq_show,
857 DEFINE_SEQ_ATTRIBUTE(tze);
859 void thermal_debug_tz_add(struct thermal_zone_device *tz)
861 struct thermal_debugfs *thermal_dbg;
862 struct tz_debugfs *tz_dbg;
864 thermal_dbg = thermal_debugfs_add_id(d_tz, tz->id);
868 tz_dbg = &thermal_dbg->tz_dbg;
872 tz_dbg->trips_crossed = kzalloc(sizeof(int) * tz->num_trips, GFP_KERNEL);
873 if (!tz_dbg->trips_crossed) {
874 thermal_debugfs_remove_id(thermal_dbg);
878 INIT_LIST_HEAD(&tz_dbg->tz_episodes);
880 debugfs_create_file("mitigations", 0400, thermal_dbg->d_top,
881 thermal_dbg, &tze_fops);
883 tz->debugfs = thermal_dbg;
886 void thermal_debug_tz_remove(struct thermal_zone_device *tz)
888 struct thermal_debugfs *thermal_dbg;
889 struct tz_episode *tze, *tmp;
890 struct tz_debugfs *tz_dbg;
893 mutex_lock(&tz->lock);
895 thermal_dbg = tz->debugfs;
897 mutex_unlock(&tz->lock);
903 mutex_unlock(&tz->lock);
905 tz_dbg = &thermal_dbg->tz_dbg;
907 mutex_lock(&thermal_dbg->lock);
909 trips_crossed = tz_dbg->trips_crossed;
911 list_for_each_entry_safe(tze, tmp, &tz_dbg->tz_episodes, node) {
912 list_del(&tze->node);
916 mutex_unlock(&thermal_dbg->lock);
918 thermal_debugfs_remove_id(thermal_dbg);
919 kfree(trips_crossed);