[PATCH] regulator: core: Simplify error flow in _regulator_do_set_voltage()

From: Matthias Kaehlcke
Date: Wed Sep 14 2016 - 12:52:06 EST


If the voltage can not be set jump to the end of the function. This
avoids having to check for an error multiple times and eliminates one
level of nesting in a follow-up change.

Signed-off-by: Matthias Kaehlcke <mka@xxxxxxxxxxxx>
Signed-off-by: Mark Brown <broonie@xxxxxxxxxx>
---
drivers/regulator/core.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index b059e8334567..b0076ccf896b 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2800,8 +2800,11 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
ret = -EINVAL;
}

+ if (ret)
+ goto out;
+
/* Call set_voltage_time_sel if successfully obtained old_selector */
- if (ret == 0 && !rdev->constraints->ramp_disable && old_selector >= 0
+ if (!rdev->constraints->ramp_disable && old_selector >= 0
&& old_selector != selector) {

delay = ops->set_voltage_time_sel(rdev,
@@ -2821,13 +2824,14 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
}
}

- if (ret == 0 && best_val >= 0) {
+ if (best_val >= 0) {
unsigned long data = best_val;

_notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE,
(void *)data);
}

+out:
trace_regulator_set_voltage_complete(rdev_get_name(rdev), best_val);

return ret;
--
2.8.1