regulator: anatop-regulator: Fix the error handling on probe
PATCH v3 1/2 regulator: anatop-regulator: Fix the error handling on probe
From: Fabio Estevam <[email protected]>
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.
---
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(-)
drivers/regulator/anatop-regulator.c +11 -6
@@ -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; }
Signature · 1 line
1.8.1.2
PATCH v3 2/2 regulator: anatop-regulator: Remove unneeded variable
From: Fabio Estevam <[email protected]>
There is no need to create a local variable for accessing sreg->name.
Access it directly instead.
---
Changes since v2:
- None
drivers/regulator/anatop-regulator.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/regulator/anatop-regulator.c +1 -2
@@ -226,9 +226,8 @@ static int anatop_regulator_remove(struct platform_device *pdev) {struct regulator_dev *rdev =platform_get_drvdata (pdev);struct anatop_regulator *sreg =rdev_get_drvdata (rdev); -const char *name = sreg->name; -kfree (name); +kfree (sreg->name);return 0 ; }
Signature · 1 line
1.8.1.2
Quoted 11 lines · Fabio Estevam
From: Fabio Estevam <[email protected]>
Currently when
of_get_parent()orsyscon_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 <[email protected]>
Quoted 4 lines · Fabio Estevam
From: Fabio Estevam <[email protected]>
Currently when
of_get_parent()orsyscon_node_to_regmap()fail 'kfree(sreg->name)' is not called, which is incorrect.
Applied both, thanks.
Quoted 7 lines · Mark Brown
Quoted 4 lines · Fabio Estevam
From: Fabio Estevam <[email protected]>
Currently when
of_get_parent()orsyscon_node_to_regmap()fail 'kfree(sreg->name)' is not called, which is incorrect.Applied both, thanks.
Sorry for being too later, but why are we making copy to begin with? It is not like DT data will disappear later on.
Thanks.
Signature · 1 line
Dmitry
Hi Dmitry,
Quoted 11 lines · Dmitry Torokhov
Quoted 7 lines · Mark Brown
Quoted 4 lines · Fabio Estevam
From: Fabio Estevam <[email protected]>
Currently when
of_get_parent()orsyscon_node_to_regmap()fail 'kfree(sreg->name)' is not called, which is incorrect.Applied both, thanks.
Sorry for being too later, but why are we making copy to begin with? It is not like DT data will disappear later on.
Which lines of code are you referring to, please?
Regards,
Fabio Estevam
Quoted 11 lines · Fabio Estevam
Hi Dmitry,
Quoted 7 lines · Dmitry Torokhov
Quoted 6 lines · Mark Brown
Quoted 4 lines · Fabio Estevam
From: Fabio Estevam <[email protected]>
Currently when
of_get_parent()orsyscon_node_to_regmap()fail 'kfree(sreg->name)' is not called, which is incorrect.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Applied both, thanks.
Sorry for being too later, but why are we making copy to begin with? It is not like DT data will disappear later on.
Which lines of code are you referring to, please?
I am talking about this:
sreg->name = kstrdup(of_get_property(np, "regulator-name", NULL), GFP_KERNEL);
Whatis the reason for kstrdup? Can we simply say:
sreg->name = of_get_property(np, "regulator-name", NULL);
Thanks.
Signature · 1 line
Dmitry