Skip to contentSkip to conversation

regulator: da9052: Ensure setting current limit within specific range

PATCH Applied Axel Lin 2 participants 2 messages Nov 26, 2012 – Nov 27, 2012

Subsystems (2)
lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 regulator: da9052: Ensure setting current limit within specific range

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.

---
 drivers/regulator/da9052-regulator.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/regulator/da9052-regulator.c +5 -5
index d6fbfd3..d096309 100644
@@ -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
 	*/
Signature · 1 line
1.7.9.5
Applied
#1 lore raw
Quoted 2 lines · Axel Lin

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.

Applied, thanks.