[PATCH 3/3] clk: sunxi: Fix potential use-after-free of APB0 provider data

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


Unbinding the APB0 gates driver releases its managed onecell data but
leaves the OF provider registered. Later clock lookups can dereference
the released data.

Remove the provider before the managed data is freed.

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

Fixes: c8a76cac19ee ("clk: sunxi: add PRCM (Power/Reset/Clock Management) clks support")
Signed-off-by: Guangshuo Li <liguangshuo at mail.sdu.edu.cn>
---
 drivers/clk/sunxi/clk-sun6i-apb0-gates.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/clk/sunxi/clk-sun6i-apb0-gates.c b/drivers/clk/sunxi/clk-sun6i-apb0-gates.c
index a10ebd1998fb..9d1fef8c520e 100644
--- a/drivers/clk/sunxi/clk-sun6i-apb0-gates.c
+++ b/drivers/clk/sunxi/clk-sun6i-apb0-gates.c
@@ -87,11 +87,17 @@ static int sun6i_a31_apb0_gates_clk_probe(struct platform_device *pdev)
 	return of_clk_add_provider(np, of_clk_src_onecell_get, clk_data);
 }
 
+static void sun6i_a31_apb0_gates_clk_remove(struct platform_device *pdev)
+{
+	of_clk_del_provider(pdev->dev.of_node);
+}
+
 static struct platform_driver sun6i_a31_apb0_gates_clk_driver = {
 	.driver = {
 		.name = "sun6i-a31-apb0-gates-clk",
 		.of_match_table = sun6i_a31_apb0_gates_clk_dt_ids,
 	},
 	.probe = sun6i_a31_apb0_gates_clk_probe,
+	.remove = sun6i_a31_apb0_gates_clk_remove,
 };
 builtin_platform_driver(sun6i_a31_apb0_gates_clk_driver);

-- 
2.43.0



More information about the linux-arm-kernel mailing list