lkml.org 
[lkml]   [2021]   [Jan]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH 5.4 34/47] rtc: sun6i: Fix memleak in sun6i_rtc_clk_init
Hi!

> From: Dinghao Liu <dinghao.liu@zju.edu.cn>
>
> [ Upstream commit 28d211919e422f58c1e6c900e5810eee4f1ce4c8 ]
>
> When clk_hw_register_fixed_rate_with_accuracy() fails,
> clk_data should be freed. It's the same for the subsequent
> two error paths, but we should also unregister the already
> registered clocks in them.

This still leaks rtc, AFAICT. What is worse, sun6i_rtc will point to
invalid memory after the error exit.

Something like this?

Best regards,
Pavel

diff --git a/drivers/rtc/rtc-sun6i.c b/drivers/rtc/rtc-sun6i.c
index e85abe805606..59389bb99e39 100644
--- a/drivers/rtc/rtc-sun6i.c
+++ b/drivers/rtc/rtc-sun6i.c
@@ -211,6 +211,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");
+ kfree(rtc);
goto err;
}

@@ -272,6 +273,8 @@ static void __init sun6i_rtc_clk_init(struct device_node *node)
clk_hw_unregister_fixed_rate(rtc->int_osc);
err:
kfree(clk_data);
+ kfree(rtc);
+ sun6i_rtc = NULL;
}
CLK_OF_DECLARE_DRIVER(sun6i_rtc_clk, "allwinner,sun6i-a31-rtc",
sun6i_rtc_clk_init);
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2021-01-06 14:11    [W:0.223 / U:0.084 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site