summaryrefslogtreecommitdiff
path: root/drivers/regulator/s5m8767.c
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@gmail.com>2012-04-13 05:30:05 +0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-04-23 16:18:10 +0400
commit94e85a3c5d702a4ce96b7a9b883c949a08ebd93c (patch)
tree96d4d9bcc1e06d67ba5eef89eb6f6ce976d6a274 /drivers/regulator/s5m8767.c
parentb9b49af5efa405f3c394a6395e79092c785999a3 (diff)
downloadlinux-94e85a3c5d702a4ce96b7a9b883c949a08ebd93c.tar.xz
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. Signed-off-by: Axel Lin <axel.lin@gmail.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator/s5m8767.c')
-rw-r--r--drivers/regulator/s5m8767.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c
index cb53187a60d3..ebe72d071b44 100644
--- a/drivers/regulator/s5m8767.c
+++ b/drivers/regulator/s5m8767.c
@@ -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;