@@ -124,7 +124,7 @@ int thermal_register_governor(struct thermal_governor *governor)
124124 if (!governor )
125125 return - EINVAL ;
126126
127- mutex_lock (& thermal_governor_lock );
127+ guard ( mutex ) (& thermal_governor_lock );
128128
129129 err = - EBUSY ;
130130 if (!__find_governor (governor -> name )) {
@@ -163,8 +163,6 @@ int thermal_register_governor(struct thermal_governor *governor)
163163 }
164164 }
165165
166- mutex_unlock (& thermal_governor_lock );
167-
168166 return err ;
169167}
170168
@@ -175,10 +173,10 @@ void thermal_unregister_governor(struct thermal_governor *governor)
175173 if (!governor )
176174 return ;
177175
178- mutex_lock (& thermal_governor_lock );
176+ guard ( mutex ) (& thermal_governor_lock );
179177
180178 if (!__find_governor (governor -> name ))
181- goto exit ;
179+ return ;
182180
183181 list_del (& governor -> governor_list );
184182
@@ -189,9 +187,6 @@ void thermal_unregister_governor(struct thermal_governor *governor)
189187 THERMAL_NAME_LENGTH ))
190188 thermal_set_governor (pos , NULL );
191189 }
192-
193- exit :
194- mutex_unlock (& thermal_governor_lock );
195190}
196191
197192int thermal_zone_device_set_policy (struct thermal_zone_device * tz ,
@@ -200,16 +195,13 @@ int thermal_zone_device_set_policy(struct thermal_zone_device *tz,
200195 struct thermal_governor * gov ;
201196 int ret = - EINVAL ;
202197
203- mutex_lock (& thermal_governor_lock );
204-
198+ guard (mutex )(& thermal_governor_lock );
205199 guard (thermal_zone )(tz );
206200
207201 gov = __find_governor (strim (policy ));
208202 if (gov )
209203 ret = thermal_set_governor (tz , gov );
210204
211- mutex_unlock (& thermal_governor_lock );
212-
213205 thermal_notify_tz_gov_change (tz , policy );
214206
215207 return ret ;
@@ -220,15 +212,13 @@ int thermal_build_list_of_policies(char *buf)
220212 struct thermal_governor * pos ;
221213 ssize_t count = 0 ;
222214
223- mutex_lock (& thermal_governor_lock );
215+ guard ( mutex ) (& thermal_governor_lock );
224216
225217 list_for_each_entry (pos , & thermal_governor_list , governor_list ) {
226218 count += sysfs_emit_at (buf , count , "%s " , pos -> name );
227219 }
228220 count += sysfs_emit_at (buf , count , "\n" );
229221
230- mutex_unlock (& thermal_governor_lock );
231-
232222 return count ;
233223}
234224
@@ -670,17 +660,18 @@ int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *),
670660 void * data )
671661{
672662 struct thermal_governor * gov ;
673- int ret = 0 ;
674663
675- mutex_lock (& thermal_governor_lock );
664+ guard (mutex )(& thermal_governor_lock );
665+
676666 list_for_each_entry (gov , & thermal_governor_list , governor_list ) {
667+ int ret ;
668+
677669 ret = cb (gov , data );
678670 if (ret )
679- break ;
671+ return ret ;
680672 }
681- mutex_unlock (& thermal_governor_lock );
682673
683- return ret ;
674+ return 0 ;
684675}
685676
686677int for_each_thermal_cooling_device (int (* cb )(struct thermal_cooling_device * ,
@@ -1348,20 +1339,15 @@ EXPORT_SYMBOL_GPL(thermal_zone_get_crit_temp);
13481339static int thermal_zone_init_governor (struct thermal_zone_device * tz )
13491340{
13501341 struct thermal_governor * governor ;
1351- int ret ;
13521342
1353- mutex_lock (& thermal_governor_lock );
1343+ guard ( mutex ) (& thermal_governor_lock );
13541344
13551345 if (tz -> tzp )
13561346 governor = __find_governor (tz -> tzp -> governor_name );
13571347 else
13581348 governor = def_governor ;
13591349
1360- ret = thermal_set_governor (tz , governor );
1361-
1362- mutex_unlock (& thermal_governor_lock );
1363-
1364- return ret ;
1350+ return thermal_set_governor (tz , governor );
13651351}
13661352
13671353static void thermal_zone_init_complete (struct thermal_zone_device * tz )
0 commit comments