Skip to content

Commit

Permalink
regulator: core: Allow fixed voltage range in multiple linear ranges
Browse files Browse the repository at this point in the history
Current code does not allow fixed voltage range in multiple linear ranges.
If someone does set range->uV_step == 0 in one of the linear ranges, we hit
divided by zero bug. This patch fixes this issue.
For fixed voltage range, return any selector means the same voltage.
Thus just return 0.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
  • Loading branch information
Axel Lin authored and Mark Brown committed Jul 18, 2013
1 parent c36a1cd commit a56d66a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions drivers/regulator/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2436,9 +2436,15 @@ int regulator_map_voltage_linear_range(struct regulator_dev *rdev,
if (min_uV <= range->min_uV)
min_uV = range->min_uV;

ret = DIV_ROUND_UP(min_uV - range->min_uV, range->uV_step);
if (ret < 0)
return ret;
/* range->uV_step == 0 means fixed voltage range */
if (range->uV_step == 0) {
ret = 0;
} else {
ret = DIV_ROUND_UP(min_uV - range->min_uV,
range->uV_step);
if (ret < 0)
return ret;
}

break;
}
Expand Down

0 comments on commit a56d66a

Please sign in to comment.