Linux clock framework development
 help / color / mirror / Atom feed
* [PATCH] clk: nuvoton: Manage MA35D1 mux clocks with the controller
@ 2026-11-26  8:26 Guangshuo Li
  2026-11-26  8:32 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2026-11-26  8:26 UTC (permalink / raw)
  To: ychuang3, schung, sboyd, bmasney+clk, jbrunet+clk, arnd, krzk
  Cc: linux-arm-kernel, linux-clk

The MA35D1 muxes remain registered after the platform device releases
their register mapping. Use managed registration so both mux helpers
unregister their clocks before the registers are unmapped.

This issue was found by our static analysis tool under development.

Fixes: 691521a367cf ("clk: nuvoton: Add clock driver for ma35d1 clock controller")
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
 drivers/clk/nuvoton/clk-ma35d1.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/nuvoton/clk-ma35d1.c b/drivers/clk/nuvoton/clk-ma35d1.c
index e95f72bb8103..4428556b64ad 100644
--- a/drivers/clk/nuvoton/clk-ma35d1.c
+++ b/drivers/clk/nuvoton/clk-ma35d1.c
@@ -380,9 +380,9 @@ static struct clk_hw *ma35d1_clk_mux_parent(struct device *dev, const char *name
 					    const struct clk_parent_data *pdata,
 					    int num_pdata)
 {
-	return clk_hw_register_mux_parent_data(dev, name, pdata, num_pdata,
-					       CLK_SET_RATE_NO_REPARENT, reg, shift,
-					       width, 0, &ma35d1_lock);
+	return devm_clk_hw_register_mux_parent_data_table(dev, name, pdata, num_pdata,
+							  CLK_SET_RATE_NO_REPARENT, reg, shift,
+							  width, 0, NULL, &ma35d1_lock);
 }
 
 static struct clk_hw *ma35d1_clk_mux(struct device *dev, const char *name,
@@ -390,9 +390,9 @@ static struct clk_hw *ma35d1_clk_mux(struct device *dev, const char *name,
 				     const struct clk_parent_data *pdata,
 				     int num_pdata)
 {
-	return clk_hw_register_mux_parent_data(dev, name, pdata, num_pdata,
-					       CLK_SET_RATE_NO_REPARENT, reg, shift,
-					       width, 0, &ma35d1_lock);
+	return devm_clk_hw_register_mux_parent_data_table(dev, name, pdata, num_pdata,
+							  CLK_SET_RATE_NO_REPARENT, reg, shift,
+							  width, 0, NULL, &ma35d1_lock);
 }
 
 static struct clk_hw *ma35d1_clk_divider(struct device *dev, const char *name,

base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5
-- 
2.43.0


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

* Re: [PATCH] clk: nuvoton: Manage MA35D1 mux clocks with the controller
  2026-11-26  8:26 [PATCH] clk: nuvoton: Manage MA35D1 mux clocks with the controller Guangshuo Li
@ 2026-11-26  8:32 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-26  8:32 UTC (permalink / raw)
  To: Guangshuo Li; +Cc: linux-clk

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] clk: nuvoton: use-after-free in ma35d1_clocks_probe() [1]
--

commit 9ff45d0263efa96de1be9a7ff0a42ea74ccdf3fa
Author: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>

clk: nuvoton: Manage MA35D1 mux clocks with the controller

This commit converts ma35d1_clk_mux_parent() and ma35d1_clk_mux() to use
devm_clk_hw_register_mux_parent_data_table() so that the mux clocks are
automatically unregistered when the platform device is removed.

> diff --git a/drivers/clk/nuvoton/clk-ma35d1.c b/drivers/clk/nuvoton/clk-ma35d1.c
> index e95f72bb81032..4428556b64ade 100644
> --- a/drivers/clk/nuvoton/clk-ma35d1.c
> +++ b/drivers/clk/nuvoton/clk-ma35d1.c
> @@ -380,9 +380,9 @@ static struct clk_hw *ma35d1_clk_mux_parent(struct device *dev, const char *name
>  					    const struct clk_parent_data *pdata,
>  					    int num_pdata)
>  {
> -	return clk_hw_register_mux_parent_data(dev, name, pdata, num_pdata,
> -					       CLK_SET_RATE_NO_REPARENT, reg, shift,
> -					       width, 0, &ma35d1_lock);
> +	return devm_clk_hw_register_mux_parent_data_table(dev, name, pdata, num_pdata,
> +							  CLK_SET_RATE_NO_REPARENT, reg, shift,
> +							  width, 0, NULL, &ma35d1_lock);
>  }
>  
>  static struct clk_hw *ma35d1_clk_mux(struct device *dev, const char *name,
> @@ -390,9 +390,9 @@ static struct clk_hw *ma35d1_clk_mux(struct device *dev, const char *name,
>  				     const struct clk_parent_data *pdata,
>  				     int num_pdata)
>  {
> -	return clk_hw_register_mux_parent_data(dev, name, pdata, num_pdata,
> -					       CLK_SET_RATE_NO_REPARENT, reg, shift,
> -					       width, 0, &ma35d1_lock);
> +	return devm_clk_hw_register_mux_parent_data_table(dev, name, pdata, num_pdata,
> +							  CLK_SET_RATE_NO_REPARENT, reg, shift,
> +							  width, 0, NULL, &ma35d1_lock);
>  }

[Severity: Critical]
This problem wasn't introduced by this patch, but right above
ma35d1_clk_mux_parent(), doesn't ma35d1_clk_fixed() also leave its clocks
registered on probe failure or driver unbind [1]?

drivers/clk/nuvoton/clk-ma35d1.c:ma35d1_clk_fixed() {
	return clk_hw_register_fixed_rate(NULL, name, NULL, 0, rate);
}

Because ma35d1_clk_fixed() uses the unmanaged
clk_hw_register_fixed_rate() helper instead of
devm_clk_hw_register_fixed_rate(), the fixed-rate clocks remain
registered in the clock framework and leak after ma35d1_clocks_probe()
fails or the device is unbound.

[1] https://sashiko.dev/#/bug/linux-0fffc72d-3bbf-4403-b81b-eac9ff603015

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-a35bb25eb5-u10-0@mail.sdu.edu.cn?part=1

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

end of thread, other threads:[~2026-11-26  8:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26  8:26 [PATCH] clk: nuvoton: Manage MA35D1 mux clocks with the controller Guangshuo Li
2026-11-26  8:32 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox