Skip to content

Commit b778b4d

Browse files
groeckrafaeljw
authored andcommitted
thermal/core: Protect thermal device operations against thermal device removal
Thermal device operations may be called after thermal zone device removal. After thermal zone device removal, thermal zone device operations must no longer be called. To prevent such calls from happening, ensure that the thermal device is registered before executing any thermal device operations. Signed-off-by: Guenter Roeck <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 91b3aaf commit b778b4d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

drivers/thermal/thermal_core.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ int thermal_zone_device_set_policy(struct thermal_zone_device *tz,
203203
mutex_lock(&thermal_governor_lock);
204204
mutex_lock(&tz->lock);
205205

206+
if (!device_is_registered(&tz->device))
207+
goto exit;
208+
206209
gov = __find_governor(strim(policy));
207210
if (!gov)
208211
goto exit;
@@ -445,6 +448,12 @@ static int thermal_zone_device_set_mode(struct thermal_zone_device *tz,
445448
return ret;
446449
}
447450

451+
if (!device_is_registered(&tz->device)) {
452+
mutex_unlock(&tz->lock);
453+
454+
return -ENODEV;
455+
}
456+
448457
if (tz->ops->change_mode)
449458
ret = tz->ops->change_mode(tz, mode);
450459

@@ -486,7 +495,8 @@ void thermal_zone_device_update(struct thermal_zone_device *tz,
486495
enum thermal_notify_event event)
487496
{
488497
mutex_lock(&tz->lock);
489-
__thermal_zone_device_update(tz, event);
498+
if (device_is_registered(&tz->device))
499+
__thermal_zone_device_update(tz, event);
490500
mutex_unlock(&tz->lock);
491501
}
492502
EXPORT_SYMBOL_GPL(thermal_zone_device_update);

0 commit comments

Comments
 (0)