Skip to content

Commit fa4f9c9

Browse files
committed
thermal: core: Consolidate thermal zone locking in the exit path
In analogy with a previous change in the thermal zone initialization path, to avoid acquiring the thermal zone lock and releasing it multiple times back and forth unnecessarily, move all of the code running under thermal_list_lock in thermal_zone_device_unregister() into a new function called thermal_zone_exit() and make the latter acquire the thermal zone lock only once and release it along with thermal_list_lock. For this purpose, provide an "unlocked" variant of thermal_zone_cdev_unbind() to be called by thermal_zone_exit() under the thermal zone lock. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <[email protected]> Link: https://patch.msgid.link/[email protected] Reviewed-by: Lukasz Luba <[email protected]>
1 parent 1dae3e7 commit fa4f9c9

File tree

1 file changed

+39
-27
lines changed

1 file changed

+39
-27
lines changed

drivers/thermal/thermal_core.c

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,15 +1268,21 @@ void thermal_cooling_device_update(struct thermal_cooling_device *cdev)
12681268
}
12691269
EXPORT_SYMBOL_GPL(thermal_cooling_device_update);
12701270

1271-
static void thermal_zone_cdev_unbind(struct thermal_zone_device *tz,
1272-
struct thermal_cooling_device *cdev)
1271+
static void __thermal_zone_cdev_unbind(struct thermal_zone_device *tz,
1272+
struct thermal_cooling_device *cdev)
12731273
{
12741274
struct thermal_trip_desc *td;
12751275

1276-
mutex_lock(&tz->lock);
1277-
12781276
for_each_trip_desc(tz, td)
12791277
thermal_unbind_cdev_from_trip(tz, &td->trip, cdev);
1278+
}
1279+
1280+
static void thermal_zone_cdev_unbind(struct thermal_zone_device *tz,
1281+
struct thermal_cooling_device *cdev)
1282+
{
1283+
mutex_lock(&tz->lock);
1284+
1285+
__thermal_zone_cdev_unbind(tz, cdev);
12801286

12811287
mutex_unlock(&tz->lock);
12821288
}
@@ -1596,43 +1602,49 @@ struct device *thermal_zone_device(struct thermal_zone_device *tzd)
15961602
}
15971603
EXPORT_SYMBOL_GPL(thermal_zone_device);
15981604

1599-
/**
1600-
* thermal_zone_device_unregister - removes the registered thermal zone device
1601-
* @tz: the thermal zone device to remove
1602-
*/
1603-
void thermal_zone_device_unregister(struct thermal_zone_device *tz)
1605+
static bool thermal_zone_exit(struct thermal_zone_device *tz)
16041606
{
16051607
struct thermal_cooling_device *cdev;
1606-
struct thermal_zone_device *pos = NULL;
1607-
1608-
if (!tz)
1609-
return;
1610-
1611-
thermal_debug_tz_remove(tz);
1608+
bool ret = true;
16121609

16131610
mutex_lock(&thermal_list_lock);
1614-
list_for_each_entry(pos, &thermal_tz_list, node)
1615-
if (pos == tz)
1616-
break;
1617-
if (pos != tz) {
1618-
/* thermal zone device not found */
1619-
mutex_unlock(&thermal_list_lock);
1620-
return;
1611+
1612+
if (list_empty(&tz->node)) {
1613+
ret = false;
1614+
goto unlock;
16211615
}
16221616

16231617
mutex_lock(&tz->lock);
16241618

16251619
tz->state |= TZ_STATE_FLAG_EXIT;
1626-
list_del(&tz->node);
1620+
list_del_init(&tz->node);
16271621

1628-
mutex_unlock(&tz->lock);
1629-
1630-
/* Unbind all cdevs associated with 'this' thermal zone */
1622+
/* Unbind all cdevs associated with this thermal zone. */
16311623
list_for_each_entry(cdev, &thermal_cdev_list, node)
1632-
thermal_zone_cdev_unbind(tz, cdev);
1624+
__thermal_zone_cdev_unbind(tz, cdev);
16331625

1626+
mutex_unlock(&tz->lock);
1627+
1628+
unlock:
16341629
mutex_unlock(&thermal_list_lock);
16351630

1631+
return ret;
1632+
}
1633+
1634+
/**
1635+
* thermal_zone_device_unregister - removes the registered thermal zone device
1636+
* @tz: the thermal zone device to remove
1637+
*/
1638+
void thermal_zone_device_unregister(struct thermal_zone_device *tz)
1639+
{
1640+
if (!tz)
1641+
return;
1642+
1643+
thermal_debug_tz_remove(tz);
1644+
1645+
if (!thermal_zone_exit(tz))
1646+
return;
1647+
16361648
cancel_delayed_work_sync(&tz->poll_queue);
16371649

16381650
thermal_set_governor(tz, NULL);

0 commit comments

Comments
 (0)