All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] regulator: ab3100: Fix regulator register error handling
@ 2013-04-26 13:57 Axel Lin
  2013-04-26 15:33 ` Mark Brown
  2013-04-29 12:53 ` Linus Walleij
  0 siblings, 2 replies; 3+ messages in thread
From: Axel Lin @ 2013-04-26 13:57 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linus Walleij, Liam Girdwood, linux-kernel

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>
---
 drivers/regulator/ab3100.c |   33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/drivers/regulator/ab3100.c b/drivers/regulator/ab3100.c
index be1e6ad..3be9e46 100644
--- a/drivers/regulator/ab3100.c
+++ b/drivers/regulator/ab3100.c
@@ -609,6 +609,19 @@ static const u8 ab3100_reg_initvals[] = {
 	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
 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,
 			ab3100_regulator_matches[i].of_node,
 			(int) ab3100_regulator_matches[i].driver_data);
-		if (err)
+		if (err) {
+			ab3100_regulators_remove(pdev);
 			return err;
+		}
 	}
 
 	return 0;
@@ -695,25 +710,15 @@ static int ab3100_regulators_probe(struct platform_device *pdev)
 
 		err = ab3100_regulator_register(pdev, plfdata, NULL, NULL,
 						desc->id);
-		if (err)
+		if (err) {
+			ab3100_regulators_remove(pdev);
 			return err;
+		}
 	}
 
 	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 = {
 	.driver = {
 		.name  = "ab3100-regulators",
-- 
1.7.10.4




^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] regulator: ab3100: Fix regulator register error handling
  2013-04-26 13:57 [PATCH] regulator: ab3100: Fix regulator register error handling Axel Lin
@ 2013-04-26 15:33 ` Mark Brown
  2013-04-29 12:53 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2013-04-26 15:33 UTC (permalink / raw)
  To: Axel Lin; +Cc: Linus Walleij, Liam Girdwood, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 465 bytes --]

On Fri, Apr 26, 2013 at 09:57:09PM +0800, Axel Lin wrote:
> 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.

Applied, thanks.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] regulator: ab3100: Fix regulator register error handling
  2013-04-26 13:57 [PATCH] regulator: ab3100: Fix regulator register error handling Axel Lin
  2013-04-26 15:33 ` Mark Brown
@ 2013-04-29 12:53 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2013-04-29 12:53 UTC (permalink / raw)
  To: Axel Lin; +Cc: Mark Brown, Liam Girdwood, linux-kernel

On Fri, Apr 26, 2013 at 3:57 PM, Axel Lin <axel.lin@ingics.com> wrote:

> 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>

Excellent patch Axel, thanks!
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-04-29 12:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-26 13:57 [PATCH] regulator: ab3100: Fix regulator register error handling Axel Lin
2013-04-26 15:33 ` Mark Brown
2013-04-29 12:53 ` Linus Walleij

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.