mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] Don't leak 'old_class_name' in drivers/base/core.c::device_rename()
@ 2006-09-28 21:56 Jesper Juhl
  2006-09-29  8:13 ` Cornelia Huck
  0 siblings, 1 reply; 3+ messages in thread
From: Jesper Juhl @ 2006-09-28 21:56 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-kernel, Patrick Mochel, Patrick Mochel

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.


Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
---

 drivers/base/core.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

--- linux-2.6.18-git10-orig/drivers/base/core.c	2006-09-28 22:39:53.000000000 +0200
+++ linux-2.6.18-git10/drivers/base/core.c	2006-09-28 23:48:51.000000000 +0200
@@ -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;
 }


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Don't leak 'old_class_name' in drivers/base/core.c::device_rename()
  2006-09-28 21:56 [PATCH] Don't leak 'old_class_name' in drivers/base/core.c::device_rename() Jesper Juhl
@ 2006-09-29  8:13 ` Cornelia Huck
  2006-09-29  8:48   ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Cornelia Huck @ 2006-09-29  8:13 UTC (permalink / raw)
  To: Jesper Juhl
  Cc: Greg Kroah-Hartman, linux-kernel, Patrick Mochel, Patrick Mochel

On Thu, 28 Sep 2006 23:56:01 +0200,
Jesper Juhl <jesper.juhl@gmail.com> wrote:

> 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).

-- 
Cornelia Huck
Linux for zSeries Developer
Tel.: +49-7031-16-4837, Mail: cornelia.huck@de.ibm.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Don't leak 'old_class_name' in drivers/base/core.c::device_rename()
  2006-09-29  8:13 ` Cornelia Huck
@ 2006-09-29  8:48   ` Andrew Morton
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2006-09-29  8:48 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: Jesper Juhl, Greg Kroah-Hartman, linux-kernel, Patrick Mochel,
	Patrick Mochel

On Fri, 29 Sep 2006 10:13:27 +0200
Cornelia Huck <cornelia.huck@de.ibm.com> wrote:

> On Thu, 28 Sep 2006 23:56:01 +0200,
> Jesper Juhl <jesper.juhl@gmail.com> wrote:
> 
> > 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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-09-29  8:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-28 21:56 [PATCH] Don't leak 'old_class_name' in drivers/base/core.c::device_rename() Jesper Juhl
2006-09-29  8:13 ` Cornelia Huck
2006-09-29  8:48   ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome