Skip to contentSkip to conversation

max8998: fix off-by-one value range checking

PATCH Applied Axel Lin 4 participants 5 messages Aug 4, 2010 – Aug 5, 2010 Voltage and current regulator framework

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 max8998: fix off-by-one value range checking

In max8998_list_voltage() and max8998_set_voltage(),
we use ldo as array index of ldo_voltage_map.
Thus the valid range should be 0 .. ARRAY_SIZE(ldo_voltage_map)-1.

---
 drivers/regulator/max8998.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/regulator/max8998.c +2 -2
index 03e55a1..ab67298 100644
@@ -119,7 +119,7 @@ static int max8998_list_voltage(struct regulator_dev *rdev,
 	int ldo = max8998_get_ldo(rdev);
 	int val;
 
-	if (ldo > ARRAY_SIZE(ldo_voltage_map))
+	if (ldo >= ARRAY_SIZE(ldo_voltage_map))
 		return -EINVAL;
 
 	desc = ldo_voltage_map[ldo];
@@ -306,7 +306,7 @@ static int max8998_set_voltage(struct regulator_dev *rdev,
 	u8 val;
 	bool en_ramp = false;
 
-	if (ldo > ARRAY_SIZE(ldo_voltage_map))
+	if (ldo >= ARRAY_SIZE(ldo_voltage_map))
 		return -EINVAL;
 
 	desc = ldo_voltage_map[ldo];
Signature · 1 line
1.5.4.3
Acked-by on v1 1/1
#1 lore raw

Nice catch.

Quoted 42 lines · Axel Lin

In max8998_list_voltage() and max8998_set_voltage(),
we use ldo as array index of ldo_voltage_map.
Thus the valid range should be 0 .. ARRAY_SIZE(ldo_voltage_map)-1.

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

 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/regulator/max8998.c +2 -3
index 03e55a1..ab67298 100644
@@ -119,7 +119,7 @@ static int max8998_list_voltage(struct regulator_dev *rdev,
        int ldo = max8998_get_ldo(rdev);
        int val;
 
-       if (ldo > ARRAY_SIZE(ldo_voltage_map))
+       if (ldo >= ARRAY_SIZE(ldo_voltage_map))
                return -EINVAL;
 
        desc = ldo_voltage_map[ldo];
@@ -306,7 +306,7 @@ static int max8998_set_voltage(struct regulator_dev *rdev,
        u8 val;
        bool en_ramp = false;
 
-       if (ldo > ARRAY_SIZE(ldo_voltage_map))
+       if (ldo >= ARRAY_SIZE(ldo_voltage_map))
                return -EINVAL;
 
        desc = ldo_voltage_map[ldo];
--

1.5.4.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Acked-by on v1 1/1
#2 lore raw
In reply to Axel Lin
Quoted 5 lines · Axel Lin

In max8998_list_voltage() and max8998_set_voltage(),
we use ldo as array index of ldo_voltage_map.
Thus the valid range should be 0 .. ARRAY_SIZE(ldo_voltage_map)-1.

Axel, please do try to bear in mind my previous comments about supplying subject lines for your commits consistent with those for the relevant code area. This makes your patches easier to apply.

#3 lore raw
Quoted 9 lines · Mark Brown
Quoted 5 lines · Axel Lin

In max8998_list_voltage() and max8998_set_voltage(),
we use ldo as array index of ldo_voltage_map.
Thus the valid range should be 0 .. ARRAY_SIZE(ldo_voltage_map)-1.

Applied.

Thanks

Liam

Signature · 3 lines
Freelance Developer, SlimLogic Ltd
ASoC and Voltage Regulator Maintainer.
http://www.slimlogic.co.uk
author
#4 lore raw
In reply to Mark Brown

2010/8/4 Mark Brown <[email protected]>:

Quoted 5 lines · Axel Lin
Quoted 3 lines

In max8998_list_voltage() and max8998_set_voltage(),
we use ldo as array index of ldo_voltage_map.
Thus the valid range should be 0 .. ARRAY_SIZE(ldo_voltage_map)-1.

Quoted 8 lines
Quoted 1 line

Axel, please do try to bear in mind my previous comments about supplying subject lines for your commits consistent with those for the relevant code area.  This makes your patches easier to apply.

OK, will improve it next time.

Regards,
Axel