All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jon Hunter <jonathanh@nvidia.com>
To: Romain Gantois <romain.gantois@bootlin.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	linux-kernel@vger.kernel.org,
	"linux-tegra@vger.kernel.org" <linux-tegra@vger.kernel.org>
Subject: Re: [PATCH] regulator: core: correct convergence check in regulator_set_voltage()
Date: Tue, 29 Jul 2025 12:00:31 +0100	[thread overview]
Message-ID: <e563ac87-ffb4-4272-b8bf-ef673a0952a4@nvidia.com> (raw)
In-Reply-To: <20250729-b4-regulator-stepping-fix-v1-1-3f7b8c55d7d7@bootlin.com>


On 29/07/2025 10:50, Romain Gantois wrote:
> 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;
>   			}


Thanks for the quick fix!

Tested-by: Jon Hunter <jonathanh@nvidia.com>
Reviewed-by: Jon Hunter <jonathanh@nvidia.com>

Jon

-- 
nvpublic


  reply	other threads:[~2025-07-29 11:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-29  9:50 [PATCH] regulator: core: correct convergence check in regulator_set_voltage() Romain Gantois
2025-07-29 11:00 ` Jon Hunter [this message]
2025-07-29 16:52 ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e563ac87-ffb4-4272-b8bf-ef673a0952a4@nvidia.com \
    --to=jonathanh@nvidia.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=romain.gantois@bootlin.com \
    --cc=thomas.petazzoni@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.