[PATCH] clk: imx: Check the i.MX51 IIM clock before reading the revision

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


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

> During i.MX51 device-tree boot, mx51_clocks_init() enables the IIM
> clock to read the silicon revision. If IIM gate registration fails,
> clk_prepare() dereferences the error pointer and can fault during boot.
> If preparing or enabling a valid clock fails, the code still reads the
> IIM register and releases a clock reference it never acquired.
> 
> Check the clock handle and cache the revision only after a successful
> enable. Release the clock after the read. On clock failure, leave the
> revision unknown and continue CCM and UART initialization. Make the late
> NEON fixup use the cached revision and disable NEON when the revision
> is unknown.
> 
> Verification included source and
> ARM object inspection, targeted ARM builds with CONFIG_NEON enabled
> and disabled, git diff --check, and checkpatch. Runtime and hardware
> reproduction were not performed.
> 
> Fixes: b8d4176fa59e ("ARM i.MX5: implement clocks using common clock framework")
> Signed-off-by: Jiawen Liu <liu1298662399 at gmail.com>
> ---
>  arch/arm/mach-imx/cpu-imx5.c | 41 ++++++++++++++++++++++++++----------
>  drivers/clk/imx/clk-imx5.c   |  3 +--
>  include/soc/imx/revision.h   |  3 +++
>  3 files changed, 34 insertions(+), 13 deletions(-)
> 
> diff --git a/arch/arm/mach-imx/cpu-imx5.c b/arch/arm/mach-imx/cpu-imx5.c
> index a67c89bf155dd..a7c48e3e4e7f2 100644
> --- a/arch/arm/mach-imx/cpu-imx5.c
> +++ b/arch/arm/mach-imx/cpu-imx5.c
> @@ -5,6 +5,8 @@
>   * This file contains the CPU initialization code.
>   */
>  
> +#include <linux/clk.h>
> +#include <linux/err.h>
>  #include <linux/types.h>
>  #include <linux/kernel.h>
>  #include <linux/init.h>
> @@ -16,7 +18,8 @@
>  #include "hardware.h"
>  #include "common.h"
>  
> -static int mx5_cpu_rev = -1;
> +static int mx51_cpu_rev = IMX_CHIP_REVISION_UNKNOWN;
> +static int mx53_cpu_rev = -1;
>  
>  #define IIM_SREV 0x24
>  
> @@ -58,13 +61,27 @@ static int get_mx51_srev(void)
>   */
>  int mx51_revision(void)
>  {
> -	if (mx5_cpu_rev == -1)
> -		mx5_cpu_rev = get_mx51_srev();
> -
> -	return mx5_cpu_rev;
> +	return mx51_cpu_rev;
>  }
>  EXPORT_SYMBOL(mx51_revision);
>  
> +void __init mx51_revision_init(struct clk *iim_clk)
> +{
> +	int ret;
> +
> +	if (IS_ERR(iim_clk))
> +		return;
> +
> +	ret = clk_prepare_enable(iim_clk);
> +	if (ret) {
> +		pr_err("i.MX51: failed to enable IIM clock: %d\n", ret);
> +		return;
> +	}
> +
> +	mx51_cpu_rev = get_mx51_srev();
> +	clk_disable_unprepare(iim_clk);
> +}
> +
>  #ifdef CONFIG_NEON
>  
>  /*
> @@ -74,10 +91,12 @@ EXPORT_SYMBOL(mx51_revision);
>   */
>  int __init mx51_neon_fixup(void)
>  {
> -	if (mx51_revision() < IMX_CHIP_REVISION_3_0 &&
> -			(elf_hwcap & HWCAP_NEON)) {
> +	int rev = mx51_revision();
> +
> +	if ((rev == IMX_CHIP_REVISION_UNKNOWN || rev < IMX_CHIP_REVISION_3_0) &&
> +	    (elf_hwcap & HWCAP_NEON)) {
>  		elf_hwcap &= ~HWCAP_NEON;
> -		pr_info("Turning off NEON support, detected broken NEON implementation\n");
> +		pr_info("Turning off NEON support on i.MX51\n");

Why change the log?

Regards
Peng



More information about the linux-arm-kernel mailing list