@@ -920,7 +920,7 @@ __thermal_cooling_device_register(struct device_node *np,
}
ret = device_register(&cdev->device);
if (ret)
- goto out_kfree_type;
+ goto out_put_device;
/* Add 'this' new cdev to the global cdev list */
mutex_lock(&thermal_list_lock);
@@ -939,10 +939,11 @@ __thermal_cooling_device_register(struct device_node *np,
return cdev;
+out_put_device:
+ put_device(&cdev->device);
out_kfree_type:
thermal_cooling_device_destroy_sysfs(cdev);
kfree(cdev->type);
- put_device(&cdev->device);
cdev = NULL;
out_ida_remove:
ida_free(&thermal_cdev_ida, id);
Commit c408b3d1d9bb ("thermal: Validate new state in cur_state_store()") causes device_put() to be called if the get_max_state() callback fails during __thermal_cooling_device_register(). Fix the cleanup ordering to only call device_put() if initialization fails after the matching device_register() call. Fixes: c408b3d1d9bb ("thermal: Validate new state in cur_state_store()") Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org> --- Changes since v1: * Add second patch. V1: https://lore.kernel.org/all/20221231210301.6968-1-caleb.connolly@linaro.org/ --- drivers/thermal/thermal_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)