Skip to content

Commit c92688c

Browse files
xdarklightbroonie
authored andcommitted
regulator: pwm-regulator: Add validity checks in continuous .get_voltage
Continuous regulators can be configured to operate only in a certain duty cycle range (for example from 0..91%). Add a check to error out if the duty cycle translates to an unsupported (or out of range) voltage. Suggested-by: Uwe Kleine-König <[email protected]> Signed-off-by: Martin Blumenstingl <[email protected]> Link: https://msgid.link/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 6613476 commit c92688c

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/regulator/pwm-regulator.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ static int pwm_regulator_get_voltage(struct regulator_dev *rdev)
158158
pwm_get_state(drvdata->pwm, &pstate);
159159

160160
voltage = pwm_get_relative_duty_cycle(&pstate, duty_unit);
161+
if (voltage < min(max_uV_duty, min_uV_duty) ||
162+
voltage > max(max_uV_duty, min_uV_duty))
163+
return -ENOTRECOVERABLE;
161164

162165
/*
163166
* The dutycycle for min_uV might be greater than the one for max_uV.

0 commit comments

Comments
 (0)