Skip to contentSkip to conversation

regulator: s5m8767: Use DIV_ROUND_UP to calculate selector

PATCH Applied Axel Lin 2 participants 2 messages Apr 13, 2012 – Apr 23, 2012

Subsystems (2)
lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 regulator: s5m8767: Use DIV_ROUND_UP to calculate selector

Integer division may truncate the result.
Use DIV_ROUND_UP to ensure new voltage setting falls within specified range.

Also properly handle the case min_vol < desc->min to ensure we don't return negative value for selector.

---
 drivers/regulator/s5m8767.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
drivers/regulator/s5m8767.c +4 -1
index cb53187..ebe72d0 100644
@@ -347,7 +347,10 @@ static int s5m8767_convert_voltage_to_sel(
 	if (max_vol < desc->min || min_vol > desc->max)
 		return -EINVAL;
 
-	selector = (min_vol - desc->min) / desc->step;
+	if (min_vol < desc->min)
+		min_vol = desc->min;
+
+	selector = DIV_ROUND_UP(min_vol - desc->min, desc->step);
 
 	if (desc->min + desc->step * selector > max_vol)
 		return -EINVAL;
Signature · 1 line
1.7.5.4
Applied
#1 lore raw
Quoted 2 lines · Axel Lin

Integer division may truncate the result.
Use DIV_ROUND_UP to ensure new voltage setting falls within specified range.

Applied, thanks.