public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] regulator core: fix double-free in regulator_register() error path
@ 2009-04-25 11:28 Paul Walmsley
  2009-04-25 22:11 ` David Brownell
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Paul Walmsley @ 2009-04-25 11:28 UTC (permalink / raw)
  To: lrg, broonie; +Cc: linux-kernel, linux-omap, dbrownell


During regulator registration, any error after device_register() will 
cause a double-free on the struct regulator_dev 'rdev'.  The bug is in 
drivers/regulator/core.c:regulator_register():

...
scrub:
	device_unregister(&rdev->dev);
clean:
	kfree(rdev);                           <---
	rdev = ERR_PTR(ret);
	goto out;
...

device_unregister() calls regulator_dev_release() which frees rdev.  The 
subsequent kfree corrupts memory and causes some OMAP3 systems to oops on 
boot in regulator_get().

Applies against 2.6.30-rc3.

Signed-off-by: Paul Walmsley <paul@pwsan.com>
---
 drivers/regulator/core.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 01f7702..fabd2e0 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2080,6 +2080,10 @@ out:
 
 scrub:
 	device_unregister(&rdev->dev);
+	/* device core frees rdev */
+	rdev = ERR_PTR(ret);
+	goto out;
+
 clean:
 	kfree(rdev);
 	rdev = ERR_PTR(ret);
-- 
1.6.3.rc1.51.gea0b7


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

end of thread, other threads:[~2009-04-28 12:47 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-25 11:28 [PATCH] regulator core: fix double-free in regulator_register() error path Paul Walmsley
2009-04-25 22:11 ` David Brownell
2009-04-26  4:53 ` Paul Walmsley
2009-04-28  3:08   ` David Brownell
2009-04-28  8:16     ` Mark Brown
2009-04-28  9:32       ` David Brownell
2009-04-28 11:00         ` Mark Brown
2009-04-28 11:47           ` David Brownell
2009-04-28 12:47             ` Mark Brown
2009-04-26  9:23 ` Mark Brown
2009-04-27 11:40 ` Liam Girdwood

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