Skip to contentSkip to conversation

ab3100: fix off-by-one value range checking for voltage selector

PATCH Superseded Axel Lin 2 participants 2 messages Jul 26, 2010 Voltage and current regulator framework

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 ab3100: fix off-by-one value range checking for voltage selector

The valid typ_voltages range should be 0..voltages_len-1.

---
 drivers/regulator/ab3100.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/regulator/ab3100.c +2 -2
index 7b14a67..1179099 100644
@@ -286,7 +286,7 @@ static int ab3100_list_voltage_regulator(struct regulator_dev *reg,
 {
 	struct ab3100_regulator *abreg = reg->reg_data;
 
-	if (selector > abreg->voltages_len)
+	if (selector >= abreg->voltages_len)
 		return -EINVAL;
 	return abreg->typ_voltages[selector];
 }
@@ -318,7 +318,7 @@ static int ab3100_get_voltage_regulator(struct regulator_dev *reg)
 	regval &= 0xE0;
 	regval >>= 5;
 
-	if (regval > abreg->voltages_len) {
+	if (regval >= abreg->voltages_len) {
 		dev_err(&reg->dev,
 			"regulator register %02x contains an illegal voltage setting\n",
 			abreg->regreg);
Signature · 1 line
1.5.4.3
Acked-by on v1 1/1
#1 lore raw
Quoted 3 lines · Axel Lin

The valid typ_voltages range should be 0..voltages_len-1.

It'd be nice to include a few extra words in the change log explaining that the reason for the limit is that it's an array index.

Quoted 31 lines

---
drivers/regulator/ab3100.c | 4 ++--

1 files changed, 2 insertions(+), 2 deletions(-)
drivers/regulator/ab3100.c +2 -2
index 7b14a67..1179099 100644
@@ -286,7 +286,7 @@ static int ab3100_list_voltage_regulator(struct regulator_dev *reg,
 {
 	struct ab3100_regulator *abreg = reg->reg_data;
 
-	if (selector > abreg->voltages_len)
+	if (selector >= abreg->voltages_len)
 		return -EINVAL;
 	return abreg->typ_voltages[selector];
 }
@@ -318,7 +318,7 @@ static int ab3100_get_voltage_regulator(struct regulator_dev *reg)
 	regval &= 0xE0;
 	regval >>= 5;
 
-	if (regval > abreg->voltages_len) {
+	if (regval >= abreg->voltages_len) {
 		dev_err(&reg->dev,
 			"regulator register %02x contains an illegal voltage setting\n",
 			abreg->regreg);
Signature · 1 line
1.5.4.3