Skip to contentSkip to conversation

power: pfuze100: Fix off by one error in voltage table handling

PATCH New Trent Piepho 1 participant 1 message Apr 4, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 power: pfuze100: Fix off by one error in voltage table handling

The code that sets a regulator by looking up the voltage in a table had an off by one error. vsel_mask is a bitmask, not the number of table entries, so a vsel_mask value of 0x7 indicates there are 8, not 7, entries in the table.

Cc Peng Fan <[email protected]>
Cc Jaehoon Chung <[email protected]>
---
 drivers/power/regulator/pfuze100.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/power/regulator/pfuze100.c +2 -2
index 99073d6018..d6d35f3a39 100644
@@ -482,11 +482,11 @@ static int pfuze100_regulator_val(struct udevice *dev, int op, int *uV)
 		debug("Set voltage for REGULATOR_TYPE_FIXED regulator\n");
 		return -EINVAL;
 	} else if (desc->volt_table) {
-		for (i = 0; i < desc->vsel_mask; i++) {
+		for (i = 0; i <= desc->vsel_mask; i++) {
 			if (*uV == desc->volt_table[i])
 				break;
 		}
-		if (i == desc->vsel_mask) {
+		if (i == desc->vsel_mask + 1) {
 			debug("Unsupported voltage %u\n", *uV);
 			return -EINVAL;
 		}
Signature · 1 line
2.14.5