mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Fabio Estevam <festevam@gmail.com>
To: broonie@kernel.org
Cc: shawn.guo@linaro.org, Anson.Huang@freescale.com,
	linux-kernel@vger.kernel.org,
	Fabio Estevam <fabio.estevam@freescale.com>
Subject: [PATCH v3 1/2] regulator: anatop-regulator: Fix the error handling on probe
Date: Mon, 23 Dec 2013 12:44:40 -0200	[thread overview]
Message-ID: <1387809881-16092-1-git-send-email-festevam@gmail.com> (raw)

From: Fabio Estevam <fabio.estevam@freescale.com>

Currently when of_get_parent() or syscon_node_to_regmap() fail 
'kfree(sreg->name)' is not called, which is incorrect.

Fix this by jumping to 'anatop_probe_end' instead.

While at it, make 'anatop_probe_end' to be executed only on the error path, so
that the code can be a bit easier to follow.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
Changes since v2:
- Fix the error path for of_get_parent() or syscon_node_to_regmap().

 drivers/regulator/anatop-regulator.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/regulator/anatop-regulator.c b/drivers/regulator/anatop-regulator.c
index c734d09..88d95cd 100644
--- a/drivers/regulator/anatop-regulator.c
+++ b/drivers/regulator/anatop-regulator.c
@@ -132,12 +132,16 @@ static int anatop_regulator_probe(struct platform_device *pdev)
 	rdesc->owner = THIS_MODULE;
 
 	anatop_np = of_get_parent(np);
-	if (!anatop_np)
-		return -ENODEV;
+	if (!anatop_np) {
+		ret = -ENODEV;
+		goto anatop_probe_end;
+	}
 	sreg->anatop = syscon_node_to_regmap(anatop_np);
 	of_node_put(anatop_np);
-	if (IS_ERR(sreg->anatop))
-		return PTR_ERR(sreg->anatop);
+	if (IS_ERR(sreg->anatop)) {
+		ret = PTR_ERR(sreg->anatop);
+		goto anatop_probe_end;
+	}
 
 	ret = of_property_read_u32(np, "anatop-reg-offset",
 				   &sreg->control_reg);
@@ -210,9 +214,10 @@ static int anatop_regulator_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, rdev);
 
+	return 0;
+
 anatop_probe_end:
-	if (ret)
-		kfree(sreg->name);
+	kfree(sreg->name);
 
 	return ret;
 }
-- 
1.8.1.2


             reply	other threads:[~2013-12-23 14:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-23 14:44 Fabio Estevam [this message]
2013-12-23 14:44 ` [PATCH v3 2/2] regulator: anatop-regulator: Remove unneeded variable Fabio Estevam
2013-12-23 14:50 ` [PATCH v3 1/2] regulator: anatop-regulator: Fix the error handling on probe Shawn Guo
2013-12-24 13:03 ` Mark Brown
2014-01-04  0:02   ` Dmitry Torokhov
2014-01-04 16:00     ` Fabio Estevam
2014-01-04 22:31       ` Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1387809881-16092-1-git-send-email-festevam@gmail.com \
    --to=festevam@gmail.com \
    --cc=Anson.Huang@freescale.com \
    --cc=broonie@kernel.org \
    --cc=fabio.estevam@freescale.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shawn.guo@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®