Linux clock framework development
 help / color / mirror / Atom feed
From: Haotian Zhang <vulab@iscas.ac.cn>
To: abelvesa@kernel.org, mturquette@baylibre.com, sboyd@kernel.org,
	shawnguo@kernel.org, s.hauer@pengutronix.de, peng.fan@nxp.com,
	kernel@pengutronix.de, festevam@gmail.com
Cc: linux-clk@vger.kernel.org, imx@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, Haotian Zhang <vulab@iscas.ac.cn>
Subject: [PATCH v2] clk: imx: imx95-blk-ctl: Fix clock leak in error paths
Date: Wed, 12 Nov 2025 10:30:25 +0800	[thread overview]
Message-ID: <20251112023025.793-1-vulab@iscas.ac.cn> (raw)
In-Reply-To: <20251111114123.2075-1-vulab@iscas.ac.cn>

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


  parent reply	other threads:[~2025-11-12  2:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-11 11:41 [PATCH] clk: imx: imx95-blk-ctl: Fix clock leak in error paths Haotian Zhang
2025-11-11 14:18 ` Peng Fan
2025-11-12  2:30 ` Haotian Zhang [this message]
2025-11-12  8:58   ` [PATCH v2] " Abel Vesa

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=20251112023025.793-1-vulab@iscas.ac.cn \
    --to=vulab@iscas.ac.cn \
    --cc=abelvesa@kernel.org \
    --cc=festevam@gmail.com \
    --cc=imx@lists.linux.dev \
    --cc=kernel@pengutronix.de \
    --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 \
    --cc=shawnguo@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