[PATCH] clk: imx5: Check the IIM clock before reading the i.MX53 revision

Peng Fan (OSS) peng.fan at oss.nxp.com
Sun Nov 29 18:29:23 PST 2026


On Sun, 29 Nov 2026 19:25:33 +0000 Jiawen Liu <liu1298662399 at gmail.com> wrote:

> 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 at 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);
> +		}
> +	}
>  

Reviewed-by: Peng Fan <peng.fan at nxp.com>



More information about the linux-arm-kernel mailing list