regulator: core: Ensure simple linear voltage mappings falls within the specified...
authorAxel Lin <axel.lin@gmail.com>
Mon, 14 May 2012 02:33:37 +0000 (10:33 +0800)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Mon, 14 May 2012 08:11:34 +0000 (09:11 +0100)
Integer division may truncate the result.
Use DIV_ROUND_UP to ensure simple linear voltage mappings falls within the
specified range.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
drivers/regulator/core.c

index 5751f5ed47c0f5a780d6157d2251fe3e60fe10fc..8918271f9e85b20eff09e84398bc74b54645819d 100644 (file)
@@ -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;