@@ -69,58 +69,60 @@ static struct user_threshold *__thermal_thresholds_find(const struct list_head *
69
69
return NULL ;
70
70
}
71
71
72
- static bool __thermal_threshold_is_crossed (struct user_threshold * threshold , int temperature ,
73
- int last_temperature , int direction ,
74
- int * low , int * high )
72
+ static bool thermal_thresholds_handle_raising (struct list_head * thresholds , int temperature ,
73
+ int last_temperature )
75
74
{
75
+ struct user_threshold * t ;
76
76
77
- if (temperature >= threshold -> temperature ) {
78
- if (threshold -> temperature > * low &&
79
- THERMAL_THRESHOLD_WAY_DOWN & threshold -> direction )
80
- * low = threshold -> temperature ;
77
+ list_for_each_entry (t , thresholds , list_node ) {
81
78
82
- if (last_temperature < threshold -> temperature &&
83
- threshold -> direction & direction )
84
- return true;
85
- } else {
86
- if (threshold -> temperature < * high && THERMAL_THRESHOLD_WAY_UP
87
- & threshold -> direction )
88
- * high = threshold -> temperature ;
79
+ if (!(t -> direction & THERMAL_THRESHOLD_WAY_UP ))
80
+ continue ;
89
81
90
- if (last_temperature >= threshold -> temperature &&
91
- threshold -> direction & direction )
82
+ if (temperature >= t -> temperature &&
83
+ last_temperature < t -> temperature )
92
84
return true;
93
85
}
94
86
95
87
return false;
96
88
}
97
89
98
- static bool thermal_thresholds_handle_raising (struct list_head * thresholds , int temperature ,
99
- int last_temperature , int * low , int * high )
90
+ static bool thermal_thresholds_handle_dropping (struct list_head * thresholds , int temperature ,
91
+ int last_temperature )
100
92
{
101
93
struct user_threshold * t ;
102
94
103
- list_for_each_entry (t , thresholds , list_node ) {
104
- if (__thermal_threshold_is_crossed (t , temperature , last_temperature ,
105
- THERMAL_THRESHOLD_WAY_UP , low , high ))
95
+ list_for_each_entry_reverse (t , thresholds , list_node ) {
96
+
97
+ if (!(t -> direction & THERMAL_THRESHOLD_WAY_DOWN ))
98
+ continue ;
99
+
100
+ if (temperature <= t -> temperature &&
101
+ last_temperature > t -> temperature )
106
102
return true;
107
103
}
108
104
109
105
return false;
110
106
}
111
107
112
- static bool thermal_thresholds_handle_dropping (struct list_head * thresholds , int temperature ,
113
- int last_temperature , int * low , int * high )
108
+ static void thermal_threshold_find_boundaries (struct list_head * thresholds , int temperature ,
109
+ int * low , int * high )
114
110
{
115
111
struct user_threshold * t ;
116
112
117
- list_for_each_entry_reverse (t , thresholds , list_node ) {
118
- if (__thermal_threshold_is_crossed (t , temperature , last_temperature ,
119
- THERMAL_THRESHOLD_WAY_DOWN , low , high ))
120
- return true;
113
+ list_for_each_entry (t , thresholds , list_node ) {
114
+ if (temperature < t -> temperature &&
115
+ (t -> direction & THERMAL_THRESHOLD_WAY_UP ) &&
116
+ * high > t -> temperature )
117
+ * high = t -> temperature ;
121
118
}
122
119
123
- return false;
120
+ list_for_each_entry_reverse (t , thresholds , list_node ) {
121
+ if (temperature > t -> temperature &&
122
+ (t -> direction & THERMAL_THRESHOLD_WAY_DOWN ) &&
123
+ * low < t -> temperature )
124
+ * low = t -> temperature ;
125
+ }
124
126
}
125
127
126
128
void thermal_thresholds_handle (struct thermal_zone_device * tz , int * low , int * high )
@@ -132,6 +134,8 @@ void thermal_thresholds_handle(struct thermal_zone_device *tz, int *low, int *hi
132
134
133
135
lockdep_assert_held (& tz -> lock );
134
136
137
+ thermal_threshold_find_boundaries (thresholds , temperature , low , high );
138
+
135
139
/*
136
140
* We need a second update in order to detect a threshold being crossed
137
141
*/
@@ -151,12 +155,12 @@ void thermal_thresholds_handle(struct thermal_zone_device *tz, int *low, int *hi
151
155
* - decreased : thresholds are crossed the way down
152
156
*/
153
157
if (temperature > last_temperature ) {
154
- if (thermal_thresholds_handle_raising (thresholds , temperature ,
155
- last_temperature , low , high ))
158
+ if (thermal_thresholds_handle_raising (thresholds ,
159
+ temperature , last_temperature ))
156
160
thermal_notify_threshold_up (tz );
157
161
} else {
158
- if (thermal_thresholds_handle_dropping (thresholds , temperature ,
159
- last_temperature , low , high ))
162
+ if (thermal_thresholds_handle_dropping (thresholds ,
163
+ temperature , last_temperature ))
160
164
thermal_notify_threshold_down (tz );
161
165
}
162
166
}
0 commit comments