Commit 10dfd36f authored by Romain Gantois's avatar Romain Gantois Committed by Mark Brown
Browse files

regulator: core: correct convergence check in regulator_set_voltage()



The logic in regulator_set_voltage() which checks for a non-convergence
condition on a stepped regulator is flawed.

regulator_set_voltage() checks if the error in target voltage has increased
or decreased, and returns -EWOULDBLOCK if the error has not decreased
enough. The correct non-convergence condition is:

new_delta - delta > -rdev->constraints->max_uV_step

or equivalently:

delta - new_delta < rdev->constraints->max_uV_step

But the currently used condition is:

new_delta - delta > rdev->constraints->max_uV_step

Which may cause an infinite loop if the voltage error doesn't converge.

Fix this by correcting the convergence condition.

Suggested-by: default avatarJon Hunter <jonathanh@nvidia.com>
Fixes: d511206d ("regulator: core: repeat voltage setting request for stepped regulators")
Signed-off-by: default avatarRomain Gantois <romain.gantois@bootlin.com>
Link: https://patch.msgid.link/20250729-b4-regulator-stepping-fix-v1-1-3f7b8c55d7d7@bootlin.com


Tested-by: default avatarJon Hunter <jonathanh@nvidia.com>
Reviewed-by: default avatarJon Hunter <jonathanh@nvidia.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 0bd042ae
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3884,7 +3884,7 @@ static int regulator_set_voltage_unlocked(struct regulator *regulator,
			new_delta = ret;

			/* check that voltage is converging quickly enough */
			if (new_delta - delta > rdev->constraints->max_uV_step) {
			if (delta - new_delta < rdev->constraints->max_uV_step) {
				ret = -EWOULDBLOCK;
				goto out;
			}