diff mbox series

ACPI: fan: cleanup resources in the error path of .probe()

Message ID 20241203033018.1023827-1-joe@pf.is.s.u-tokyo.ac.jp (mailing list archive)
State New
Headers show
Series ACPI: fan: cleanup resources in the error path of .probe() | expand

Commit Message

Joe Hattori Dec. 3, 2024, 3:30 a.m. UTC
Call thermal_cooling_device_unregister() and sysfs_remove_link() in the
error path of acpi_fan_probe() to fix possible memory leak.

Fixes: 05a83d972293 ("ACPI: register ACPI Fan as generic thermal cooling device")
Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
---
 drivers/acpi/fan_core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/acpi/fan_core.c b/drivers/acpi/fan_core.c
index 3ea9cfcff46e..8e3f62a3745e 100644
--- a/drivers/acpi/fan_core.c
+++ b/drivers/acpi/fan_core.c
@@ -379,11 +379,14 @@  static int acpi_fan_probe(struct platform_device *pdev)
 				   "device");
 	if (result) {
 		dev_err(&pdev->dev, "Failed to create sysfs link 'device'\n");
-		goto err_end;
+		goto err_unregister;
 	}
 
 	return 0;
 
+err_unregister:
+	sysfs_remove_link(&pdev->dev.kobj, "thermal_cooling");
+	thermal_cooling_device_unregister(cdev);
 err_end:
 	if (fan->acpi4)
 		acpi_fan_delete_attributes(device);