mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Manush Prajwal" <manushprajwal555@gmail.com>
To: abelvesa@kernel.org, peng.fan@nxp.com, sboyd@kernel.org,
	mturquette@baylibre.com
Cc: s.hauer@pengutronix.de, Frank.Li@nxp.com,
	linux-clk@vger.kernel.org, imx@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] clk: imx: clk-imx95-blk-ctl: fix error unwinding in probe
Date: 11 Nov 2026 16:32:50 +0530	[thread overview]
Message-ID: <6af44b5c.67914289.fe7ab.6559@mx.google.com> (raw)

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


                 reply	other threads:[~2026-11-11 11:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6af44b5c.67914289.fe7ab.6559@mx.google.com \
    --to=manushprajwal555@gmail.com \
    --cc=Frank.Li@nxp.com \
    --cc=abelvesa@kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=peng.fan@nxp.com \
    --cc=s.hauer@pengutronix.de \
    --cc=sboyd@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®