* [PATCH 1/2] clk: imx: Manage the OF clock providers for i.MX8M and i.MX93
2026-11-28 9:45 [PATCH 0/2] clk: imx: Manage OF clock provider lifetimes Guangshuo Li
@ 2026-11-28 9:45 ` Guangshuo Li
2026-11-28 9:45 ` [PATCH 2/2] clk: imxrt1050: Fix potential use-after-free on unbind Guangshuo Li
1 sibling, 0 replies; 4+ messages in thread
From: Guangshuo Li @ 2026-11-28 9:45 UTC (permalink / raw)
To: abelvesa, sboyd, bmasney+clk, jbrunet+clk, Frank.Li, s.hauer,
m202171776, peng.fan, dzm91, lyx2022, zero12113, mr.bossman075
Cc: kernel, festevam, linux-clk, imx, linux-arm-kernel
The i.MX8MN, i.MX8MP, i.MX8MQ and i.MX93 clock drivers register an OF
provider backed by a device-managed lookup table. When a modular
controller can be unloaded, the provider survives the table it points
to.
Manage the provider on the same device so OF stops exposing the clock
table before devres frees it.
This issue was found by our static analysis tool under development.
Fixes: 188d070de913 ("clk: imx: clk-imx8mn: fix memory leak in imx8mn_clocks_probe")
Fixes: 878b02d5f3b5 ("clk: imx: clk-imx8mp: improve error handling in imx8mp_clocks_probe()")
Fixes: 577ad169966e ("clk: imx: imx8mq: correct error handling path")
Fixes: e02ba11b4576 ("clk: imx93: fix memory leak and missing unwind goto in imx93_clocks_probe")
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
drivers/clk/imx/clk-imx8mn.c | 2 +-
drivers/clk/imx/clk-imx8mp.c | 2 +-
drivers/clk/imx/clk-imx8mq.c | 2 +-
drivers/clk/imx/clk-imx93.c | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/clk/imx/clk-imx8mn.c b/drivers/clk/imx/clk-imx8mn.c
index 9d4c3064dd2c..3d9f54c00d34 100644
--- a/drivers/clk/imx/clk-imx8mn.c
+++ b/drivers/clk/imx/clk-imx8mn.c
@@ -596,7 +596,7 @@ static int imx8mn_clocks_probe(struct platform_device *pdev)
imx_check_clk_hws(hws, IMX8MN_CLK_END);
- ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_hw_data);
+ ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, clk_hw_data);
if (ret < 0) {
dev_err(dev, "failed to register hws for i.MX8MN\n");
goto unregister_hws;
diff --git a/drivers/clk/imx/clk-imx8mp.c b/drivers/clk/imx/clk-imx8mp.c
index c621beb1fa0a..a41616776dc7 100644
--- a/drivers/clk/imx/clk-imx8mp.c
+++ b/drivers/clk/imx/clk-imx8mp.c
@@ -866,7 +866,7 @@ static int imx8mp_clocks_probe(struct platform_device *pdev)
imx8mp_clocks_apply_constraints(imx8mp_clock_overdrive_constraints);
}
- err = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_hw_data);
+ err = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, clk_hw_data);
if (err < 0) {
dev_err(dev, "failed to register hws for i.MX8MP\n");
imx_unregister_hw_clocks(hws, IMX8MP_CLK_END);
diff --git a/drivers/clk/imx/clk-imx8mq.c b/drivers/clk/imx/clk-imx8mq.c
index a1f34e05ef77..ddb2d4a43ce4 100644
--- a/drivers/clk/imx/clk-imx8mq.c
+++ b/drivers/clk/imx/clk-imx8mq.c
@@ -598,7 +598,7 @@ static int imx8mq_clocks_probe(struct platform_device *pdev)
imx_check_clk_hws(hws, IMX8MQ_CLK_END);
- err = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_hw_data);
+ err = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, clk_hw_data);
if (err < 0) {
dev_err(dev, "failed to register hws for i.MX8MQ\n");
goto unregister_hws;
diff --git a/drivers/clk/imx/clk-imx93.c b/drivers/clk/imx/clk-imx93.c
index 1f10833659df..8c7373ca4441 100644
--- a/drivers/clk/imx/clk-imx93.c
+++ b/drivers/clk/imx/clk-imx93.c
@@ -354,7 +354,7 @@ static int imx93_clocks_probe(struct platform_device *pdev)
imx_check_clk_hws(clks, IMX93_CLK_END);
- ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_hw_data);
+ ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, clk_hw_data);
if (ret < 0) {
dev_err(dev, "failed to register clks for i.MX93\n");
goto unregister_hws;
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/2] clk: imxrt1050: Fix potential use-after-free on unbind
2026-11-28 9:45 [PATCH 0/2] clk: imx: Manage OF clock provider lifetimes Guangshuo Li
2026-11-28 9:45 ` [PATCH 1/2] clk: imx: Manage the OF clock providers for i.MX8M and i.MX93 Guangshuo Li
@ 2026-11-28 9:45 ` Guangshuo Li
2026-11-28 9:53 ` sashiko-bot
1 sibling, 1 reply; 4+ messages in thread
From: Guangshuo Li @ 2026-11-28 9:45 UTC (permalink / raw)
To: abelvesa, sboyd, bmasney+clk, jbrunet+clk, Frank.Li, s.hauer,
m202171776, peng.fan, dzm91, lyx2022, zero12113, mr.bossman075
Cc: kernel, festevam, linux-clk, imx, linux-arm-kernel
The OF clock provider retains the managed onecell data after the
driver is unbound. Subsequent clock lookups can access freed memory.
Manage the provider so it is removed before the onecell data is freed.
This issue was found by our static analysis tool under development.
Fixes: 7154b046d8f3 ("clk: imx: Add initial support for i.MXRT1050 clock driver")
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
drivers/clk/imx/clk-imxrt1050.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/clk/imx/clk-imxrt1050.c b/drivers/clk/imx/clk-imxrt1050.c
index db152c66d66f..28f4534cbeff 100644
--- a/drivers/clk/imx/clk-imxrt1050.c
+++ b/drivers/clk/imx/clk-imxrt1050.c
@@ -150,7 +150,7 @@ static int imxrt1050_clocks_probe(struct platform_device *pdev)
hws[IMXRT1050_CLK_DMA_MUX] = imx_clk_hw_gate("dmamux0", "ipg", ccm_base + 0x7C, 7);
imx_check_clk_hws(hws, IMXRT1050_CLK_END);
- ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_hw_data);
+ ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, clk_hw_data);
if (ret < 0) {
dev_err(dev, "Failed to register clks for i.MXRT1050.\n");
goto unregister_hws;
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread