Skip to content

Commit d07700b

Browse files
committed
thermal: core: Consolidate thermal zone locking during initialization
The part of thermal zone initialization carried out under thermal_list_lock acquires the thermal zone lock and releases it multiple times back and forth which is not really necessary. Instead of doing this, make it acquire the thermal zone lock once after acquiring thermal_list_lock and release it along with that lock. For this purpose, move all of the code in question to thermal_zone_init_complete() introduced previously and provide an "unlocked" variant of thermal_zone_cdev_bind() to be invoked from there. Also notice that a thermal zone does not need to be added to thermal_tz_list under its own lock, so make the new code acquire the thermal zone lock after adding it to the list. 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]> [ rjw: Rebase on top of recent thermal core changes ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent cdf771a commit d07700b

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

drivers/thermal/thermal_core.c

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -935,16 +935,14 @@ void print_bind_err_msg(struct thermal_zone_device *tz,
935935
cdev->type, thermal_zone_trip_id(tz, trip), ret);
936936
}
937937

938-
static void thermal_zone_cdev_bind(struct thermal_zone_device *tz,
939-
struct thermal_cooling_device *cdev)
938+
static void __thermal_zone_cdev_bind(struct thermal_zone_device *tz,
939+
struct thermal_cooling_device *cdev)
940940
{
941941
struct thermal_trip_desc *td;
942942

943943
if (!tz->ops.should_bind)
944944
return;
945945

946-
mutex_lock(&tz->lock);
947-
948946
for_each_trip_desc(tz, td) {
949947
struct thermal_trip *trip = &td->trip;
950948
struct cooling_spec c = {
@@ -961,6 +959,14 @@ static void thermal_zone_cdev_bind(struct thermal_zone_device *tz,
961959
if (ret)
962960
print_bind_err_msg(tz, trip, cdev, ret);
963961
}
962+
}
963+
964+
static void thermal_zone_cdev_bind(struct thermal_zone_device *tz,
965+
struct thermal_cooling_device *cdev)
966+
{
967+
mutex_lock(&tz->lock);
968+
969+
__thermal_zone_cdev_bind(tz, cdev);
964970

965971
mutex_unlock(&tz->lock);
966972
}
@@ -1338,8 +1344,18 @@ EXPORT_SYMBOL_GPL(thermal_zone_get_crit_temp);
13381344

13391345
static void thermal_zone_init_complete(struct thermal_zone_device *tz)
13401346
{
1347+
struct thermal_cooling_device *cdev;
1348+
1349+
mutex_lock(&thermal_list_lock);
1350+
1351+
list_add_tail(&tz->node, &thermal_tz_list);
1352+
13411353
mutex_lock(&tz->lock);
13421354

1355+
/* Bind cooling devices for this zone. */
1356+
list_for_each_entry(cdev, &thermal_cdev_list, node)
1357+
__thermal_zone_cdev_bind(tz, cdev);
1358+
13431359
tz->state &= ~TZ_STATE_FLAG_INIT;
13441360
/*
13451361
* If system suspend or resume is in progress at this point, the
@@ -1352,6 +1368,8 @@ static void thermal_zone_init_complete(struct thermal_zone_device *tz)
13521368
__thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
13531369

13541370
mutex_unlock(&tz->lock);
1371+
1372+
mutex_unlock(&thermal_list_lock);
13551373
}
13561374

13571375
/**
@@ -1388,7 +1406,6 @@ thermal_zone_device_register_with_trips(const char *type,
13881406
unsigned int polling_delay)
13891407
{
13901408
const struct thermal_trip *trip = trips;
1391-
struct thermal_cooling_device *cdev;
13921409
struct thermal_zone_device *tz;
13931410
struct thermal_trip_desc *td;
13941411
int id;
@@ -1520,20 +1537,8 @@ thermal_zone_device_register_with_trips(const char *type,
15201537
if (result)
15211538
goto remove_hwmon;
15221539

1523-
mutex_lock(&thermal_list_lock);
1524-
1525-
mutex_lock(&tz->lock);
1526-
list_add_tail(&tz->node, &thermal_tz_list);
1527-
mutex_unlock(&tz->lock);
1528-
1529-
/* Bind cooling devices for this zone */
1530-
list_for_each_entry(cdev, &thermal_cdev_list, node)
1531-
thermal_zone_cdev_bind(tz, cdev);
1532-
15331540
thermal_zone_init_complete(tz);
15341541

1535-
mutex_unlock(&thermal_list_lock);
1536-
15371542
thermal_notify_tz_create(tz);
15381543

15391544
thermal_debug_tz_add(tz);

0 commit comments

Comments
 (0)