Skip to content

Commit 018fd85

Browse files
AxelLinbroonie
authored andcommitted
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>
1 parent 8735bc2 commit 018fd85

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

‎drivers/regulator/ab3100.c‎

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,19 @@ static const u8 ab3100_reg_initvals[] = {
609609
LDO_D_SETTING,
610610
};
611611

612+
static int ab3100_regulators_remove(struct platform_device *pdev)
613+
{
614+
int i;
615+
616+
for (i = 0; i < AB3100_NUM_REGULATORS; i++) {
617+
struct ab3100_regulator *reg = &ab3100_regulators[i];
618+
619+
regulator_unregister(reg->rdev);
620+
reg->rdev = NULL;
621+
}
622+
return 0;
623+
}
624+
612625
static int
613626
ab3100_regulator_of_probe(struct platform_device *pdev, struct device_node *np)
614627
{
@@ -635,8 +648,10 @@ ab3100_regulator_of_probe(struct platform_device *pdev, struct device_node *np)
635648
pdev, NULL, ab3100_regulator_matches[i].init_data,
636649
ab3100_regulator_matches[i].of_node,
637650
(int) ab3100_regulator_matches[i].driver_data);
638-
if (err)
651+
if (err) {
652+
ab3100_regulators_remove(pdev);
639653
return err;
654+
}
640655
}
641656

642657
return 0;
@@ -695,25 +710,15 @@ static int ab3100_regulators_probe(struct platform_device *pdev)
695710

696711
err = ab3100_regulator_register(pdev, plfdata, NULL, NULL,
697712
desc->id);
698-
if (err)
713+
if (err) {
714+
ab3100_regulators_remove(pdev);
699715
return err;
716+
}
700717
}
701718

702719
return 0;
703720
}
704721

705-
static int ab3100_regulators_remove(struct platform_device *pdev)
706-
{
707-
int i;
708-
709-
for (i = 0; i < AB3100_NUM_REGULATORS; i++) {
710-
struct ab3100_regulator *reg = &ab3100_regulators[i];
711-
712-
regulator_unregister(reg->rdev);
713-
}
714-
return 0;
715-
}
716-
717722
static struct platform_driver ab3100_regulators_driver = {
718723
.driver = {
719724
.name = "ab3100-regulators",

0 commit comments

Comments
 (0)