Skip to contentSkip to conversation

regulator: aat2870: Fix the logic of checking if no id is matched in aat2870_get_regulator

PATCH Superseded Axel Lin 4 participants 5 messages Jul 6, 2011 Voltage and current regulator framework

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/2 regulator: aat2870: Fix the logic of checking if no id is matched in aat2870_get_regulator

In current implementation, the pointer ri is not NULL if no id is matched. Fix it by checking i == ARRAY_SIZE(aat2870_regulators) if no id is matched.

---
 drivers/regulator/aat2870-regulator.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/regulator/aat2870-regulator.c +1 -1
index cd41045..11d1ab4 100644
@@ -159,7 +159,7 @@ static struct aat2870_regulator *aat2870_get_regulator(int id)
 			break;
 	}
 
-	if (!ri)
+	if (i == ARRAY_SIZE(aat2870_regulators))
 		return NULL;
 
 	ri->enable_addr = AAT2870_LDO_EN;
Signature · 1 line
1.7.4.1
author
#1 lore raw

PATCH 2/2 regulator: aat2870: Remove a redundant bitwise and operation

The implementation in aat2870_update() already did the bitwise and operation against mask parameter.

---
 drivers/regulator/aat2870-regulator.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/regulator/aat2870-regulator.c +1 -1
index 11d1ab4..c8ea28e 100644
@@ -62,7 +62,7 @@ static int aat2870_ldo_set_voltage_sel(struct regulator_dev *rdev,
 	struct aat2870_data *aat2870 = dev_get_drvdata(ri->pdev->dev.parent);
 
 	return aat2870->update(aat2870, ri->voltage_addr, ri->voltage_mask,
-			(selector << ri->voltage_shift) & ri->voltage_mask);
+			selector << ri->voltage_shift);
 }
 
 static int aat2870_ldo_get_voltage_sel(struct regulator_dev *rdev)
Signature · 1 line
1.7.4.1
#2 lore raw
In reply to Axel Lin

Hi, Axel

Quoted 1 line

In current implementation, the pointer ri is not NULL if no id is

matched.

Quoted 1 line

Fix it by checking i == ARRAY_SIZE(aat2870_regulators) if no id is

matched.
You are right, the ri never be NULL in current implementation. That's my mistake, I didn't find it when writing and verifying the driver.

Thanks,
Jin.

#4 lore raw
In reply to Axel Lin
Quoted 13 lines · Axel Lin

In current implementation, the pointer ri is not NULL if no id is matched. Fix it by checking i == ARRAY_SIZE(aat2870_regulators) if no id is matched.

---
 drivers/regulator/aat2870-regulator.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/regulator/aat2870-regulator.c +0 -0
index cd41045..11d1ab4 100644

drivers/regulator/aat2870-regulator.c static struct aat2870_regulator *aat2870_get_regulator(int id) · line 165

Quoted 8 lines
drivers/regulator/aat2870-regulator.c +1 -1
@@ -159,7 +159,7 @@ static struct aat2870_regulator *aat2870_get_regulator(int id)
 			break;
 	}
 
-	if (!ri)
+	if (i == ARRAY_SIZE(aat2870_regulators))
 		return NULL;
 
 	ri->enable_addr = AAT2870_LDO_EN;

Can you resend both of these to Samuel with Mark's Ack as aat2870 went upstream via MFD.

Liam