[PATCH v9 1/3] regulator: bq257xx: Clamp the BQ25703 OTG current limit to the hardware maximum
From: Alexey Charkov
Date: Mon Nov 02 2026 - 05:30:04 EST
The regulator core only clamps max_uA when the regulator node sets
regulator-max-microamp, so a consumer can request an arbitrarily large
limit. FIELD_PREP() then silently drops the bits above the 7-bit field, and
a large request programs a tiny limit while the rounding check still
passes on the unmasked value.
Clamp max_uA to the hardware maximum before converting it to a register
value, so that oversized requests program the highest available limit.
Fixes: 981dd162b635 ("regulator: bq257xx: Add bq257xx boost regulator driver")
Signed-off-by: Alexey Charkov <alchark@xxxxxxxxxxx>
---
drivers/regulator/bq257xx-regulator.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/regulator/bq257xx-regulator.c b/drivers/regulator/bq257xx-regulator.c
index 577b277efd7f..cf827faf48b7 100644
--- a/drivers/regulator/bq257xx-regulator.c
+++ b/drivers/regulator/bq257xx-regulator.c
@@ -45,7 +45,7 @@ static int bq25703_vbus_set_cur_limit(struct regulator_dev *rdev,
if ((min_uA > BQ25703_OTG_CUR_MAX_UA) || (max_uA < 0))
return -EINVAL;
- reg = (max_uA / BQ25703_OTG_CUR_STEP_UA);
+ reg = min(max_uA, BQ25703_OTG_CUR_MAX_UA) / BQ25703_OTG_CUR_STEP_UA;
/* Catch rounding errors since our step is 50000uA. */
if ((reg * BQ25703_OTG_CUR_STEP_UA) < min_uA)
--
2.56.0