lkml.org 
[lkml]   [2013]   [Dec]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v3 1/2] regulator: anatop-regulator: Fix the error handling on probe
Date
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


\
 
 \ /
  Last update: 2013-12-23 16:21    [W:1.391 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site