Skip to contentSkip to conversation

regulator: max8952 - fix max8952_pmic_probe error path

PATCH In review Axel Lin 2 participants 5 messages Oct 25, 2010 Voltage and current regulator framework

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/2 regulator: max8952 - fix max8952_pmic_probe error path

---
 drivers/regulator/max8952.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
drivers/regulator/max8952.c +8 -2
index f2af0b1..7d6aacf 100644
@@ -212,9 +212,11 @@ static int __devinit max8952_pmic_probe(struct i2c_client *client,
 	max8952->rdev = regulator_register(&regulator, max8952->dev,
 			&pdata->reg_data, max8952);
 
-	ret = IS_ERR(max8952->rdev);
-	if (ret)
+	if (IS_ERR(max8952->rdev)) {
+		ret = PTR_ERR(max8952->rdev);
 		dev_err(max8952->dev, "regulator init failed (%d)\n", ret);
+		goto err_reg;
+	}
 
 	max8952->en = !!(pdata->reg_data.constraints.boot_on);
 	max8952->vid0 = (pdata->default_mode % 2) == 1;
@@ -309,6 +311,10 @@ static int __devinit max8952_pmic_probe(struct i2c_client *client,
 
 	i2c_set_clientdata(client, max8952);
 
+	return 0;
+
+err_reg:
+	kfree(max8952);
 	return ret;
 }
 
Signature · 1 line
1.7.2
author
#1 lore raw

PATCH 2/2 regulator: max8952 - fix max8952_set_voltage

In current implementation, vid is declared as u8,
then "vid == -1" is always false, and "vid >= 0" is always true. Thus change it to s8.

vid is always less than MAX8952_NUM_DVS_MODE in current implementation, thus remove the cheking for "vid < MAX8952_NUM_DVS_MODE".

---
 drivers/regulator/max8952.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/regulator/max8952.c +2 -2
index 7d6aacf..5b4601e 100644
@@ -136,7 +136,7 @@ static int max8952_set_voltage(struct regulator_dev *rdev,
 				int min_uV, int max_uV)
 {
 	struct max8952_data *max8952 = rdev_get_drvdata(rdev);
-	u8 vid = -1, i;
+	s8 vid = -1, i;
 
 	if (!gpio_is_valid(max8952->pdata->gpio_vid0) ||
 			!gpio_is_valid(max8952->pdata->gpio_vid0)) {
@@ -153,7 +153,7 @@ static int max8952_set_voltage(struct regulator_dev *rdev,
 				vid = i;
 	}
 
-	if (vid >= 0 && vid < MAX8952_NUM_DVS_MODE) {
+	if (vid >= 0) {
 		max8952->vid0 = (vid % 2 == 1);
 		max8952->vid1 = (((vid >> 1) % 2) == 1);
 		gpio_set_value(max8952->pdata->gpio_vid0, max8952->vid0);
Signature · 1 line
1.7.2
#2 lore raw

Re: [PATCH 2/2] regulator: max8952 - fix max8952_set_voltage

In reply to Axel Lin
Quoted 6 lines · Axel Lin

In current implementation, vid is declared as u8,
then "vid == -1" is always false, and "vid >= 0" is always true. Thus change it to s8.

vid is always less than MAX8952_NUM_DVS_MODE in current implementation, thus remove the cheking for "vid < MAX8952_NUM_DVS_MODE".

This bit seems like reasonable paranoia in the face of future code changes and we're not really in a sufficiently fast path to worry about cycles - are you sure that this is essential?

author
#3 lore raw

Re: [PATCH 2/2] regulator: max8952 - fix max8952_set_voltage

2010/10/26 Mark Brown <[email protected]>:

Quoted 5 lines · Axel Lin
Quoted 4 lines

In current implementation, vid is declared as u8,
then "vid == -1" is always false, and "vid >= 0" is always true. Thus change it to s8.

Quoted 7 lines
Quoted 2 lines

vid is always less than MAX8952_NUM_DVS_MODE in current implementation, thus remove the cheking for "vid < MAX8952_NUM_DVS_MODE".

This bit seems like reasonable paranoia in the face of future code changes and we're not really in a sufficiently fast path to worry about cycles - are you sure that this is essential?

Ok. I will send a v2 thant only change u8 to s8.

Regards,
Axel