linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] thermal/core: fix error paths in __thermal_cooling_device_register()
@ 2023-01-12 15:47 Caleb Connolly
  2023-01-12 21:43 ` Luca Weiss
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Caleb Connolly @ 2023-01-12 15:47 UTC (permalink / raw)
  To: Amit Kucheria, Daniel Lezcano, Rafael J. Wysocki, Viresh Kumar,
	Zhang Rui
  Cc: Yang Yingliang, Caleb Connolly, linux-pm, Rafael J. Wysocki

There is in invalid call to thermal_cooling_device_destroy_sysfs() and
another to put_device() in the error paths here. Fix them.

Fixes: c408b3d1d9bb ("thermal: Validate new state in cur_state_store()")
Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
---
Changes since v2:
 * Rework and simplify into one patch following Yang's suggestions.

V2: https://lore.kernel.org/all/20230103171811.204196-1-caleb.connolly@linaro.org/
---
 drivers/thermal/thermal_core.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index f17ab2316dbd..321d2a6300c4 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -909,15 +909,16 @@ __thermal_cooling_device_register(struct device_node *np,
 	cdev->devdata = devdata;
 
 	ret = cdev->ops->get_max_state(cdev, &cdev->max_state);
-	if (ret)
-		goto out_kfree_type;
+	if (ret) {
+		kfree(cdev->type);
+		goto out_ida_remove;
+	}
 
 	thermal_cooling_device_setup_sysfs(cdev);
 	ret = dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
-	if (ret) {
-		thermal_cooling_device_destroy_sysfs(cdev);
+	if (ret)
 		goto out_kfree_type;
-	}
+
 	ret = device_register(&cdev->device);
 	if (ret)
 		goto out_kfree_type;
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-01-18  4:18 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-12 15:47 [PATCH v3] thermal/core: fix error paths in __thermal_cooling_device_register() Caleb Connolly
2023-01-12 21:43 ` Luca Weiss
2023-01-16  4:23 ` Viresh Kumar
2023-01-16 12:22   ` Caleb Connolly
2023-01-17  4:40     ` Viresh Kumar
2023-01-16 12:38   ` Yang Yingliang
2023-01-17  4:36     ` Viresh Kumar
2023-01-17 13:39       ` Rafael J. Wysocki
2023-01-17 18:11         ` Caleb Connolly
2023-01-18  4:18           ` Viresh Kumar
2023-01-16 12:52 ` Yang Yingliang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).