regulator: ti-abb: Fix off-by-one valid range checking for abb->current_info_idx
authorAxel Lin <axel.lin@ingics.com>
Sat, 4 May 2013 14:02:27 +0000 (22:02 +0800)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Sun, 12 May 2013 14:31:36 +0000 (18:31 +0400)
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.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Acked-by: Nishanth Menon <nm@ti.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
drivers/regulator/ti-abb-regulator.c

index c1870ea649392b6e4f4fcf2c72c9dab887f1d750..870d209ec866a8317f7ef11a116f6f3095549b60 100644 (file)
@@ -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;
        }