regulator: ab3100: Fix regulator register error handling
Ensure to unregister all regulators before return error in probe(). The regulator register order depends on the regulator ID pass to ab3100_regulator_register() function. Thus we need to scan ab3100_regulator_desc and find the index of successfully registered regulators, or alternatively just call ab3100_regulators_remove() to unregister all registered regulators. Since current code uses a static ab3100_regulators table, explicitly set reg->rdev = NULL after regulator_unregister() call to ensure calling ab3100_regulators_remove() in the unwind path always work. Also move ab3100_regulators_remove() to avoid forward declaration. Signed-off-by: Axel Lin <axel.lin@ingics.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
This commit is contained in:
parent
8735bc2fe6
commit
018fd856ce
|
@ -609,6 +609,19 @@ static const u8 ab3100_reg_initvals[] = {
|
||||||
LDO_D_SETTING,
|
LDO_D_SETTING,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int ab3100_regulators_remove(struct platform_device *pdev)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < AB3100_NUM_REGULATORS; i++) {
|
||||||
|
struct ab3100_regulator *reg = &ab3100_regulators[i];
|
||||||
|
|
||||||
|
regulator_unregister(reg->rdev);
|
||||||
|
reg->rdev = NULL;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ab3100_regulator_of_probe(struct platform_device *pdev, struct device_node *np)
|
ab3100_regulator_of_probe(struct platform_device *pdev, struct device_node *np)
|
||||||
{
|
{
|
||||||
|
@ -635,8 +648,10 @@ ab3100_regulator_of_probe(struct platform_device *pdev, struct device_node *np)
|
||||||
pdev, NULL, ab3100_regulator_matches[i].init_data,
|
pdev, NULL, ab3100_regulator_matches[i].init_data,
|
||||||
ab3100_regulator_matches[i].of_node,
|
ab3100_regulator_matches[i].of_node,
|
||||||
(int) ab3100_regulator_matches[i].driver_data);
|
(int) ab3100_regulator_matches[i].driver_data);
|
||||||
if (err)
|
if (err) {
|
||||||
|
ab3100_regulators_remove(pdev);
|
||||||
return err;
|
return err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -695,25 +710,15 @@ static int ab3100_regulators_probe(struct platform_device *pdev)
|
||||||
|
|
||||||
err = ab3100_regulator_register(pdev, plfdata, NULL, NULL,
|
err = ab3100_regulator_register(pdev, plfdata, NULL, NULL,
|
||||||
desc->id);
|
desc->id);
|
||||||
if (err)
|
if (err) {
|
||||||
|
ab3100_regulators_remove(pdev);
|
||||||
return err;
|
return err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ab3100_regulators_remove(struct platform_device *pdev)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < AB3100_NUM_REGULATORS; i++) {
|
|
||||||
struct ab3100_regulator *reg = &ab3100_regulators[i];
|
|
||||||
|
|
||||||
regulator_unregister(reg->rdev);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct platform_driver ab3100_regulators_driver = {
|
static struct platform_driver ab3100_regulators_driver = {
|
||||||
.driver = {
|
.driver = {
|
||||||
.name = "ab3100-regulators",
|
.name = "ab3100-regulators",
|
||||||
|
|
Loading…
Reference in a new issue