All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] regulator: core: correct convergence check in regulator_set_voltage()
@ 2025-07-29  9:50 Romain Gantois
  2025-07-29 11:00 ` Jon Hunter
  2025-07-29 16:52 ` Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: Romain Gantois @ 2025-07-29  9:50 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown
  Cc: Thomas Petazzoni, linux-kernel, Jon Hunter, Romain Gantois

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: Jon Hunter <jonathanh@nvidia.com>
Fixes: d511206dc7443 ("regulator: core: repeat voltage setting request for stepped regulators")
Signed-off-by: Romain Gantois <romain.gantois@bootlin.com>
---
 drivers/regulator/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 8ed9b96518cf5186c0db147a6895a92bc59fae4e..554d83c4af0c1c98edb43b60dbfacb8844d5e1eb 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -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;
 			}

---
base-commit: 0bd042ae771d61ef7ccd5882f7aeca59a25f71d9
change-id: 20250729-b4-regulator-stepping-fix-6e23fe03e914

Best regards,
-- 
Romain Gantois <romain.gantois@bootlin.com>


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-07-29 16:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-29  9:50 [PATCH] regulator: core: correct convergence check in regulator_set_voltage() Romain Gantois
2025-07-29 11:00 ` Jon Hunter
2025-07-29 16:52 ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.