[PATCH] clk: imx: imx95-blk-ctl: Fix clock leak in error paths
Haotian Zhang
vulab at iscas.ac.cn
Tue Nov 11 03:41:23 PST 2025
The probe function enables bc->clk_apb early but fails to disable it
when bc_data is NULL or clk_hw_data allocation fails. The cleanup
path also misses pm_runtime_put_sync() when rpm is enabled.
Add err_disable_clk label to ensure clk_disable_unprepare() is called
on all error paths. Add pm_runtime_put_sync() in cleanup path when rpm
is enabled.
Fixes: 5224b189462f ("clk: imx: add i.MX95 BLK CTL clk driver")
Signed-off-by: Haotian Zhang <vulab at iscas.ac.cn>
---
drivers/clk/imx/clk-imx95-blk-ctl.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/drivers/clk/imx/clk-imx95-blk-ctl.c b/drivers/clk/imx/clk-imx95-blk-ctl.c
index 7e88877a6245..b12aded2b304 100644
--- a/drivers/clk/imx/clk-imx95-blk-ctl.c
+++ b/drivers/clk/imx/clk-imx95-blk-ctl.c
@@ -380,13 +380,19 @@ static int imx95_bc_probe(struct platform_device *pdev)
}
bc_data = of_device_get_match_data(dev);
- if (!bc_data)
- return devm_of_platform_populate(dev);
+ if (!bc_data) {
+ ret = devm_of_platform_populate(dev);
+ if (ret)
+ clk_disable_unprepare(bc->clk_apb);
+ return ret;
+ }
clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws, bc_data->num_clks),
GFP_KERNEL);
- if (!clk_hw_data)
- return -ENOMEM;
+ if (!clk_hw_data) {
+ ret = -ENOMEM;
+ goto err_disable_clk;
+ }
if (bc_data->rpm_enabled) {
devm_pm_runtime_enable(&pdev->dev);
@@ -444,7 +450,11 @@ static int imx95_bc_probe(struct platform_device *pdev)
continue;
clk_hw_unregister(hws[i]);
}
+ if (bc_data->rpm_enabled && pm_runtime_enabled(bc->dev))
+ pm_runtime_put_sync(&pdev->dev);
+err_disable_clk:
+ clk_disable_unprepare(bc->clk_apb);
return ret;
}
--
2.50.1.windows.1
More information about the linux-arm-kernel
mailing list