Skip to content

Commit

Permalink
regulator: da9052: Ensure the selected voltage falls within the speci…
Browse files Browse the repository at this point in the history
…fied range

Integer division may truncate the result, use DIV_ROUND_UP to ensure the
selected voltage falls within the specified range.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
  • Loading branch information
AxelLin authored and broonie committed Mar 11, 2012
1 parent 7b95765 commit 9365121
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions drivers/regulator/da9052-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ static int da9052_regulator_set_voltage_int(struct regulator_dev *rdev,
if (min_uV < info->min_uV)
min_uV = info->min_uV;

*selector = (min_uV - info->min_uV) / info->step_uV;
*selector = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV);

ret = da9052_list_voltage(rdev, *selector);
if (ret < 0)
Expand Down Expand Up @@ -318,10 +318,10 @@ static int da9052_set_buckperi_voltage(struct regulator_dev *rdev, int min_uV,
if ((regulator->da9052->chip_id == DA9052) &&
(min_uV >= DA9052_CONST_3uV))
*selector = DA9052_BUCK_PERI_REG_MAP_UPTO_3uV +
((min_uV - DA9052_CONST_3uV) /
(DA9052_BUCK_PERI_3uV_STEP));
DIV_ROUND_UP(min_uV - DA9052_CONST_3uV,
DA9052_BUCK_PERI_3uV_STEP);
else
*selector = (min_uV - info->min_uV) / info->step_uV;
*selector = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV);

ret = da9052_list_buckperi_voltage(rdev, *selector);
if (ret < 0)
Expand Down

0 comments on commit 9365121

Please sign in to comment.