Skip to content

Commit 6c54b7b

Browse files
vireshkrafaeljw
authored andcommitted
thermal: core: call put_device() only after device_register() fails
put_device() shouldn't be called before a prior call to device_register(). __thermal_cooling_device_register() doesn't follow that properly and needs fixing. Also thermal_cooling_device_destroy_sysfs() is getting called unnecessarily on few error paths. Fix all this by placing the calls at the right place. Based on initial work done by Caleb Connolly. Fixes: 4748f96 ("thermal: core: fix some possible name leaks in error paths") Fixes: c408b3d ("thermal: Validate new state in cur_state_store()") Reported-by: Caleb Connolly <[email protected]> Signed-off-by: Viresh Kumar <[email protected]> Tested-by: Frank Rowand <[email protected]> Reviewed-by: Yang Yingliang <[email protected]> Tested-by: Caleb Connolly <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 5dc4c99 commit 6c54b7b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

drivers/thermal/thermal_core.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -909,15 +909,20 @@ __thermal_cooling_device_register(struct device_node *np,
909909
cdev->devdata = devdata;
910910

911911
ret = cdev->ops->get_max_state(cdev, &cdev->max_state);
912-
if (ret)
913-
goto out_kfree_type;
912+
if (ret) {
913+
kfree(cdev->type);
914+
goto out_ida_remove;
915+
}
914916

915917
thermal_cooling_device_setup_sysfs(cdev);
918+
916919
ret = dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
917920
if (ret) {
921+
kfree(cdev->type);
918922
thermal_cooling_device_destroy_sysfs(cdev);
919-
goto out_kfree_type;
923+
goto out_ida_remove;
920924
}
925+
921926
ret = device_register(&cdev->device);
922927
if (ret)
923928
goto out_kfree_type;
@@ -943,6 +948,8 @@ __thermal_cooling_device_register(struct device_node *np,
943948
thermal_cooling_device_destroy_sysfs(cdev);
944949
kfree(cdev->type);
945950
put_device(&cdev->device);
951+
952+
/* thermal_release() takes care of the rest */
946953
cdev = NULL;
947954
out_ida_remove:
948955
ida_free(&thermal_cdev_ida, id);

0 commit comments

Comments
 (0)