Commit 8ae5767b authored by Axel Lin's avatar Axel Lin Committed by Mark Brown

regulator: max8997: Convert ot use devm_kzalloc

Also simplify the error handling to start unwind from the place
regulator_register fails.

No need to check rdev[i] is NULL or not before calling regulator_unregister.
regulator_unregister is safe if rdev is NULL,
Signed-off-by: default avatarAxel Lin <axel.lin@gmail.com>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent 6c9eeb0f
...@@ -949,16 +949,15 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) ...@@ -949,16 +949,15 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev)
return -ENODEV; return -ENODEV;
} }
max8997 = kzalloc(sizeof(struct max8997_data), GFP_KERNEL); max8997 = devm_kzalloc(&pdev->dev, sizeof(struct max8997_data),
GFP_KERNEL);
if (!max8997) if (!max8997)
return -ENOMEM; return -ENOMEM;
size = sizeof(struct regulator_dev *) * pdata->num_regulators; size = sizeof(struct regulator_dev *) * pdata->num_regulators;
max8997->rdev = kzalloc(size, GFP_KERNEL); max8997->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
if (!max8997->rdev) { if (!max8997->rdev)
kfree(max8997);
return -ENOMEM; return -ENOMEM;
}
rdev = max8997->rdev; rdev = max8997->rdev;
max8997->dev = &pdev->dev; max8997->dev = &pdev->dev;
...@@ -982,7 +981,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) ...@@ -982,7 +981,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev)
pdata->buck1_voltage[i] / 1000 + pdata->buck1_voltage[i] / 1000 +
buck1245_voltage_map_desc.step); buck1245_voltage_map_desc.step);
if (ret < 0) if (ret < 0)
goto err_alloc; goto err_out;
max8997->buck2_vol[i] = ret = max8997->buck2_vol[i] = ret =
max8997_get_voltage_proper_val( max8997_get_voltage_proper_val(
...@@ -991,7 +990,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) ...@@ -991,7 +990,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev)
pdata->buck2_voltage[i] / 1000 + pdata->buck2_voltage[i] / 1000 +
buck1245_voltage_map_desc.step); buck1245_voltage_map_desc.step);
if (ret < 0) if (ret < 0)
goto err_alloc; goto err_out;
max8997->buck5_vol[i] = ret = max8997->buck5_vol[i] = ret =
max8997_get_voltage_proper_val( max8997_get_voltage_proper_val(
...@@ -1000,7 +999,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) ...@@ -1000,7 +999,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev)
pdata->buck5_voltage[i] / 1000 + pdata->buck5_voltage[i] / 1000 +
buck1245_voltage_map_desc.step); buck1245_voltage_map_desc.step);
if (ret < 0) if (ret < 0)
goto err_alloc; goto err_out;
if (max_buck1 < max8997->buck1_vol[i]) if (max_buck1 < max8997->buck1_vol[i])
max_buck1 = max8997->buck1_vol[i]; max_buck1 = max8997->buck1_vol[i];
...@@ -1033,7 +1032,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) ...@@ -1033,7 +1032,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev)
!gpio_is_valid(pdata->buck125_gpios[2])) { !gpio_is_valid(pdata->buck125_gpios[2])) {
dev_err(&pdev->dev, "GPIO NOT VALID\n"); dev_err(&pdev->dev, "GPIO NOT VALID\n");
ret = -EINVAL; ret = -EINVAL;
goto err_alloc; goto err_out;
} }
ret = gpio_request(pdata->buck125_gpios[0], ret = gpio_request(pdata->buck125_gpios[0],
...@@ -1042,7 +1041,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) ...@@ -1042,7 +1041,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev)
dev_warn(&pdev->dev, "Duplicated gpio request" dev_warn(&pdev->dev, "Duplicated gpio request"
" on SET1\n"); " on SET1\n");
else if (ret) else if (ret)
goto err_alloc; goto err_out;
else else
gpio1set = true; gpio1set = true;
...@@ -1054,7 +1053,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) ...@@ -1054,7 +1053,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev)
else if (ret) { else if (ret) {
if (gpio1set) if (gpio1set)
gpio_free(pdata->buck125_gpios[0]); gpio_free(pdata->buck125_gpios[0]);
goto err_alloc; goto err_out;
} else } else
gpio2set = true; gpio2set = true;
...@@ -1068,7 +1067,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) ...@@ -1068,7 +1067,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev)
gpio_free(pdata->buck125_gpios[0]); gpio_free(pdata->buck125_gpios[0]);
if (gpio2set) if (gpio2set)
gpio_free(pdata->buck125_gpios[1]); gpio_free(pdata->buck125_gpios[1]);
goto err_alloc; goto err_out;
} }
gpio_direction_output(pdata->buck125_gpios[0], gpio_direction_output(pdata->buck125_gpios[0],
...@@ -1137,13 +1136,9 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) ...@@ -1137,13 +1136,9 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev)
return 0; return 0;
err: err:
for (i = 0; i < max8997->num_regulators; i++) while (--i >= 0)
if (rdev[i]) regulator_unregister(rdev[i]);
regulator_unregister(rdev[i]); err_out:
err_alloc:
kfree(max8997->rdev);
kfree(max8997);
return ret; return ret;
} }
...@@ -1154,12 +1149,7 @@ static int __devexit max8997_pmic_remove(struct platform_device *pdev) ...@@ -1154,12 +1149,7 @@ static int __devexit max8997_pmic_remove(struct platform_device *pdev)
int i; int i;
for (i = 0; i < max8997->num_regulators; i++) for (i = 0; i < max8997->num_regulators; i++)
if (rdev[i]) regulator_unregister(rdev[i]);
regulator_unregister(rdev[i]);
kfree(max8997->rdev);
kfree(max8997);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment