Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clk: imx5: Check the IIM clock before reading the i.MX53 revision
@ 2026-11-29 19:25 Jiawen Liu
  0 siblings, 0 replies; only message in thread
From: Jiawen Liu @ 2026-11-29 19:25 UTC (permalink / raw)
  To: Abel Vesa, Stephen Boyd, Brian Masney, Jerome Brunet, Frank Li,
	Sascha Hauer
  Cc: Peng Fan, Pengutronix Kernel Team, Fabio Estevam, linux-clk, imx,
	linux-arm-kernel

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


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

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

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 19:25 [PATCH] clk: imx5: Check the IIM clock before reading the i.MX53 revision Jiawen Liu

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