Skip to content

Commit

Permalink
regulator: s5m8767: Use DIV_ROUND_UP to calculate selector
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Axel Lin authored and Mark Brown committed Apr 23, 2012
1 parent b9b49af commit 94e85a3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/regulator/s5m8767.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 94e85a3

Please sign in to comment.