diff options
author | Javier Martinez Canillas <javier@osg.samsung.com> | 2015-07-15 16:10:29 +0200 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2015-07-16 21:38:59 +0100 |
commit | 36a1f1b6ddc6d1442424e29548e790633ca39c7b (patch) | |
tree | 2b7bf7c9648986cfd7947d80e851a27dbdf7b247 /drivers | |
parent | e2c09ae7a74d94222187edbe8f5cf1fa9364efcd (diff) |
regulator: core: Fix memory leak in regulator_resolve_supply()
The regulator_resolve_supply() function calls set_supply() which in turn
calls create_regulator() to allocate a supply regulator.
If an error occurs after set_supply() succeeded, the allocated regulator
has to be freed before propagating the error code.
Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/regulator/core.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 934fde4faebe..80a123e8d0c3 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -109,6 +109,7 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev, static struct regulator *create_regulator(struct regulator_dev *rdev, struct device *dev, const char *supply_name); +static void _regulator_put(struct regulator *regulator); static const char *rdev_get_name(struct regulator_dev *rdev) { @@ -1401,8 +1402,11 @@ static int regulator_resolve_supply(struct regulator_dev *rdev) /* Cascade always-on state to supply */ if (_regulator_is_enabled(rdev)) { ret = regulator_enable(rdev->supply); - if (ret < 0) + if (ret < 0) { + if (rdev->supply) + _regulator_put(rdev->supply); return ret; + } } return 0; |