Re: [PATCH RFC] regulator: core: fix constraints handling if current state out of range

From: Mark Brown

Date: Tue Nov 04 2025 - 08:54:12 EST


On Mon, Nov 03, 2025 at 08:32:41PM +0100, Andreas Kemnade wrote:

> - if (current_uV < rdev->constraints->min_uV) {
> + if ((current_uV < rdev->constraints->min_uV) ||
> + (current_uV > rdev->constraints->max_uV)) {
> target_min = rdev->constraints->min_uV;
> - target_max = rdev->constraints->min_uV;
> - }
> -
> - if (current_uV > rdev->constraints->max_uV) {
> - target_min = rdev->constraints->max_uV;
> target_max = rdev->constraints->max_uV;
> }

There's a valid issue here if we can't represent the exact constraint
(the hope was that people wouldn't specify constraints that their
hardware wasn't capable of representing but we can't exactly stop
them...) however this change is risky in the case where the voltage is
too high since if we specify a range from minimum to maximum we'll try
to select a voltage as close as possible to the minimum. That could
result in a large change if the range is wide, and potentially go under
the voltage the hardware needs for it's current configuration. We were
trying to set the highest voltage in the range to minimise the risk
there. This isn't a concern in the case where we're raising the
voltage.

Attachment: signature.asc
Description: PGP signature