Skip to content

Commit

Permalink
regulator: da9052: Ensure setting current limit within specific range
Browse files Browse the repository at this point in the history
Checking da9052_current_limits[row][i] <= max_uA is not enough, it is possible
da9052_current_limits[row][i] may less than the requested min_uA.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
  • Loading branch information
Axel Lin authored and Mark Brown committed Nov 27, 2012
1 parent 9489e9d commit 1e369bc
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions drivers/regulator/da9052-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,17 @@ static int da9052_dcdc_set_current_limit(struct regulator_dev *rdev, int min_uA,
else if (offset == 0)
row = 1;

if (min_uA > da9052_current_limits[row][DA9052_MAX_UA] ||
max_uA < da9052_current_limits[row][DA9052_MIN_UA])
return -EINVAL;

for (i = DA9052_CURRENT_RANGE - 1; i >= 0; i--) {
if (da9052_current_limits[row][i] <= max_uA) {
if ((min_uA <= da9052_current_limits[row][i]) &&
(da9052_current_limits[row][i] <= max_uA)) {
reg_val = i;
break;
}
}

if (i < 0)
return -EINVAL;

/* Determine the even or odd position of the buck current limit
* register field
*/
Expand Down

0 comments on commit 1e369bc

Please sign in to comment.