Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jiawen Liu <liu1298662399@gmail.com>
To: Abel Vesa <abelvesa@kernel.org>, Stephen Boyd <sboyd@kernel.org>,
	Brian Masney <bmasney+clk@redhat.com>,
	Jerome Brunet <jbrunet+clk@baylibre.com>,
	Frank Li <Frank.Li@nxp.com>,
	Sascha Hauer <s.hauer@pengutronix.de>
Cc: Peng Fan <peng.fan@nxp.com>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Fabio Estevam <festevam@gmail.com>,
	linux-clk@vger.kernel.org, imx@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH] clk: imx5: Check the IIM clock before reading the i.MX53 revision
Date: Sun, 29 Nov 2026 19:25:33 +0000	[thread overview]
Message-ID: <179598034195.2.4863762640537317638.pattern-ext-124.21@gmail.com> (raw)

During i.MX53 device-tree boot, mx53_clocks_init() reads the silicon
revision from the IIM after calling clk_prepare_enable(). The IIM gate
registration can return an error pointer that clk_prepare() dereferences.
If a valid clock fails to prepare or enable, the callback still reads
the IIM without acquiring its clock and then attempts an unmatched
disable and unprepare.

Use the existing registration diagnostic and skip the revision read
when the IIM gate failed to register. Log prepare or enable failures,
and read the revision and release the clock only after a successful
acquisition. Continue USB and UART clock setup in all cases.

Verified the control flow by source
inspection, cross-built clk-imx5.o with ARM imx_v6_v7_defconfig, and ran
git diff --check and checkpatch. No runtime or hardware reproduction
was performed.

Fixes: b8d4176fa59e ("ARM i.MX5: implement clocks using common clock framework")
Signed-off-by: Jiawen Liu <liu1298662399@gmail.com>
---
 drivers/clk/imx/clk-imx5.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/imx/clk-imx5.c b/drivers/clk/imx/clk-imx5.c
index 9c5f489b3975d..d3fc9fcd8ec2f 100644
--- a/drivers/clk/imx/clk-imx5.c
+++ b/drivers/clk/imx/clk-imx5.c
@@ -472,7 +472,9 @@ static void __init mx53_clocks_init(struct device_node *np)
 {
 	void __iomem *ccm_base;
 	void __iomem *pll_base;
+	struct clk *iim_clk;
 	unsigned long r;
+	int ret;
 
 	pll_base = ioremap(MX53_DPLL1_BASE, SZ_16K);
 	WARN_ON(!pll_base);
@@ -602,9 +604,16 @@ static void __init mx53_clocks_init(struct device_node *np)
 	/* make sure step clock is running from 24MHz */
 	clk_set_parent(clk[IMX5_CLK_STEP_SEL], clk[IMX5_CLK_LP_APM]);
 
-	clk_prepare_enable(clk[IMX5_CLK_IIM_GATE]);
-	imx_print_silicon_rev("i.MX53", mx53_revision());
-	clk_disable_unprepare(clk[IMX5_CLK_IIM_GATE]);
+	iim_clk = clk[IMX5_CLK_IIM_GATE];
+	if (!IS_ERR(iim_clk)) {
+		ret = clk_prepare_enable(iim_clk);
+		if (ret) {
+			pr_err("i.MX53: failed to enable IIM clock: %d\n", ret);
+		} else {
+			imx_print_silicon_rev("i.MX53", mx53_revision());
+			clk_disable_unprepare(iim_clk);
+		}
+	}
 
 	r = clk_round_rate(clk[IMX5_CLK_USBOH3_PER_GATE], 54000000);
 	clk_set_rate(clk[IMX5_CLK_USBOH3_PER_GATE], r);
-- 
2.34.1


                 reply	other threads:[~2026-11-29 20:41 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=179598034195.2.4863762640537317638.pattern-ext-124.21@gmail.com \
    --to=liu1298662399@gmail.com \
    --cc=Frank.Li@nxp.com \
    --cc=abelvesa@kernel.org \
    --cc=bmasney+clk@redhat.com \
    --cc=festevam@gmail.com \
    --cc=imx@lists.linux.dev \
    --cc=jbrunet+clk@baylibre.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --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