mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] clk: imx: clk-imx95-blk-ctl: fix error unwinding in probe
@ 2026-11-11 11:02 Manush Prajwal
  0 siblings, 0 replies; only message in thread
From: Manush Prajwal @ 2026-11-11 11:02 UTC (permalink / raw)
  To: abelvesa, peng.fan, sboyd, mturquette
  Cc: s.hauer, Frank.Li, linux-clk, imx, linux-arm-kernel, linux-kernel

In imx95_bc_probe(), bc->clk_apb is enabled via clk_prepare_enable().
However, if subsequent operations fail:
1. When !bc->pdata, devm_of_platform_populate() failure returns directly
   without disabling bc->clk_apb.
2. When clk_hw_data allocation fails, probe returns -ENOMEM directly
   without disabling bc->clk_apb.
3. The return values of devm_pm_runtime_enable() and
   pm_runtime_resume_and_get() are ignored, potentially proceeding with
   an unresumed device or invalid runtime PM state.
4. If clock registration, of_clk_add_hw_provider(), or child
   devm_of_platform_populate() fails, execution jumps to cleanup:,
   which unregisters registered clocks but fails to drop the runtime PM
   reference acquired by pm_runtime_resume_and_get() and fails to call
   clk_disable_unprepare(bc->clk_apb).

Fix these issues by:
- Handling devm_of_platform_populate() failure on !bc->pdata by jumping
  to err_clk_disable.
- Jumping to err_clk_disable if clk_hw_data allocation fails.
- Checking the return values of devm_pm_runtime_enable() and
  pm_runtime_resume_and_get() and jumping to err_clk_disable on error.
- Calling pm_runtime_put_sync() in cleanup: if runtime PM is enabled.
- Adding err_clk_disable to call clk_disable_unprepare(bc->clk_apb).

Fixes: 5224b189462f ("clk: imx: add i.MX95 BLK CTL clk driver")
Fixes: b08217a25721 ("clk: imx95-blk-ctl: Fix synchronous abort")
Signed-off-by: Manush Prajwal <manushprajwal555@gmail.com>
---
 drivers/clk/imx/clk-imx95-blk-ctl.c | 30 +++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/imx/clk-imx95-blk-ctl.c b/drivers/clk/imx/clk-imx95-blk-ctl.c
index bc6957299..ad386a48e 100644
--- a/drivers/clk/imx/clk-imx95-blk-ctl.c
+++ b/drivers/clk/imx/clk-imx95-blk-ctl.c
@@ -394,17 +394,29 @@ static int imx95_bc_probe(struct platform_device *pdev)
 	}

 	bc->pdata = of_device_get_match_data(dev);
-	if (!bc->pdata)
-		return devm_of_platform_populate(dev);
+	if (!bc->pdata) {
+		ret = devm_of_platform_populate(dev);
+		if (ret)
+			goto err_clk_disable;
+
+		return 0;
+	}

 	clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws, bc->pdata->num_clks),
 				   GFP_KERNEL);
-	if (!clk_hw_data)
-		return -ENOMEM;
+	if (!clk_hw_data) {
+		ret = -ENOMEM;
+		goto err_clk_disable;
+	}

 	if (bc->pdata->rpm_enabled) {
-		devm_pm_runtime_enable(&pdev->dev);
-		pm_runtime_resume_and_get(&pdev->dev);
+		ret = devm_pm_runtime_enable(&pdev->dev);
+		if (ret)
+			goto err_clk_disable;
+
+		ret = pm_runtime_resume_and_get(&pdev->dev);
+		if (ret)
+			goto err_clk_disable;
 	}

 	clk_hw_data->num = bc->pdata->num_clks;
@@ -462,6 +474,12 @@ static int imx95_bc_probe(struct platform_device *pdev)
 		clk_hw_unregister(hws[i]);
 	}

+	if (pm_runtime_enabled(bc->dev))
+		pm_runtime_put_sync(&pdev->dev);
+
+err_clk_disable:
+	clk_disable_unprepare(bc->clk_apb);
+
 	return ret;
 }

-- 
2.46.2.windows.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-11 11:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-11 11:02 [PATCH] clk: imx: clk-imx95-blk-ctl: fix error unwinding in probe Manush Prajwal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®