Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <stable@vger.kernel.org>
Signed-off-by: Steve Twiss <stwiss.opensource@diasemi.com>
Reviewed-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Steve Twiss and committed by
Mark Brown
70b46491 e5680c4d

+4 -7
+4 -7
drivers/regulator/core.c
··· 3322 3322 3323 3323 /* for not coupled regulators this will just set the voltage */ 3324 3324 ret = regulator_balance_voltage(rdev, state); 3325 - if (ret < 0) 3326 - goto out2; 3325 + if (ret < 0) { 3326 + voltage->min_uV = old_min_uV; 3327 + voltage->max_uV = old_max_uV; 3328 + } 3327 3329 3328 3330 out: 3329 - return 0; 3330 - out2: 3331 - voltage->min_uV = old_min_uV; 3332 - voltage->max_uV = old_max_uV; 3333 - 3334 3331 return ret; 3335 3332 } 3336 3333