diff options
author | Paolo Pisati <paolo.pisati@canonical.com> | 2012-12-13 04:13:00 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-12-15 09:53:05 -0500 |
commit | 92d7a55879c01b30349045501108e775655a4b92 (patch) | |
tree | c4da55ecf4b8253483f238a036e7b1c3911d26b2 | |
parent | 29594404d7fe73cd80eaa4ee8c43dcc53970c60e (diff) |
regulator: core: if voltage scaling fails, restore original voltage values
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>
-rw-r--r-- | drivers/regulator/core.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index e872c8be080e..c347fd03b727 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
@@ -2250,6 +2250,7 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) | |||
2250 | { | 2250 | { |
2251 | struct regulator_dev *rdev = regulator->rdev; | 2251 | struct regulator_dev *rdev = regulator->rdev; |
2252 | int ret = 0; | 2252 | int ret = 0; |
2253 | int old_min_uV, old_max_uV; | ||
2253 | 2254 | ||
2254 | mutex_lock(&rdev->mutex); | 2255 | mutex_lock(&rdev->mutex); |
2255 | 2256 | ||
@@ -2271,18 +2272,29 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) | |||
2271 | ret = regulator_check_voltage(rdev, &min_uV, &max_uV); | 2272 | ret = regulator_check_voltage(rdev, &min_uV, &max_uV); |
2272 | if (ret < 0) | 2273 | if (ret < 0) |
2273 | goto out; | 2274 | goto out; |
2275 | |||
2276 | /* restore original values in case of error */ | ||
2277 | old_min_uV = regulator->min_uV; | ||
2278 | old_max_uV = regulator->max_uV; | ||
2274 | regulator->min_uV = min_uV; | 2279 | regulator->min_uV = min_uV; |
2275 | regulator->max_uV = max_uV; | 2280 | regulator->max_uV = max_uV; |
2276 | 2281 | ||
2277 | ret = regulator_check_consumers(rdev, &min_uV, &max_uV); | 2282 | ret = regulator_check_consumers(rdev, &min_uV, &max_uV); |
2278 | if (ret < 0) | 2283 | if (ret < 0) |
2279 | goto out; | 2284 | goto out2; |
2280 | 2285 | ||
2281 | ret = _regulator_do_set_voltage(rdev, min_uV, max_uV); | 2286 | ret = _regulator_do_set_voltage(rdev, min_uV, max_uV); |
2282 | 2287 | if (ret < 0) | |
2288 | goto out2; | ||
2289 | |||
2283 | out: | 2290 | out: |
2284 | mutex_unlock(&rdev->mutex); | 2291 | mutex_unlock(&rdev->mutex); |
2285 | return ret; | 2292 | return ret; |
2293 | out2: | ||
2294 | regulator->min_uV = old_min_uV; | ||
2295 | regulator->max_uV = old_max_uV; | ||
2296 | mutex_unlock(&rdev->mutex); | ||
2297 | return ret; | ||
2286 | } | 2298 | } |
2287 | EXPORT_SYMBOL_GPL(regulator_set_voltage); | 2299 | EXPORT_SYMBOL_GPL(regulator_set_voltage); |
2288 | 2300 | ||