Skip to contentSkip to conversation

regulator: 88pm8607: Fix off-by-one value range checking in the case of no id is matched

PATCH Applied Axel Lin 3 participants 3 messages Aug 4, 2011 – Aug 8, 2011 Voltage and current regulator framework

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 regulator: 88pm8607: Fix off-by-one value range checking in the case of no id is matched

In the case of no id is matched, the variable i is equal to ARRAY_SIZE(pm8607_regulator_info).

---
I think compare variable i with ARRAY_SIZE(pm8607_regulator_info) here is slightly better in readability than compare with PM8607_ID_RG_MAX.
Axel

 drivers/regulator/88pm8607.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/regulator/88pm8607.c +1 -1
index 5dcdb0f..ca0d608 100644
@@ -413,7 +413,7 @@ static int __devinit pm8607_regulator_probe(struct platform_device *pdev)
 		if (info->desc.id == res->start)
 			break;
 	}
-	if ((i < 0) || (i > PM8607_ID_RG_MAX)) {
+	if (i == ARRAY_SIZE(pm8607_regulator_info)) {
 		dev_err(&pdev->dev, "Failed to find regulator %llu\n",
 			(unsigned long long)res->start);
 		return -EINVAL;
Signature · 1 line
1.7.4.1
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Axel Lin

In the case of no id is matched, the variable i is equal to ARRAY_SIZE(pm8607_regulator_info).

Quoted 2 lines

I think compare variable i with ARRAY_SIZE(pm8607_regulator_info) here is slightly better in readability than compare with PM8607_ID_RG_MAX.

It should be more robust I guess.

#2 lore raw
In reply to Axel Lin
Quoted 9 lines · Axel Lin

In the case of no id is matched, the variable i is equal to ARRAY_SIZE(pm8607_regulator_info).

---
I think compare variable i with ARRAY_SIZE(pm8607_regulator_info) here is slightly better in readability than compare with PM8607_ID_RG_MAX.
Axel

Applied.

Thanks

Liam