2014-06-14 01:48:15

by Nicholas Krause

[permalink] [raw]
Subject: [PATCH] Fixes two memory leaks in drivers/clk/sunxi/clk-sunxi.c

diff --git a/drivers/clk/sunxi/clk-sunxi.c b/drivers/clk/sunxi/clk-sunxi.c
index 4264834..07b45d1 100644
--- a/drivers/clk/sunxi/clk-sunxi.c
+++ b/drivers/clk/sunxi/clk-sunxi.c
@@ -41,9 +41,11 @@ 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))
+ if (of_property_read_u32(node, "clock-frequency", &rate)) {
+ kfree(fixed);
+ kfree(gate);
return;
-
+ }
/* allocate fixed-rate and gate clock structs */
fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL);
if (!fixed)
--
1.9.1


2014-06-14 02:11:32

by Emilio López

[permalink] [raw]
Subject: Re: [PATCH] Fixes two memory leaks in drivers/clk/sunxi/clk-sunxi.c

Hi,

El 13/06/14 22:47, Nick escribi?:
> diff --git a/drivers/clk/sunxi/clk-sunxi.c b/drivers/clk/sunxi/clk-sunxi.c
> index 4264834..07b45d1 100644
> --- a/drivers/clk/sunxi/clk-sunxi.c
> +++ b/drivers/clk/sunxi/clk-sunxi.c
> @@ -41,9 +41,11 @@ 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))
> + if (of_property_read_u32(node, "clock-frequency", &rate)) {
> + kfree(fixed);
> + kfree(gate);

Why are you trying to free these two, when they haven't been allocated yet?

> return;
> -
> + }
> /* allocate fixed-rate and gate clock structs */
> fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL);
> if (!fixed)
>

fixed is allocated here. gate follows suit after it.

Cheers,

Emilio

PS: For next time, please use a proper prefix on your patch subject
("clk: sunxi: " in this case) as well as add a description to your patch
and a signoff line.

2014-06-14 17:22:38

by Sergei Shtylyov

[permalink] [raw]
Subject: Re: [PATCH] Fixes two memory leaks in drivers/clk/sunxi/clk-sunxi.c

Hello.

On 06/14/2014 05:47 AM, Nick wrote:

Please sign off on your patches, they can't applied otherwise.

> diff --git a/drivers/clk/sunxi/clk-sunxi.c b/drivers/clk/sunxi/clk-sunxi.c
> index 4264834..07b45d1 100644
> --- a/drivers/clk/sunxi/clk-sunxi.c
> +++ b/drivers/clk/sunxi/clk-sunxi.c
> @@ -41,9 +41,11 @@ 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))
> + if (of_property_read_u32(node, "clock-frequency", &rate)) {
> + kfree(fixed);

Eh, we only allocate 'fixed' after this point, no?

> + kfree(gate);
> return;
> -
> + }
> /* allocate fixed-rate and gate clock structs */
> fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL);
> if (!fixed)

WBR, Sergei