Skip to contentSkip to conversation

regulator: core: Ensure simple linear voltage mappings falls within the specified range

PATCH Applied Axel Lin 2 participants 2 messages May 14, 2012 Voltage and current regulator framework

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 regulator: core: Ensure simple linear voltage mappings falls within the specified range

Integer division may truncate the result.
Use DIV_ROUND_UP to ensure simple linear voltage mappings falls within the specified range.

---
 drivers/regulator/core.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/regulator/core.c +1 -1
index 5751f5e..8918271 100644
@@ -2047,7 +2047,7 @@ int regulator_map_voltage_linear(struct regulator_dev *rdev,
 		return -EINVAL;
 	}
 
-	ret = (min_uV - rdev->desc->min_uV) / rdev->desc->uV_step;
+	ret = DIV_ROUND_UP(min_uV - rdev->desc->min_uV, rdev->desc->uV_step);
 	if (ret < 0)
 		return ret;
 
Signature · 1 line
1.7.5.4
Applied
#1 lore raw
Quoted 3 lines · Axel Lin

Integer division may truncate the result.
Use DIV_ROUND_UP to ensure simple linear voltage mappings falls within the specified range.

Applied, thanks.