drivers/clk/imx/clk-imx95-blk-ctl.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
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@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
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.
Switch to devm_clk_get_enabled() to automatically manage the clock
resource. Add pm_runtime_put_sync() in cleanup path when rpm
is enabled.
Fixes: 5224b189462f ("clk: imx: add i.MX95 BLK CTL clk driver")
Suggested-by: Peng Fan <peng.fan@nxp.com>
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
Changes in v2:
-Use devm_clk_get_enabled() instead of manual error path cleanup
---
drivers/clk/imx/clk-imx95-blk-ctl.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/drivers/clk/imx/clk-imx95-blk-ctl.c b/drivers/clk/imx/clk-imx95-blk-ctl.c
index 7e88877a6245..5fdc2af7176e 100644
--- a/drivers/clk/imx/clk-imx95-blk-ctl.c
+++ b/drivers/clk/imx/clk-imx95-blk-ctl.c
@@ -369,16 +369,10 @@ static int imx95_bc_probe(struct platform_device *pdev)
return PTR_ERR(base);
bc->base = base;
- bc->clk_apb = devm_clk_get(dev, NULL);
+ bc->clk_apb = devm_clk_get_enabled(dev, NULL);
if (IS_ERR(bc->clk_apb))
return dev_err_probe(dev, PTR_ERR(bc->clk_apb), "failed to get APB clock\n");
- ret = clk_prepare_enable(bc->clk_apb);
- if (ret) {
- dev_err(dev, "failed to enable apb clock: %d\n", ret);
- return ret;
- }
-
bc_data = of_device_get_match_data(dev);
if (!bc_data)
return devm_of_platform_populate(dev);
@@ -431,10 +425,8 @@ static int imx95_bc_probe(struct platform_device *pdev)
goto cleanup;
}
- if (pm_runtime_enabled(bc->dev)) {
+ if (pm_runtime_enabled(bc->dev))
pm_runtime_put_sync(&pdev->dev);
- clk_disable_unprepare(bc->clk_apb);
- }
return 0;
@@ -444,6 +436,8 @@ 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);
return ret;
}
--
2.50.1.windows.1
On 25-11-12 10:30:25, Haotian Zhang wrote:
> 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.
>
> Switch to devm_clk_get_enabled() to automatically manage the clock
> resource. Add pm_runtime_put_sync() in cleanup path when rpm
> is enabled.
>
> Fixes: 5224b189462f ("clk: imx: add i.MX95 BLK CTL clk driver")
> Suggested-by: Peng Fan <peng.fan@nxp.com>
> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
Next time, please do not send the new version as a reply to the old one.
Everything else LGTM:
Reviewed-by: Abel Vesa <abel.vesa@linaro.org>
© 2016 - 2026 Red Hat, Inc.