@@ -69,58 +69,60 @@ static struct user_threshold *__thermal_thresholds_find(const struct list_head *
6969 return NULL ;
7070}
7171
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 )
7574{
75+ struct user_threshold * t ;
7676
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 ) {
8178
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 ;
8981
90- if (last_temperature >= threshold -> temperature &&
91- threshold -> direction & direction )
82+ if (temperature >= t -> temperature &&
83+ last_temperature < t -> temperature )
9284 return true;
9385 }
9486
9587 return false;
9688}
9789
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 )
10092{
10193 struct user_threshold * t ;
10294
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 )
106102 return true;
107103 }
108104
109105 return false;
110106}
111107
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 )
114110{
115111 struct user_threshold * t ;
116112
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 ;
121118 }
122119
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+ }
124126}
125127
126128void 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
132134
133135 lockdep_assert_held (& tz -> lock );
134136
137+ thermal_threshold_find_boundaries (thresholds , temperature , low , high );
138+
135139 /*
136140 * We need a second update in order to detect a threshold being crossed
137141 */
@@ -151,12 +155,12 @@ void thermal_thresholds_handle(struct thermal_zone_device *tz, int *low, int *hi
151155 * - decreased : thresholds are crossed the way down
152156 */
153157 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 ))
156160 thermal_notify_threshold_up (tz );
157161 } 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 ))
160164 thermal_notify_threshold_down (tz );
161165 }
162166}
0 commit comments