drivers: regulator: fix set_voltage limits check

Only voltage ranges out of the allowed range have to be skipped.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2022-12-19 14:19:37 +01:00 committed by Fabio Baltieri
commit 8c6819120e

View file

@ -137,7 +137,7 @@ bool regulator_is_supported_voltage(const struct device *dev, int32_t min_uv,
unsigned int volt_cnt; unsigned int volt_cnt;
/* voltage may not be allowed, even if supported */ /* voltage may not be allowed, even if supported */
if ((min_uv < config->min_uv) || (max_uv > config->max_uv)) { if ((min_uv > config->max_uv) || (max_uv < config->min_uv)) {
return false; return false;
} }
@ -169,7 +169,7 @@ int regulator_set_voltage(const struct device *dev, int32_t min_uv,
} }
/* voltage may not be allowed, even if supported */ /* voltage may not be allowed, even if supported */
if ((min_uv < config->min_uv) || (max_uv > config->max_uv)) { if ((min_uv > config->max_uv) || (max_uv < config->min_uv)) {
return -EINVAL; return -EINVAL;
} }