Skip to contentSkip to conversation

regulator: Fix off-by-one value range checking for mc13xxx_regulator_get_voltage

PATCH Applied Axel Lin 3 participants 3 messages May 18, 2011 – May 21, 2011 Voltage and current regulator framework

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 regulator: Fix off-by-one value range checking for mc13xxx_regulator_get_voltage

We use val as array index,
thus the valid value rangae for val should be 0 .. n_voltages-1.

---
 drivers/regulator/mc13xxx-regulator-core.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/regulator/mc13xxx-regulator-core.c +1 -1
index 2bb5de1..bc27ab1 100644
@@ -174,7 +174,7 @@ static int mc13xxx_regulator_get_voltage(struct regulator_dev *rdev)
 
 	dev_dbg(rdev_get_dev(rdev), "%s id: %d val: %d\n", __func__, id, val);
 
-	BUG_ON(val > mc13xxx_regulators[id].desc.n_voltages);
+	BUG_ON(val >= mc13xxx_regulators[id].desc.n_voltages);
 
 	return mc13xxx_regulators[id].voltages[val];
 }
Signature · 1 line
1.7.1
#2 lore raw
In reply to Axel Lin
Quoted 13 lines · Axel Lin

We use val as array index,
thus the valid value rangae for val should be 0 .. n_voltages-1.

---
 drivers/regulator/mc13xxx-regulator-core.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/regulator/mc13xxx-regulator-core.c +0 -0
index 2bb5de1..bc27ab1 100644

drivers/regulator/mc13xxx-regulator-core.c static int mc13xxx_regulator_get_voltage(struct regulator_dev *rdev) · line 180

Quoted 8 lines
drivers/regulator/mc13xxx-regulator-core.c +1 -1
@@ -174,7 +174,7 @@ static int mc13xxx_regulator_get_voltage(struct regulator_dev *rdev)
 
 	dev_dbg(rdev_get_dev(rdev), "%s id: %d val: %d\n", __func__, id, val);
 
-	BUG_ON(val > mc13xxx_regulators[id].desc.n_voltages);
+	BUG_ON(val >= mc13xxx_regulators[id].desc.n_voltages);
 
 	return mc13xxx_regulators[id].voltages[val];
 }

Applied

Thanks

Liam