@@ -967,6 +967,20 @@ static void thermal_zone_cdev_bind(struct thermal_zone_device *tz,
967967 __thermal_zone_device_update (tz , THERMAL_EVENT_UNSPECIFIED );
968968}
969969
970+ static void thermal_cooling_device_init_complete (struct thermal_cooling_device * cdev )
971+ {
972+ struct thermal_zone_device * tz ;
973+
974+ mutex_lock (& thermal_list_lock );
975+
976+ list_add (& cdev -> node , & thermal_cdev_list );
977+
978+ list_for_each_entry (tz , & thermal_tz_list , node )
979+ thermal_zone_cdev_bind (tz , cdev );
980+
981+ mutex_unlock (& thermal_list_lock );
982+ }
983+
970984/**
971985 * __thermal_cooling_device_register() - register a new thermal cooling device
972986 * @np: a pointer to a device tree node.
@@ -989,7 +1003,6 @@ __thermal_cooling_device_register(struct device_node *np,
9891003 const struct thermal_cooling_device_ops * ops )
9901004{
9911005 struct thermal_cooling_device * cdev ;
992- struct thermal_zone_device * pos ;
9931006 unsigned long current_state ;
9941007 int id , ret ;
9951008
@@ -1056,16 +1069,7 @@ __thermal_cooling_device_register(struct device_node *np,
10561069 if (current_state <= cdev -> max_state )
10571070 thermal_debug_cdev_add (cdev , current_state );
10581071
1059- /* Add 'this' new cdev to the global cdev list */
1060- mutex_lock (& thermal_list_lock );
1061-
1062- list_add (& cdev -> node , & thermal_cdev_list );
1063-
1064- /* Update binding information for 'this' new cdev */
1065- list_for_each_entry (pos , & thermal_tz_list , node )
1066- thermal_zone_cdev_bind (pos , cdev );
1067-
1068- mutex_unlock (& thermal_list_lock );
1072+ thermal_cooling_device_init_complete (cdev );
10691073
10701074 return cdev ;
10711075
@@ -1276,38 +1280,42 @@ static void thermal_zone_cdev_unbind(struct thermal_zone_device *tz,
12761280 __thermal_zone_cdev_unbind (tz , cdev );
12771281}
12781282
1279- /**
1280- * thermal_cooling_device_unregister - removes a thermal cooling device
1281- * @cdev: the thermal cooling device to remove.
1282- *
1283- * thermal_cooling_device_unregister() must be called when a registered
1284- * thermal cooling device is no longer needed.
1285- */
1286- void thermal_cooling_device_unregister (struct thermal_cooling_device * cdev )
1283+ static bool thermal_cooling_device_exit (struct thermal_cooling_device * cdev )
12871284{
12881285 struct thermal_zone_device * tz ;
1289-
1290- if (!cdev )
1291- return ;
1292-
1293- thermal_debug_cdev_remove (cdev );
1286+ bool ret = true;
12941287
12951288 mutex_lock (& thermal_list_lock );
12961289
12971290 if (!thermal_cooling_device_present (cdev )) {
1298- mutex_unlock ( & thermal_list_lock ) ;
1299- return ;
1291+ ret = false ;
1292+ goto unlock ;
13001293 }
13011294
13021295 list_del (& cdev -> node );
13031296
1304- /* Unbind all thermal zones associated with 'this' cdev */
13051297 list_for_each_entry (tz , & thermal_tz_list , node )
13061298 thermal_zone_cdev_unbind (tz , cdev );
13071299
1300+ unlock :
13081301 mutex_unlock (& thermal_list_lock );
13091302
1310- device_unregister (& cdev -> device );
1303+ return ret ;
1304+ }
1305+
1306+ /**
1307+ * thermal_cooling_device_unregister() - removes a thermal cooling device
1308+ * @cdev: Thermal cooling device to remove.
1309+ */
1310+ void thermal_cooling_device_unregister (struct thermal_cooling_device * cdev )
1311+ {
1312+ if (!cdev )
1313+ return ;
1314+
1315+ thermal_debug_cdev_remove (cdev );
1316+
1317+ if (thermal_cooling_device_exit (cdev ))
1318+ device_unregister (& cdev -> device );
13111319}
13121320EXPORT_SYMBOL_GPL (thermal_cooling_device_unregister );
13131321
0 commit comments