Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1692026 > unrolled thread

[PATCH] rtc: sun6i: ensure clk_data is kfree'd on error

Started byColin King <colin.king@canonical.com>
First post2017-07-19 19:00 +0200
Last post2017-07-30 17:00 +0200
Articles 4 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] rtc: sun6i: ensure clk_data is kfree'd on error Colin King <colin.king@canonical.com> - 2017-07-19 19:00 +0200
    Re: [PATCH] rtc: sun6i: ensure clk_data is kfree'd on error Alexandre Belloni <alexandre.belloni@free-electrons.com> - 2017-07-19 19:40 +0200
      Re: [PATCH] rtc: sun6i: ensure clk_data is kfree'd on error Colin Ian King <colin.king@canonical.com> - 2017-07-19 19:50 +0200
        Re: [PATCH] rtc: sun6i: ensure clk_data is kfree'd on error Alexandre Belloni <alexandre.belloni@free-electrons.com> - 2017-07-30 17:00 +0200

#1692026 — [PATCH] rtc: sun6i: ensure clk_data is kfree'd on error

FromColin King <colin.king@canonical.com>
Date2017-07-19 19:00 +0200
Subject[PATCH] rtc: sun6i: ensure clk_data is kfree'd on error
Message-ID<u50um-2TW-11@gated-at.bofh.it>
From: Colin Ian King <colin.king@canonical.com>

There are two error return paths that do not kfree clk_data and
we end up with a memory leak. Fix these with a kfree error exit
path.

Detected by CoverityScan, CID#1402959 ("Resource Leak")

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/rtc/rtc-sun6i.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-sun6i.c b/drivers/rtc/rtc-sun6i.c
index 39cbc1238b92..61502221ab6e 100644
--- a/drivers/rtc/rtc-sun6i.c
+++ b/drivers/rtc/rtc-sun6i.c
@@ -204,7 +204,7 @@ static void __init sun6i_rtc_clk_init(struct device_node *node)
 	rtc->base = of_io_request_and_map(node, 0, of_node_full_name(node));
 	if (IS_ERR(rtc->base)) {
 		pr_crit("Can't map RTC registers");
-		return;
+		goto err;
 	}
 
 	/* Switch to the external, more precise, oscillator */
@@ -216,7 +216,7 @@ static void __init sun6i_rtc_clk_init(struct device_node *node)
 
 	/* Deal with old DTs */
 	if (!of_get_property(node, "clocks", NULL))
-		return;
+		goto err;
 
 	rtc->int_osc = clk_hw_register_fixed_rate_with_accuracy(NULL,
 								"rtc-int-osc",
@@ -246,6 +246,10 @@ static void __init sun6i_rtc_clk_init(struct device_node *node)
 	clk_data->num = 1;
 	clk_data->hws[0] = &rtc->hw;
 	of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
+	return;
+
+err:
+	kfree(clk_data);
 }
 CLK_OF_DECLARE_DRIVER(sun6i_rtc_clk, "allwinner,sun6i-a31-rtc",
 		      sun6i_rtc_clk_init);
-- 
2.11.0

[toc] | [next] | [standalone]


#1692053

FromAlexandre Belloni <alexandre.belloni@free-electrons.com>
Date2017-07-19 19:40 +0200
Message-ID<u5174-3pP-3@gated-at.bofh.it>
In reply to#1692026
Hi,

On 19/07/2017 at 17:57:02 +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> There are two error return paths that do not kfree clk_data and
> we end up with a memory leak. Fix these with a kfree error exit
> path.
> 
> Detected by CoverityScan, CID#1402959 ("Resource Leak")
> 

I think that patch fixes the same issue (and more):
http://patchwork.ozlabs.org/patch/787151/

> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/rtc/rtc-sun6i.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-sun6i.c b/drivers/rtc/rtc-sun6i.c
> index 39cbc1238b92..61502221ab6e 100644
> --- a/drivers/rtc/rtc-sun6i.c
> +++ b/drivers/rtc/rtc-sun6i.c
> @@ -204,7 +204,7 @@ static void __init sun6i_rtc_clk_init(struct device_node *node)
>  	rtc->base = of_io_request_and_map(node, 0, of_node_full_name(node));
>  	if (IS_ERR(rtc->base)) {
>  		pr_crit("Can't map RTC registers");
> -		return;
> +		goto err;
>  	}
>  
>  	/* Switch to the external, more precise, oscillator */
> @@ -216,7 +216,7 @@ static void __init sun6i_rtc_clk_init(struct device_node *node)
>  
>  	/* Deal with old DTs */
>  	if (!of_get_property(node, "clocks", NULL))
> -		return;
> +		goto err;
>  
>  	rtc->int_osc = clk_hw_register_fixed_rate_with_accuracy(NULL,
>  								"rtc-int-osc",
> @@ -246,6 +246,10 @@ static void __init sun6i_rtc_clk_init(struct device_node *node)
>  	clk_data->num = 1;
>  	clk_data->hws[0] = &rtc->hw;
>  	of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
> +	return;
> +
> +err:
> +	kfree(clk_data);
>  }
>  CLK_OF_DECLARE_DRIVER(sun6i_rtc_clk, "allwinner,sun6i-a31-rtc",
>  		      sun6i_rtc_clk_init);
> -- 
> 2.11.0
> 

-- 
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

[toc] | [prev] | [next] | [standalone]


#1692062

