Skip to content

Commit

Permalink
regulator: core: if voltage scaling fails, restore original voltage v…
Browse files Browse the repository at this point in the history
…alues

Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
Tested-by: Robert Nelson <robertcnelson@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
  • Loading branch information
Paolo Pisati authored and Mark Brown committed Dec 15, 2012
1 parent 2959440 commit 92d7a55
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions drivers/regulator/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2250,6 +2250,7 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
{
struct regulator_dev *rdev = regulator->rdev;
int ret = 0;
int old_min_uV, old_max_uV;

mutex_lock(&rdev->mutex);

Expand All @@ -2271,18 +2272,29 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
ret = regulator_check_voltage(rdev, &min_uV, &max_uV);
if (ret < 0)
goto out;

/* restore original values in case of error */
old_min_uV = regulator->min_uV;
old_max_uV = regulator->max_uV;
regulator->min_uV = min_uV;
regulator->max_uV = max_uV;

ret = regulator_check_consumers(rdev, &min_uV, &max_uV);
if (ret < 0)
goto out;
goto out2;

ret = _regulator_do_set_voltage(rdev, min_uV, max_uV);

if (ret < 0)
goto out2;

out:
mutex_unlock(&rdev->mutex);
return ret;
out2:
regulator->min_uV = old_min_uV;
regulator->max_uV = old_max_uV;
mutex_unlock(&rdev->mutex);
return ret;
}
EXPORT_SYMBOL_GPL(regulator_set_voltage);

Expand Down

0 comments on commit 92d7a55

Please sign in to comment.