Skip to contentSkip to conversation

ACPI fan: fix memleak on acpi_fan_add_fs() failure

PATCH Superseded Alan Jenkins 2 participants 3 messages Sep 13, 2009 – Sep 14, 2009 ACPI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI fan: fix memleak on acpi_fan_add_fs() failure

---
 drivers/acpi/fan.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
drivers/acpi/fan.c +6 -2
index 947556e..eb1511e 100644
@@ -283,13 +283,17 @@ static int acpi_fan_add(struct acpi_device *device)
 
 	result = acpi_fan_add_fs(device);
 	if (result)
-		goto end;
+		goto unregister;
 
 	printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
 	       acpi_device_name(device), acpi_device_bid(device),
 	       !device->power.state ? "on" : "off");
 
-      end:
+unregister:
+	sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
+	sysfs_remove_link(&cdev->device.kobj, "device");
+	thermal_cooling_device_unregister(cdev);
+end:
 	return result;
 }
 
#1 lore raw
Quoted 1 line · Alan Jenkins

It sounds reasonable although we don't fail in calling the function of acpi_fan_add_fs.

Quoted 9 lines
---
 drivers/acpi/fan.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
drivers/acpi/fan.c +0 -0
index 947556e..eb1511e 100644

drivers/acpi/fan.c static int acpi_fan_add(struct acpi_device *device) · line 290

Quoted 9 lines
drivers/acpi/fan.c +1 -1
@@ -283,13 +283,17 @@ static int acpi_fan_add(struct acpi_device *device)
 
 	result = acpi_fan_add_fs(device);
 	if (result)
-		goto end;
+		goto unregister;
 
 	printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
 	       acpi_device_name(device), acpi_device_bid(device),
 	       !device->power.state ? "on" : "off");

At the same time we should return directly if the result is zero. But in this patch it seems that it will also remove the sysfs I/F link when the result is zero.

Thanks.

Quoted 15 lines
drivers/acpi/fan.c +5 -2
-      end:
+unregister:
+	sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
+	sysfs_remove_link(&cdev->device.kobj, "device");
+	thermal_cooling_device_unregister(cdev);
+end:
 	return result;
 }
 
 
--

To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 7 lines · ykzhao
Quoted 2 lines · Alan Jenkins

It sounds reasonable although we don't fail in calling the function of acpi_fan_add_fs.

Agreed, this applies to ENOMEM or other weird internal errors only.

Quoted 24 lines
Quoted 9 lines
---
 drivers/acpi/fan.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
drivers/acpi/fan.c +0 -0
index 947556e..eb1511e 100644

drivers/acpi/fan.c static int acpi_fan_add(struct acpi_device *device) · line 291

Quoted 10 lines
drivers/acpi/fan.c +1 -1
@@ -283,13 +283,17 @@ static int acpi_fan_add(struct acpi_device *device)
 
 	result = acpi_fan_add_fs(device);
 	if (result)
-		goto end;
+		goto unregister;
 
 	printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
 	       acpi_device_name(device), acpi_device_bid(device),
 	       !device->power.state ? "on" : "off");
 

At the same time we should return directly if the result is zero. But in this patch it seems that it will also remove the sysfs I/F link when the result is zero.

Quoted 2 lines

Thanks.

Eek, thanks for pointing this out. I'll send a fixed version Alan