FromColin Ian King <colin.king@canonical.com>
Date2017-07-19 19:50 +0200
Message-ID<u51gK-3tP-3@gated-at.bofh.it>
In reply to#1692053
On 19/07/17 18:32, Alexandre Belloni wrote:
> Hi,
> 
> On 19/07/2017 at 17:57:02 +0100, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> There are two error return paths that do not kfree clk_data and
>> we end up with a memory leak. Fix these with a kfree error exit
>> path.
>>
>> Detected by CoverityScan, CID#1402959 ("Resource Leak")
>>
> 
> I think that patch fixes the same issue (and more):
> http://patchwork.ozlabs.org/patch/787151/

Yep, that's true.

> 
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
>> ---
>>  drivers/rtc/rtc-sun6i.c | 8 ++++++--
>>  1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/rtc/rtc-sun6i.c b/drivers/rtc/rtc-sun6i.c
>> index 39cbc1238b92..61502221ab6e 100644
>> --- a/drivers/rtc/rtc-sun6i.c
>> +++ b/drivers/rtc/rtc-sun6i.c
>> @@ -204,7 +204,7 @@ static void __init sun6i_rtc_clk_init(struct device_node *node)
>>  	rtc->base = of_io_request_and_map(node, 0, of_node_full_name(node));
>>  	if (IS_ERR(rtc->base)) {
>>  		pr_crit("Can't map RTC registers");
>> -		return;
>> +		goto err;
>>  	}
>>  
>>  	/* Switch to the external, more precise, oscillator */
>> @@ -216,7 +216,7 @@ static void __init sun6i_rtc_clk_init(struct device_node *node)
>>  
>>  	/* Deal with old DTs */
>>  	if (!of_get_property(node, "clocks", NULL))
>> -		return;
>> +		goto err;
>>  
>>  	rtc->int_osc = clk_hw_register_fixed_rate_with_accuracy(NULL,
>>  								"rtc-int-osc",
>> @@ -246,6 +246,10 @@ static void __init sun6i_rtc_clk_init(struct device_node *node)
>>  	clk_data->num = 1;
>>  	clk_data->hws[0] = &rtc->hw;
>>  	of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
>> +	return;
>> +
>> +err:
>> +	kfree(clk_data);
>>  }
>>  CLK_OF_DECLARE_DRIVER(sun6i_rtc_clk, "allwinner,sun6i-a31-rtc",
>>  		      sun6i_rtc_clk_init);
>> -- 
>> 2.11.0
>>
> 

[toc] | [prev] | [next] | [standalone]


#1699545

FromAlexandre Belloni <alexandre.belloni@free-electrons.com>
Date2017-07-30 17:00 +0200
Message-ID<u8XRg-1Dp-13@gated-at.bofh.it>
In reply to#1692062
On 19/07/2017 at 18:48:27 +0100, Colin Ian King wrote:
> On 19/07/17 18:32, Alexandre Belloni wrote:
> > Hi,
> > 
> > On 19/07/2017 at 17:57:02 +0100, Colin King wrote:
> >> From: Colin Ian King <colin.king@canonical.com>
> >>
> >> There are two error return paths that do not kfree clk_data and
> >> we end up with a memory leak. Fix these with a kfree error exit
> >> path.
> >>
> >> Detected by CoverityScan, CID#1402959 ("Resource Leak")
> >>
> > 
> > I think that patch fixes the same issue (and more):
> > http://patchwork.ozlabs.org/patch/787151/
> 
> Yep, that's true.
> 

Actually, I'm taking your patch now because it is the correct thing to
do.

> > 
> >> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> >> ---
> >>  drivers/rtc/rtc-sun6i.c | 8 ++++++--
> >>  1 file changed, 6 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/rtc/rtc-sun6i.c b/drivers/rtc/rtc-sun6i.c
> >> index 39cbc1238b92..61502221ab6e 100644
> >> --- a/drivers/rtc/rtc-sun6i.c
> >> +++ b/drivers/rtc/rtc-sun6i.c
> >> @@ -204,7 +204,7 @@ static void __init sun6i_rtc_clk_init(struct device_node *node)
> >>  	rtc->base = of_io_request_and_map(node, 0, of_node_full_name(node));
> >>  	if (IS_ERR(rtc->base)) {
> >>  		pr_crit("Can't map RTC registers");
> >> -		return;
> >> +		goto err;
> >>  	}
> >>  
> >>  	/* Switch to the external, more precise, oscillator */
> >> @@ -216,7 +216,7 @@ static void __init sun6i_rtc_clk_init(struct device_node *node)
> >>  
> >>  	/* Deal with old DTs */
> >>  	if (!of_get_property(node, "clocks", NULL))
> >> -		return;
> >> +		goto err;
> >>  
> >>  	rtc->int_osc = clk_hw_register_fixed_rate_with_accuracy(NULL,
> >>  								"rtc-int-osc",
> >> @@ -246,6 +246,10 @@ static void __init sun6i_rtc_clk_init(struct device_node *node)
> >>  	clk_data->num = 1;
> >>  	clk_data->hws[0] = &rtc->hw;
> >>  	of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
> >> +	return;
> >> +
> >> +err:
> >> +	kfree(clk_data);
> >>  }
> >>  CLK_OF_DECLARE_DRIVER(sun6i_rtc_clk, "allwinner,sun6i-a31-rtc",
> >>  		      sun6i_rtc_clk_init);
> >> -- 
> >> 2.11.0
> >>
> > 
> 

-- 
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web