public inbox for linuxppc-dev@ozlabs.org 
 help / color / mirror / Atom feed
* [patch] powerpc/ps3: Fix memory leak in device init
@ 2008-10-30 18:17 Geoff Levand
  0 siblings, 0 replies; only message in thread
From: Geoff Levand @ 2008-10-30 18:17 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linuxppc-dev


From: Masakazu Mokuno <mokuno@sm•sony.co.jp>

Free dynamically allocated device data structures when device registration
fails.  This fixes memory leakage when the registration fails.

Signed-off-by: Masakazu Mokuno <mokuno@sm•sony.co.jp>
Signed-off-by: Geoff Levand <geoffrey.levand@am•sony.com>
---
 arch/powerpc/platforms/ps3/device-init.c |   29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

--- a/arch/powerpc/platforms/ps3/device-init.c
+++ b/arch/powerpc/platforms/ps3/device-init.c
@@ -314,11 +314,17 @@ static int __init ps3_setup_vuart_device
 
 	result = ps3_system_bus_device_register(&p->dev);
 
-	if (result)
+	if (result) {
 		pr_debug("%s:%d ps3_system_bus_device_register failed\n",
 			__func__, __LINE__);
-
+		goto fail_device_register;
+	}
 	pr_debug(" <- %s:%d\n", __func__, __LINE__);
+	return 0;
+
+fail_device_register:
+	kfree(p);
+	pr_debug(" <- %s:%d fail\n", __func__, __LINE__);
 	return result;
 }
 
@@ -463,11 +469,17 @@ static int __init ps3_register_sound_dev
 
 	result = ps3_system_bus_device_register(&p->dev);
 
-	if (result)
+	if (result) {
 		pr_debug("%s:%d ps3_system_bus_device_register failed\n",
 			__func__, __LINE__);
-
+		goto fail_device_register;
+	}
 	pr_debug(" <- %s:%d\n", __func__, __LINE__);
+	return 0;
+
+fail_device_register:
+	kfree(p);
+	pr_debug(" <- %s:%d failed\n", __func__, __LINE__);
 	return result;
 }
 
@@ -491,11 +503,18 @@ static int __init ps3_register_graphics_
 
 	result = ps3_system_bus_device_register(&p->dev);
 
-	if (result)
+	if (result) {
 		pr_debug("%s:%d ps3_system_bus_device_register failed\n",
 			__func__, __LINE__);
+		goto fail_device_register;
+	}
 
 	pr_debug(" <- %s:%d\n", __func__, __LINE__);
+	return 0;
+
+fail_device_register:
+	kfree(p);
+	pr_debug(" <- %s:%d failed\n", __func__, __LINE__);
 	return result;
 }
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-10-30 18:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-30 18:17 [patch] powerpc/ps3: Fix memory leak in device init Geoff Levand

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