regulator core: fix double-free in regulator_register() error path
authorPaul Walmsley <paul@pwsan.com>
Sat, 25 Apr 2009 11:28:36 +0000 (05:28 -0600)
committerLiam Girdwood <lrg@slimlogic.co.uk>
Tue, 28 Apr 2009 17:58:07 +0000 (18:58 +0100)
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>
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
drivers/regulator/core.c

index cb62be63caed1b1729fb41825e2f069a1ab0e211..2f14c16f58c33cecda068ba0d912ac1863797b91 100644 (file)
@@ -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);