[PATCH 1/3] clk: sunxi: Release the platform mod0 clock before unmapping it

Guangshuo Li liguangshuo at mail.sdu.edu.cn
Sat Nov 28 01:39:51 PST 2026


The mod0 platform driver leaves the composite clock and its OF provider
registered when devres unmaps the clock registers. Save the clock
created by the platform probe and unregister it on remove.

The unregister helper receives the composite clk_hw. Use its rate
component to recover the factors, then release the composite and its
parts.

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

Fixes: 6ea3953da4e6 ("clk: sunxi: Make the mod0 clk driver also a platform driver")
Fixes: 4cbeaebb8af1 ("clk: sunxi: factors: Add unregister function")
Signed-off-by: Guangshuo Li <liguangshuo at mail.sdu.edu.cn>
---
 drivers/clk/sunxi/clk-factors.c |  5 ++---
 drivers/clk/sunxi/clk-mod0.c    | 12 ++++++++++--
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/clk/sunxi/clk-factors.c b/drivers/clk/sunxi/clk-factors.c
index 149187f189d6..14a84534011e 100644
--- a/drivers/clk/sunxi/clk-factors.c
+++ b/drivers/clk/sunxi/clk-factors.c
@@ -293,11 +293,10 @@ void sunxi_factors_unregister(struct device_node *node, struct clk *clk)
 	if (!hw)
 		return;
 
-	factors = to_clk_factors(hw);
+	factors = to_clk_factors(to_clk_composite(hw)->rate_hw);
 
 	of_clk_del_provider(node);
-	/* TODO: The composite clock stuff will leak a bit here. */
-	clk_unregister(clk);
+	clk_unregister_composite(clk);
 	kfree(factors->mux);
 	kfree(factors->gate);
 	kfree(factors);
diff --git a/drivers/clk/sunxi/clk-mod0.c b/drivers/clk/sunxi/clk-mod0.c
index b409a8d70962..e9ecdbe02fe8 100644
--- a/drivers/clk/sunxi/clk-mod0.c
+++ b/drivers/clk/sunxi/clk-mod0.c
@@ -89,6 +89,7 @@ static int sun4i_a10_mod0_clk_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
 	void __iomem *reg;
+	struct clk *clk;
 
 	if (!np)
 		return -ENODEV;
@@ -97,11 +98,17 @@ static int sun4i_a10_mod0_clk_probe(struct platform_device *pdev)
 	if (IS_ERR(reg))
 		return PTR_ERR(reg);
 
-	sunxi_factors_register(np, &sun4i_a10_mod0_data,
-			       &sun4i_a10_mod0_lock, reg);
+	clk = sunxi_factors_register(np, &sun4i_a10_mod0_data,
+				     &sun4i_a10_mod0_lock, reg);
+	platform_set_drvdata(pdev, clk);
 	return 0;
 }
 
+static void sun4i_a10_mod0_clk_remove(struct platform_device *pdev)
+{
+	sunxi_factors_unregister(pdev->dev.of_node, platform_get_drvdata(pdev));
+}
+
 static const struct of_device_id sun4i_a10_mod0_clk_dt_ids[] = {
 	{ .compatible = "allwinner,sun4i-a10-mod0-clk" },
 	{ /* sentinel */ }
@@ -113,6 +120,7 @@ static struct platform_driver sun4i_a10_mod0_clk_driver = {
 		.of_match_table = sun4i_a10_mod0_clk_dt_ids,
 	},
 	.probe = sun4i_a10_mod0_clk_probe,
+	.remove = sun4i_a10_mod0_clk_remove,
 };
 builtin_platform_driver(sun4i_a10_mod0_clk_driver);
 

-- 
2.43.0




More information about the linux-arm-kernel mailing list