[PATCH v2] rtc: amlogic-a4: fix double free caused by devm

Haotian Zhang posted 1 patch 3 months, 2 weeks ago
drivers/rtc/rtc-amlogic-a4.c | 4 ----
1 file changed, 4 deletions(-)
[PATCH v2] rtc: amlogic-a4: fix double free caused by devm
Posted by Haotian Zhang 3 months, 2 weeks ago
The clock obtained via devm_clk_get_enabled() is automatically managed
by devres and will be disabled and freed on driver detach. Manually
calling clk_disable_unprepare() in error path and remove function
causes double free.

Remove the redundant clk_disable_unprepare() calls from the probe
error path and aml_rtc_remove(), allowing the devm framework to
automatically manage the clock lifecycle.

Fixes: c89ac9182ee2 ("rtc: support for the Amlogic on-chip RTC")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
v2: Also remove the now-unused local variable 'rtc' in aml_rtc_remove()
---
 drivers/rtc/rtc-amlogic-a4.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/rtc/rtc-amlogic-a4.c b/drivers/rtc/rtc-amlogic-a4.c
index 1928b29c1045..a993d35e1d6b 100644
--- a/drivers/rtc/rtc-amlogic-a4.c
+++ b/drivers/rtc/rtc-amlogic-a4.c
@@ -390,7 +390,6 @@ static int aml_rtc_probe(struct platform_device *pdev)
 
 	return 0;
 err_clk:
-	clk_disable_unprepare(rtc->sys_clk);
 	device_init_wakeup(dev, false);
 
 	return ret;
@@ -423,9 +422,6 @@ static SIMPLE_DEV_PM_OPS(aml_rtc_pm_ops,
 
 static void aml_rtc_remove(struct platform_device *pdev)
 {
-	struct aml_rtc_data *rtc = dev_get_drvdata(&pdev->dev);
-
-	clk_disable_unprepare(rtc->sys_clk);
 	device_init_wakeup(&pdev->dev, false);
 }
 
-- 
2.25.1
Re: [PATCH v2] rtc: amlogic-a4: fix double free caused by devm
Posted by Alexandre Belloni 3 months, 1 week ago
On Tue, 21 Oct 2025 18:35:59 +0800, Haotian Zhang wrote:
> The clock obtained via devm_clk_get_enabled() is automatically managed
> by devres and will be disabled and freed on driver detach. Manually
> calling clk_disable_unprepare() in error path and remove function
> causes double free.
> 
> Remove the redundant clk_disable_unprepare() calls from the probe
> error path and aml_rtc_remove(), allowing the devm framework to
> automatically manage the clock lifecycle.
> 
> [...]

Applied, thanks!

[1/1] rtc: amlogic-a4: fix double free caused by devm
      https://git.kernel.org/abelloni/c/384150d7a5b6

Best regards,

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Re: [PATCH v2] rtc: amlogic-a4: fix double free caused by devm
Posted by Xianwei Zhao 3 months, 2 weeks ago
Reviewed-by: Xianwei Zhao <xianwei.zhao@amlogic.com>
On 2025/10/21 18:35, Haotian Zhang wrote:
> [Some people who received this message don't often get email from vulab@iscas.ac.cn. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
> 
> [ EXTERNAL EMAIL ]
> 
> The clock obtained via devm_clk_get_enabled() is automatically managed
> by devres and will be disabled and freed on driver detach. Manually
> calling clk_disable_unprepare() in error path and remove function
> causes double free.
> 
> Remove the redundant clk_disable_unprepare() calls from the probe
> error path and aml_rtc_remove(), allowing the devm framework to
> automatically manage the clock lifecycle.
> 
> Fixes: c89ac9182ee2 ("rtc: support for the Amlogic on-chip RTC")
> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
> ---
> v2: Also remove the now-unused local variable 'rtc' in aml_rtc_remove()
> ---
>   drivers/rtc/rtc-amlogic-a4.c | 4 ----
>   1 file changed, 4 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-amlogic-a4.c b/drivers/rtc/rtc-amlogic-a4.c
> index 1928b29c1045..a993d35e1d6b 100644
> --- a/drivers/rtc/rtc-amlogic-a4.c
> +++ b/drivers/rtc/rtc-amlogic-a4.c
> @@ -390,7 +390,6 @@ static int aml_rtc_probe(struct platform_device *pdev)
> 
>          return 0;
>   err_clk:
> -       clk_disable_unprepare(rtc->sys_clk);
>          device_init_wakeup(dev, false);
> 
>          return ret;
> @@ -423,9 +422,6 @@ static SIMPLE_DEV_PM_OPS(aml_rtc_pm_ops,
> 
>   static void aml_rtc_remove(struct platform_device *pdev)
>   {
> -       struct aml_rtc_data *rtc = dev_get_drvdata(&pdev->dev);
> -
> -       clk_disable_unprepare(rtc->sys_clk);
>          device_init_wakeup(&pdev->dev, false);
>   }
> 
> --
> 2.25.1
>