Skip to content

Commit 1c439de

Browse files
groeckrafaeljw
authored andcommitted
thermal/core: Introduce locked version of thermal_zone_device_update
In thermal_zone_device_set_mode(), the thermal zone mutex is released only to be reacquired in the subsequent call to thermal_zone_device_update(). Introduce __thermal_zone_device_update(), which is similar to thermal_zone_device_update() but has to be called with the thermal device mutex held. Call the new function from thermal_zone_device_set_mode() to avoid the extra thermal device mutex release/acquire sequence in that function. With the new function in place, re-implement thermal_zone_device_update() as wrapper around __thermal_zone_device_update() to acquire and release the thermal device mutex. Signed-off-by: Guenter Roeck <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent ed97d10 commit 1c439de

File tree

1 file changed

+31
-26
lines changed

1 file changed

+31
-26
lines changed

drivers/thermal/thermal_core.c

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,34 @@ static void thermal_zone_device_init(struct thermal_zone_device *tz)
403403
pos->initialized = false;
404404
}
405405

406+
static void __thermal_zone_device_update(struct thermal_zone_device *tz,
407+
enum thermal_notify_event event)
408+
{
409+
int count;
410+
411+
if (atomic_read(&in_suspend))
412+
return;
413+
414+
if (WARN_ONCE(!tz->ops->get_temp,
415+
"'%s' must not be called without 'get_temp' ops set\n",
416+
__func__))
417+
return;
418+
419+
if (!thermal_zone_device_is_enabled(tz))
420+
return;
421+
422+
update_temperature(tz);
423+
424+
__thermal_zone_set_trips(tz);
425+
426+
tz->notify_event = event;
427+
428+
for (count = 0; count < tz->num_trips; count++)
429+
handle_thermal_trip(tz, count);
430+
431+
monitor_thermal_zone(tz);
432+
}
433+
406434
static int thermal_zone_device_set_mode(struct thermal_zone_device *tz,
407435
enum thermal_device_mode mode)
408436
{
@@ -423,9 +451,9 @@ static int thermal_zone_device_set_mode(struct thermal_zone_device *tz,
423451
if (!ret)
424452
tz->mode = mode;
425453

426-
mutex_unlock(&tz->lock);
454+
__thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
427455

428-
thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
456+
mutex_unlock(&tz->lock);
429457

430458
if (mode == THERMAL_DEVICE_ENABLED)
431459
thermal_notify_tz_enable(tz->id);
@@ -457,31 +485,8 @@ int thermal_zone_device_is_enabled(struct thermal_zone_device *tz)
457485
void thermal_zone_device_update(struct thermal_zone_device *tz,
458486
enum thermal_notify_event event)
459487
{
460-
int count;
461-
462-
if (atomic_read(&in_suspend))
463-
return;
464-
465-
if (WARN_ONCE(!tz->ops->get_temp, "'%s' must not be called without "
466-
"'get_temp' ops set\n", __func__))
467-
return;
468-
469488
mutex_lock(&tz->lock);
470-
471-
if (!thermal_zone_device_is_enabled(tz))
472-
goto out;
473-
474-
update_temperature(tz);
475-
476-
__thermal_zone_set_trips(tz);
477-
478-
tz->notify_event = event;
479-
480-
for (count = 0; count < tz->num_trips; count++)
481-
handle_thermal_trip(tz, count);
482-
483-
monitor_thermal_zone(tz);
484-
out:
489+
__thermal_zone_device_update(tz, event);
485490
mutex_unlock(&tz->lock);
486491
}
487492
EXPORT_SYMBOL_GPL(thermal_zone_device_update);

0 commit comments

Comments
 (0)