Skip to contentSkip to conversation

Don't leak 'old_class_name' in drivers/base/core.c::device_rename()

PATCH In review Jesper Juhl 3 participants 3 messages Sep 28, 2006 – Sep 29, 2006 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Don't leak 'old_class_name' in drivers/base/core.c::device_rename()

If kmalloc() fails to allocate space for 'old_symlink_name' in drivers/base/core.c::device_rename(), then we'll leak 'old_class_name'.

Spotted by the Coverity checker.

---

 drivers/base/core.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/base/core.c +6 -3
@@ -805,8 +805,10 @@ int device_rename(struct device *dev, ch
 
 	if (dev->class) {
 		old_symlink_name = kmalloc(BUS_ID_SIZE, GFP_KERNEL);
-		if (!old_symlink_name)
-			return -ENOMEM;
+		if (!old_symlink_name) {
+			error = -ENOMEM;
+			goto out_free_old_class;
+		}
 		strlcpy(old_symlink_name, dev->bus_id, BUS_ID_SIZE);
 	}
 
@@ -830,9 +832,10 @@ int device_rename(struct device *dev, ch
 	}
 	put_device(dev);
 
-	kfree(old_class_name);
 	kfree(new_class_name);
 	kfree(old_symlink_name);
+ out_free_old_class:
+	kfree(old_class_name);
 
 	return error;
 }
#1 lore raw
Quoted 2 lines · Jesper Juhl

If kmalloc() fails to allocate space for 'old_symlink_name' in drivers/base/core.c::device_rename(), then we'll leak 'old_class_name'.

driver-core-fixes-check-for-return-value-of-sysfs_create_link.patch (in -mm) already fixes this (amongst other things).

Signature · 3 lines
Cornelia Huck
Linux for zSeries Developer
Tel.: +49-7031-16-4837, Mail: [email protected]
#2 lore raw
Quoted 9 lines · On Fri, 29 Sep 2006 10:13:27 +0200 Cornelia Huck <[email protected]>…
Quoted 2 lines · Jesper Juhl

If kmalloc() fails to allocate space for 'old_symlink_name' in drivers/base/core.c::device_rename(), then we'll leak 'old_class_name'.

driver-core-fixes-check-for-return-value-of-sysfs_create_link.patch (in -mm) already fixes this (amongst other things).

I noticed ;)

Greg, I fixed up the rejects this caued to driver-core-fixes-check-for-return-value-of-sysfs_create_link.patch so you might as well hang onto this patch. Will include Cornelia's patch in the next patch-bombing.