Skip to contentSkip to conversation

regulator: ti-abb: Fix off-by-one valid range checking for abb->current_info_idx

PATCH Applied Axel Lin 3 participants 3 messages May 4, 2013 – May 5, 2013 Voltage and current regulator framework

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 regulator: ti-abb: Fix off-by-one valid range checking for abb->current_info_idx

abb->current_info_idx is used as array subscript to access volt_table, thus the valid value range should be 0 ... desc->n_voltages - 1.

---
 drivers/regulator/ti-abb-regulator.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/regulator/ti-abb-regulator.c +2 -2
index c1870ea..870d209 100644
@@ -387,8 +387,8 @@ static int ti_abb_get_voltage_sel(struct regulator_dev *rdev)
 		return -EINVAL;
 	}
 
-	if (abb->current_info_idx > (int)desc->n_voltages) {
-		dev_err(dev, "%s: Corrupted data? idx(%d) > n_voltages(%d)\n",
+	if (abb->current_info_idx >= (int)desc->n_voltages) {
+		dev_err(dev, "%s: Corrupted data? idx(%d) >= n_voltages(%d)\n",
 			__func__, abb->current_info_idx, desc->n_voltages);
 		return -EINVAL;
 	}
Signature · 1 line
1.8.1.2
Acked-by on v1 1/1
#1 lore raw

Change in Liam's email ID.

Quoted 25 lines · Axel Lin

abb->current_info_idx is used as array subscript to access volt_table, thus the valid value range should be 0 ... desc->n_voltages - 1.

---
 drivers/regulator/ti-abb-regulator.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/regulator/ti-abb-regulator.c +2 -2
index c1870ea..870d209 100644
@@ -387,8 +387,8 @@ static int ti_abb_get_voltage_sel(struct regulator_dev *rdev)
 		return -EINVAL;
 	}
 
-	if (abb->current_info_idx > (int)desc->n_voltages) {
-		dev_err(dev, "%s: Corrupted data? idx(%d) > n_voltages(%d)\n",
+	if (abb->current_info_idx >= (int)desc->n_voltages) {
+		dev_err(dev, "%s: Corrupted data? idx(%d) >= n_voltages(%d)\n",
 			__func__, abb->current_info_idx, desc->n_voltages);
 		return -EINVAL;
 	}
Signature · 1 line
1.8.1.2

Thanks for the same.

Signature · 2 lines
Regards,
Nishanth Menon
maintainer Applied
#2 lore raw
In reply to Axel Lin
Quoted 2 lines · Axel Lin

abb->current_info_idx is used as array subscript to access volt_table, thus the valid value range should be 0 ... desc->n_voltages - 1.

Applied, thanks.