@@ -139,11 +139,13 @@ struct tz_episode {
139
139
* we keep track of the current position in the history array.
140
140
*
141
141
* @tz_episodes: a list of thermal mitigation episodes
142
+ * @tz: thermal zone this object belongs to
142
143
* @trips_crossed: an array of trip points crossed by id
143
144
* @nr_trips: the number of trip points currently being crossed
144
145
*/
145
146
struct tz_debugfs {
146
147
struct list_head tz_episodes ;
148
+ struct thermal_zone_device * tz ;
147
149
int * trips_crossed ;
148
150
int nr_trips ;
149
151
};
@@ -503,15 +505,23 @@ void thermal_debug_cdev_add(struct thermal_cooling_device *cdev)
503
505
*/
504
506
void thermal_debug_cdev_remove (struct thermal_cooling_device * cdev )
505
507
{
506
- struct thermal_debugfs * thermal_dbg = cdev -> debugfs ;
508
+ struct thermal_debugfs * thermal_dbg ;
507
509
508
- if (!thermal_dbg )
510
+ mutex_lock (& cdev -> lock );
511
+
512
+ thermal_dbg = cdev -> debugfs ;
513
+ if (!thermal_dbg ) {
514
+ mutex_unlock (& cdev -> lock );
509
515
return ;
516
+ }
517
+
518
+ cdev -> debugfs = NULL ;
519
+
520
+ mutex_unlock (& cdev -> lock );
510
521
511
522
mutex_lock (& thermal_dbg -> lock );
512
523
513
524
thermal_debugfs_cdev_clear (& thermal_dbg -> cdev_dbg );
514
- cdev -> debugfs = NULL ;
515
525
516
526
mutex_unlock (& thermal_dbg -> lock );
517
527
@@ -716,8 +726,7 @@ void thermal_debug_update_temp(struct thermal_zone_device *tz)
716
726
717
727
static void * tze_seq_start (struct seq_file * s , loff_t * pos )
718
728
{
719
- struct thermal_zone_device * tz = s -> private ;
720
- struct thermal_debugfs * thermal_dbg = tz -> debugfs ;
729
+ struct thermal_debugfs * thermal_dbg = s -> private ;
721
730
struct tz_debugfs * tz_dbg = & thermal_dbg -> tz_dbg ;
722
731
723
732
mutex_lock (& thermal_dbg -> lock );
@@ -727,24 +736,23 @@ static void *tze_seq_start(struct seq_file *s, loff_t *pos)
727
736
728
737
static void * tze_seq_next (struct seq_file * s , void * v , loff_t * pos )
729
738
{
730
- struct thermal_zone_device * tz = s -> private ;
731
- struct thermal_debugfs * thermal_dbg = tz -> debugfs ;
739
+ struct thermal_debugfs * thermal_dbg = s -> private ;
732
740
struct tz_debugfs * tz_dbg = & thermal_dbg -> tz_dbg ;
733
741
734
742
return seq_list_next (v , & tz_dbg -> tz_episodes , pos );
735
743
}
736
744
737
745
static void tze_seq_stop (struct seq_file * s , void * v )
738
746
{
739
- struct thermal_zone_device * tz = s -> private ;
740
- struct thermal_debugfs * thermal_dbg = tz -> debugfs ;
747
+ struct thermal_debugfs * thermal_dbg = s -> private ;
741
748
742
749
mutex_unlock (& thermal_dbg -> lock );
743
750
}
744
751
745
752
static int tze_seq_show (struct seq_file * s , void * v )
746
753
{
747
- struct thermal_zone_device * tz = s -> private ;
754
+ struct thermal_debugfs * thermal_dbg = s -> private ;
755
+ struct thermal_zone_device * tz = thermal_dbg -> tz_dbg .tz ;
748
756
struct thermal_trip * trip ;
749
757
struct tz_episode * tze ;
750
758
const char * type ;
@@ -810,6 +818,8 @@ void thermal_debug_tz_add(struct thermal_zone_device *tz)
810
818
811
819
tz_dbg = & thermal_dbg -> tz_dbg ;
812
820
821
+ tz_dbg -> tz = tz ;
822
+
813
823
tz_dbg -> trips_crossed = kzalloc (sizeof (int ) * tz -> num_trips , GFP_KERNEL );
814
824
if (!tz_dbg -> trips_crossed ) {
815
825
thermal_debugfs_remove_id (thermal_dbg );
@@ -818,23 +828,44 @@ void thermal_debug_tz_add(struct thermal_zone_device *tz)
818
828
819
829
INIT_LIST_HEAD (& tz_dbg -> tz_episodes );
820
830
821
- debugfs_create_file ("mitigations" , 0400 , thermal_dbg -> d_top , tz , & tze_fops );
831
+ debugfs_create_file ("mitigations" , 0400 , thermal_dbg -> d_top ,
832
+ thermal_dbg , & tze_fops );
822
833
823
834
tz -> debugfs = thermal_dbg ;
824
835
}
825
836
826
837
void thermal_debug_tz_remove (struct thermal_zone_device * tz )
827
838
{
828
- struct thermal_debugfs * thermal_dbg = tz -> debugfs ;
839
+ struct thermal_debugfs * thermal_dbg ;
840
+ struct tz_episode * tze , * tmp ;
841
+ struct tz_debugfs * tz_dbg ;
842
+ int * trips_crossed ;
829
843
830
- if (!thermal_dbg )
844
+ mutex_lock (& tz -> lock );
845
+
846
+ thermal_dbg = tz -> debugfs ;
847
+ if (!thermal_dbg ) {
848
+ mutex_unlock (& tz -> lock );
831
849
return ;
850
+ }
851
+
852
+ tz -> debugfs = NULL ;
853
+
854
+ mutex_unlock (& tz -> lock );
855
+
856
+ tz_dbg = & thermal_dbg -> tz_dbg ;
832
857
833
858
mutex_lock (& thermal_dbg -> lock );
834
859
835
- tz -> debugfs = NULL ;
860
+ trips_crossed = tz_dbg -> trips_crossed ;
861
+
862
+ list_for_each_entry_safe (tze , tmp , & tz_dbg -> tz_episodes , node ) {
863
+ list_del (& tze -> node );
864
+ kfree (tze );
865
+ }
836
866
837
867
mutex_unlock (& thermal_dbg -> lock );
838
868
839
869
thermal_debugfs_remove_id (thermal_dbg );
870
+ kfree (trips_crossed );
840
871
}
0 commit comments