linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtc: amlogic-a4: fix double free caused by devm
@ 2025-10-20 15:09 Haotian Zhang
  2025-10-21  9:29 ` kernel test robot
  2025-10-21 10:35 ` [PATCH v2] " Haotian Zhang
  0 siblings, 2 replies; 5+ messages in thread
From: Haotian Zhang @ 2025-10-20 15:09 UTC (permalink / raw)
  To: Yiting Deng, Xianwei Zhao, Alexandre Belloni
  Cc: linux-amlogic, linux-rtc, linux-kernel, stable, Haotian Zhang

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>
---
 drivers/rtc/rtc-amlogic-a4.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/rtc/rtc-amlogic-a4.c b/drivers/rtc/rtc-amlogic-a4.c
index 1928b29c1045..ed36b649c057 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;
@@ -425,7 +424,6 @@ 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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] rtc: amlogic-a4: fix double free caused by devm
  2025-10-20 15:09 [PATCH] rtc: amlogic-a4: fix double free caused by devm Haotian Zhang
@ 2025-10-21  9:29 ` kernel test robot
  2025-10-21 10:35 ` [PATCH v2] " Haotian Zhang
  1 sibling, 0 replies; 5+ messages in thread
From: kernel test robot @ 2025-10-21  9:29 UTC (permalink / raw)
  To: Haotian Zhang, Yiting Deng, Xianwei Zhao, Alexandre Belloni
  Cc: llvm, oe-kbuild-all, linux-amlogic, linux-rtc, linux-kernel,
	stable, Haotian Zhang

Hi Haotian,

kernel test robot noticed the following build warnings:

[auto build test WARNING on abelloni/rtc-next]
[also build test WARNING on linus/master v6.18-rc2 next-20251021]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Haotian-Zhang/rtc-amlogic-a4-fix-double-free-caused-by-devm/20251020-231345
base:   https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git rtc-next
patch link:    https://lore.kernel.org/r/20251020150956.491-1-vulab%40iscas.ac.cn
patch subject: [PATCH] rtc: amlogic-a4: fix double free caused by devm
config: i386-buildonly-randconfig-002-20251021 (https://download.01.org/0day-ci/archive/20251021/202510211756.vnQ8ZIWo-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251021/202510211756.vnQ8ZIWo-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202510211756.vnQ8ZIWo-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/rtc/rtc-amlogic-a4.c:425:23: warning: unused variable 'rtc' [-Wunused-variable]
     425 |         struct aml_rtc_data *rtc = dev_get_drvdata(&pdev->dev);
         |                              ^~~
   1 warning generated.


vim +/rtc +425 drivers/rtc/rtc-amlogic-a4.c

c89ac9182ee297 Yiting Deng  2024-11-12  419  
c89ac9182ee297 Yiting Deng  2024-11-12  420  static SIMPLE_DEV_PM_OPS(aml_rtc_pm_ops,
c89ac9182ee297 Yiting Deng  2024-11-12  421  			 aml_rtc_suspend, aml_rtc_resume);
c89ac9182ee297 Yiting Deng  2024-11-12  422  
c89ac9182ee297 Yiting Deng  2024-11-12  423  static void aml_rtc_remove(struct platform_device *pdev)
c89ac9182ee297 Yiting Deng  2024-11-12  424  {
c89ac9182ee297 Yiting Deng  2024-11-12 @425  	struct aml_rtc_data *rtc = dev_get_drvdata(&pdev->dev);
c89ac9182ee297 Yiting Deng  2024-11-12  426  
8c28c4993f117e Wolfram Sang 2024-12-17  427  	device_init_wakeup(&pdev->dev, false);
c89ac9182ee297 Yiting Deng  2024-11-12  428  }
c89ac9182ee297 Yiting Deng  2024-11-12  429  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] rtc: amlogic-a4: fix double free caused by devm
  2025-10-20 15:09 [PATCH] rtc: amlogic-a4: fix double free caused by devm Haotian Zhang
  2025-10-21  9:29 ` kernel test robot
@ 2025-10-21 10:35 ` Haotian Zhang
  2025-10-22  5:48   ` Xianwei Zhao
  2025-10-31 23:02   ` Alexandre Belloni
  1 sibling, 2 replies; 5+ messages in thread
From: Haotian Zhang @ 2025-10-21 10:35 UTC (permalink / raw)
  To: alexandre.belloni, yiting.deng, xianwei.zhao
  Cc: linux-amlogic, linux-rtc, linux-kernel, Haotian Zhang

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] rtc: amlogic-a4: fix double free caused by devm
  2025-10-21 10:35 ` [PATCH v2] " Haotian Zhang
@ 2025-10-22  5:48   ` Xianwei Zhao
  2025-10-31 23:02   ` Alexandre Belloni
  1 sibling, 0 replies; 5+ messages in thread
From: Xianwei Zhao @ 2025-10-22  5:48 UTC (permalink / raw)
  To: Haotian Zhang, alexandre.belloni, yiting.deng
  Cc: linux-amlogic, linux-rtc, linux-kernel

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
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] rtc: amlogic-a4: fix double free caused by devm
  2025-10-21 10:35 ` [PATCH v2] " Haotian Zhang
  2025-10-22  5:48   ` Xianwei Zhao
@ 2025-10-31 23:02   ` Alexandre Belloni
  1 sibling, 0 replies; 5+ messages in thread
From: Alexandre Belloni @ 2025-10-31 23:02 UTC (permalink / raw)
  To: yiting.deng, xianwei.zhao, Haotian Zhang
  Cc: linux-amlogic, linux-rtc, linux-kernel

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-10-31 23:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-20 15:09 [PATCH] rtc: amlogic-a4: fix double free caused by devm Haotian Zhang
2025-10-21  9:29 ` kernel test robot
2025-10-21 10:35 ` [PATCH v2] " Haotian Zhang
2025-10-22  5:48   ` Xianwei Zhao
2025-10-31 23:02   ` Alexandre Belloni

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).