* [PATCH 1/1] drivers: clk: sunxi: Fix memory leakage in clk-sunxi.c
@ 2013-10-12 22:05 Victor N. Ramos Mello
2013-10-14 19:32 ` Maxime Ripard
0 siblings, 1 reply; 2+ messages in thread
From: Victor N. Ramos Mello @ 2013-10-12 22:05 UTC (permalink / raw)
To: Mike Turquette, Emilio López, Maxime Ripard,
Gregory CLEMENT, Stephen Boyd
Cc: linux-kernel, Victor N. Ramos Mello
From: "Victor N. Ramos Mello" <victornrm@gmail.com>
Fix a possible memory leak in sun4i_osc_clk_setup().
Moved clock-frequency check to save superfluous allocation.
Signed-off-by: Victor N. Ramos Mello <victornrm@gmail.com>
---
drivers/clk/sunxi/clk-sunxi.c | 16 +++++++++-------
1 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/drivers/clk/sunxi/clk-sunxi.c b/drivers/clk/sunxi/clk-sunxi.c
index 34ee69f..a741770 100644
--- a/drivers/clk/sunxi/clk-sunxi.c
+++ b/drivers/clk/sunxi/clk-sunxi.c
@@ -38,18 +38,16 @@ static void __init sun4i_osc_clk_setup(struct device_node *node)
const char *clk_name = node->name;
u32 rate;
+ if (of_property_read_u32(node, "clock-frequency", &rate))
+ return;
+
/* allocate fixed-rate and gate clock structs */
fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL);
if (!fixed)
return;
gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
- if (!gate) {
- kfree(fixed);
- return;
- }
-
- if (of_property_read_u32(node, "clock-frequency", &rate))
- return;
+ if (!gate)
+ goto err_gate;
/* set up gate and fixed rate properties */
gate->reg = of_iomap(node, 0);
@@ -67,7 +65,11 @@ static void __init sun4i_osc_clk_setup(struct device_node *node)
if (!IS_ERR(clk)) {
of_clk_add_provider(node, of_clk_src_simple_get, clk);
clk_register_clkdev(clk, clk_name, NULL);
+ return;
}
+ kfree(gate);
+err_gate:
+ kfree(fixed);
}
CLK_OF_DECLARE(sun4i_osc, "allwinner,sun4i-osc-clk", sun4i_osc_clk_setup);
--
1.7.5.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 1/1] drivers: clk: sunxi: Fix memory leakage in clk-sunxi.c
2013-10-12 22:05 [PATCH 1/1] drivers: clk: sunxi: Fix memory leakage in clk-sunxi.c Victor N. Ramos Mello
@ 2013-10-14 19:32 ` Maxime Ripard
0 siblings, 0 replies; 2+ messages in thread
From: Maxime Ripard @ 2013-10-14 19:32 UTC (permalink / raw)
To: Victor N. Ramos Mello
Cc: Mike Turquette, Emilio López, Gregory CLEMENT, Stephen Boyd,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2103 bytes --]
Hi Victor,
On Sat, Oct 12, 2013 at 07:05:54PM -0300, Victor N. Ramos Mello wrote:
> From: "Victor N. Ramos Mello" <victornrm@gmail.com>
>
> Fix a possible memory leak in sun4i_osc_clk_setup().
> Moved clock-frequency check to save superfluous allocation.
>
> Signed-off-by: Victor N. Ramos Mello <victornrm@gmail.com>
> ---
> drivers/clk/sunxi/clk-sunxi.c | 16 +++++++++-------
> 1 files changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/clk/sunxi/clk-sunxi.c b/drivers/clk/sunxi/clk-sunxi.c
> index 34ee69f..a741770 100644
> --- a/drivers/clk/sunxi/clk-sunxi.c
> +++ b/drivers/clk/sunxi/clk-sunxi.c
> @@ -38,18 +38,16 @@ static void __init sun4i_osc_clk_setup(struct device_node *node)
> const char *clk_name = node->name;
> u32 rate;
>
> + if (of_property_read_u32(node, "clock-frequency", &rate))
> + return;
> +
> /* allocate fixed-rate and gate clock structs */
> fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL);
> if (!fixed)
> return;
> gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
> - if (!gate) {
> - kfree(fixed);
> - return;
> - }
> -
> - if (of_property_read_u32(node, "clock-frequency", &rate))
> - return;
> + if (!gate)
> + goto err_gate;
>
> /* set up gate and fixed rate properties */
> gate->reg = of_iomap(node, 0);
> @@ -67,7 +65,11 @@ static void __init sun4i_osc_clk_setup(struct device_node *node)
> if (!IS_ERR(clk)) {
> of_clk_add_provider(node, of_clk_src_simple_get, clk);
> clk_register_clkdev(clk, clk_name, NULL);
> + return;
> }
> + kfree(gate);
> +err_gate:
> + kfree(fixed);
While the patch is appreciated, I find the logic here a bit backward
compared to what's usually done.
I'd rather see here something like
if (IS_ERR(clk))
goto err_gate;
of_clk_add_provider(...);
clk_register_clkdev(...);
return;
err_gate:
kfree(gate);
err_fixed:
kfree(fixed);
But maybe it's just me.
Thanks!
Maxime
--
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-10-14 20:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-12 22:05 [PATCH 1/1] drivers: clk: sunxi: Fix memory leakage in clk-sunxi.c Victor N. Ramos Mello
2013-10-14 19:32 ` Maxime Ripard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).