Skip to contentSkip to conversation

regulator: core: fix error path for regulator_set_voltage_unlocked

PATCH In review Steve Twiss 2 participants 3 messages Mar 18, 2019 Voltage and current regulator framework

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 regulator: core: fix error path for regulator_set_voltage_unlocked

During several error paths in the function regulator_set_voltage_unlocked() the value of 'ret' can take on negative error values. However, in calls that go through the 'goto out' statement, this return value is lost and return 0 is used instead, indicating a 'pass'.

There are several cases where this function should legitimately return a fail instead of a pass: one such case includes constraints check during voltage selection in the call to regulator_check_voltage(), which can have -EINVAL for the case when an unsupported voltage is incorrectly requested. In that case, -22 is expected as the return value, not 0.

Fixes 9243a195be7a ("regulator: core: Change voltage setting path")
Cc stable <[email protected]>
---
 drivers/regulator/core.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/regulator/core.c +4 -7
index 68473d0..968dcd9 100644
@@ -3322,15 +3322,12 @@ static int regulator_set_voltage_unlocked(struct regulator *regulator,
 
 	/* for not coupled regulators this will just set the voltage */
 	ret = regulator_balance_voltage(rdev, state);
-	if (ret < 0)
-		goto out2;
+	if (ret < 0) {
+		voltage->min_uV = old_min_uV;
+		voltage->max_uV = old_max_uV;
+	}
 
 out:
-	return 0;
-out2:
-	voltage->min_uV = old_min_uV;
-	voltage->max_uV = old_max_uV;
-
 	return ret;
 }
 
Signature · 1 line
1.9.3
Reviewed-by on v2 1/1
#1 lore raw

18.03.2019 19:17, Steve Twiss пишет:

Quoted 34 lines

During several error paths in the function regulator_set_voltage_unlocked() the value of 'ret' can take on negative error values. However, in calls that go through the 'goto out' statement, this return value is lost and return 0 is used instead, indicating a 'pass'.

There are several cases where this function should legitimately return a fail instead of a pass: one such case includes constraints check during voltage selection in the call to regulator_check_voltage(), which can have -EINVAL for the case when an unsupported voltage is incorrectly requested. In that case, -22 is expected as the return value, not 0.

Fixes 9243a195be7a ("regulator: core: Change voltage setting path")
Cc stable <[email protected]>
---
 drivers/regulator/core.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/regulator/core.c +4 -2
index 68473d0..968dcd9 100644
@@ -3322,15 +3322,12 @@ static int regulator_set_voltage_unlocked(struct regulator *regulator,
 
 	/* for not coupled regulators this will just set the voltage */
 	ret = regulator_balance_voltage(rdev, state);
-	if (ret < 0)
-		goto out2;
+	if (ret < 0) {
+		voltage->min_uV = old_min_uV;
+		voltage->max_uV = old_max_uV;
+	}

drivers/regulator/core.c static int regulator_set_voltage_unlocked(struct regulator *regulator, · line 3333

Quoted 10 lines
drivers/regulator/core.c +0 -5
 
 out:
-	return 0;
-out2:
-	voltage->min_uV = old_min_uV;
-	voltage->max_uV = old_max_uV;
-
 	return ret;
 }