Skip to content

Commit

Permalink
regulator core: fix double-free in regulator_register() error path
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Paul Walmsley authored and Liam Girdwood committed Apr 28, 2009
1 parent cd78dfc commit 53032da
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/regulator/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2080,6 +2080,10 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,

scrub:
device_unregister(&rdev->dev);
/* device core frees rdev */
rdev = ERR_PTR(ret);
goto out;

clean:
kfree(rdev);
rdev = ERR_PTR(ret);
Expand Down

0 comments on commit 53032da

Please sign in to comment.