Skip to contentSkip to conversation

thermal: core: Fix thermal zone device registration error path

PATCH In review Rafael J. Wysocki 2 participants 2 messages Apr 1 Thermal

lore
Share & tools
lore

Rafael J. Wysocki

author maintainer
#0 lore raw

PATCH 1/1 thermal: core: Fix thermal zone device registration error path

From: Rafael J. Wysocki <[email protected]>

If thermal_zone_device_register_with_trips() fails after registering a thermal zone device, it needs to wait for the tz->removal completion like thermal_zone_device_unregister(), in case user space has managed to take a reference to the thermal zone device's kobject, in which case thermal_release() may not be called by the error path itself and tz may be freed prematurely.

Add the missing wait_for_completion() call to the thermal zone device registration error path.

Fixes 04e6ccfc93c5 ("thermal: core: Fix NULL pointer dereference in zone registration error path")
Cc All applicable <[email protected]>
---
 drivers/thermal/thermal_core.c |    1 +
 1 file changed, 1 insertion(+)
drivers/thermal/thermal_core.c +1 -0
@@ -1651,6 +1651,7 @@ unregister:
 	device_del(&tz->device);
 release_device:
 	put_device(&tz->device);
+	wait_for_completion(&tz->removal);
 remove_id:
 	ida_free(&thermal_tz_ida, id);
 free_tzp:
reviewer Reviewed-by Tested-by on v1 1/1
#1 lore raw

Hi Rafael,

Quoted 25 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

If thermal_zone_device_register_with_trips() fails after registering a thermal zone device, it needs to wait for the tz->removal completion like thermal_zone_device_unregister(), in case user space has managed to take a reference to the thermal zone device's kobject, in which case thermal_release() may not be called by the error path itself and tz may be freed prematurely.

Add the missing wait_for_completion() call to the thermal zone device registration error path.

Fixes 04e6ccfc93c5 ("thermal: core: Fix NULL pointer dereference in zone registration error path")
Cc All applicable <[email protected]>
---
  drivers/thermal/thermal_core.c |    1 +
  1 file changed, 1 insertion(+)

drivers/thermal/thermal_core.c unregister: · line 1657

Quoted 7 lines
drivers/thermal/thermal_core.c +1 -0
@@ -1651,6 +1651,7 @@ unregister:
  	device_del(&tz->device);
  release_device:
  	put_device(&tz->device);
+	wait_for_completion(&tz->removal);
  remove_id:
  	ida_free(&thermal_tz_ida, id);
  free_tzp:

LGTM. I have also tested that code path with a faked failure from device_register() - the mechanism works.

Regards,
Lukasz