clk: imx: imx95-blk-ctl: Fix clock leak in error paths
Subsystems (3)
PATCH 1/1 clk: imx: imx95-blk-ctl: Fix clock leak in error paths
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.
--- drivers/clk/imx/clk-imx95-blk-ctl.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/clk/imx/clk-imx95-blk-ctl.c +14 -4
@@ -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; }
Signature · 1 line
2.50.1.windows.1
Peng Fan
reviewerQuoted 24 lines
Subject: [PATCH] clk: imx: imx95-blk-ctl: Fix clock leak in error paths
The probe function enables
bc->clk_apbearly but fails to disable it whenbc_datais NULL orclk_hw_dataallocation fails. The cleanup path also missespm_runtime_put_sync()when rpm is enabled.Add
err_disable_clklabel to ensureclk_disable_unprepare()is called on all error paths. Addpm_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 <[email protected]>--- drivers/clk/imx/clk-imx95-blk-ctl.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)drivers/clk/imx/clk- renamed from drivers/clk/imx/clk-imx95-blk-ctl.c +0
-0
imx95-blk-ctl.c
index7e88877a6245..b12aded2b304100644drivers/clk/imx/clk-imx95-blk-ctl.c +0
-0@@ -380,13 +380,19 @@ static int imx95_bc_probe(struct platform_device *pdev) }
drivers/clk/imx/clk-imx95-blk-ctl.c static int imx95_bc_probe(struct · line 389
Quoted 10 lines
drivers/clk/imx/clk-imx95-blk-ctl.c +6
-2bc_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; + }
Use devm_clk_get_enabled to replace devm_clk_get and clk_prepare_enable. Then things could be simplified.
Regards
Peng.
Quoted 28 lines
drivers/clk/imx/clk-imx95-blk-ctl.c +4
-2clk_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) {drivers/clk/imx/clk-imx95-blk-ctl.c +4
-1devm_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
PATCH v2 1/1 clk: imx: imx95-blk-ctl: Fix clock leak in error paths
In reply to Haotian ZhangThe 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.
---
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(-)
drivers/clk/imx/clk-imx95-blk-ctl.c +4 -10
@@ -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; }
Signature · 1 line
2.50.1.windows.1
Quoted 11 lines · Haotian Zhang
The probe function enables
bc->clk_apbearly but fails to disable it whenbc_datais NULL orclk_hw_dataallocation fails. The cleanup path also missespm_runtime_put_sync()when rpm is enabled.Switch to
devm_clk_get_enabled()to automatically manage the clock resource. Addpm_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 <[email protected]>Signed-off-by Haotian Zhang <[email protected]>
Next time, please do not send the new version as a reply to the old one.
Everything else LGTM: