diff mbox

[PATCHv2] ACPI fan: fix memleak on acpi_fan_add_fs() failure

Message ID 4AADF5B0.1040400@tuffmail.co.uk (mailing list archive)
State RFC, archived
Headers show

Commit Message

Alan Jenkins Sept. 14, 2009, 7:50 a.m. UTC
Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
---
v2: Only remove sysfs links when the function fails.

 drivers/acpi/fan.c |   20 ++++++++++++--------
 1 files changed, 12 insertions(+), 8 deletions(-)
diff mbox

Patch

diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
index 947556e..6b110c7 100644
--- a/drivers/acpi/fan.c
+++ b/drivers/acpi/fan.c
@@ -249,8 +249,8 @@  static int acpi_fan_add(struct acpi_device *device)
 
 	result = acpi_bus_get_power(device->handle, &state);
 	if (result) {
-		printk(KERN_ERR PREFIX "Reading power state\n");
-		goto end;
+		printk(KERN_ERR PREFIX "Error reading power state\n");
+		return result;
 	}
 
 	device->flags.force_power_state = 1;
@@ -259,10 +259,8 @@  static int acpi_fan_add(struct acpi_device *device)
 
 	cdev = thermal_cooling_device_register("Fan", device,
 						&fan_cooling_ops);
-	if (IS_ERR(cdev)) {
-		result = PTR_ERR(cdev);
-		goto end;
-	}
+	if (IS_ERR(cdev))
+		return PTR_ERR(cdev);
 
 	dev_info(&device->dev, "registered as cooling_device%d\n", cdev->id);
 
@@ -283,13 +281,19 @@  static int acpi_fan_add(struct acpi_device *device)
 
 	result = acpi_fan_add_fs(device);
 	if (result)
-		goto end;
+		goto err_unregister;
 
 	printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
 	       acpi_device_name(device), acpi_device_bid(device),
 	       !device->power.state ? "on" : "off");
 
-      end:
+	return 0;
+
+err_unregister:
+	sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
+	sysfs_remove_link(&cdev->device.kobj, "device");
+	thermal_cooling_device_unregister(cdev);
+
 	return result;
 }