ACPI fan: fix memleak on acpi_fan_add_fs() failure
PATCH v2 1/1 ACPI fan: fix memleak on acpi_fan_add_fs() failure
Signed-off-by Alan Jenkins <[email protected]>
---
v2: Only remove sysfs links when the function fails.
drivers/acpi/fan.c | 20 ++++++++++++-------- 1 files changed, 12 insertions(+), 8 deletions(-)
drivers/acpi/fan.c +12 -8
@@ -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; }
Signature · 1 line
1.6.3.2