Skip to content

Commit

Permalink
regulator: core: Fix memory leak in regulator_resolve_supply()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Javier Martinez Canillas authored and Mark Brown committed Jul 16, 2015
1 parent e2c09ae commit 36a1f1b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion drivers/regulator/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 36a1f1b

Please sign in to comment.