diff mbox series

[v2,1/2] thermal/core: fix unbalanced put_device in register error path

Message ID 20230103171811.204196-1-caleb.connolly@linaro.org
State New
Headers show
Series [v2,1/2] thermal/core: fix unbalanced put_device in register error path | expand

Commit Message

Caleb Connolly Jan. 3, 2023, 5:18 p.m. UTC
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(-)
diff mbox series

Patch

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index f17ab2316dbd..2c6995b5dcb0 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -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);