clk: imx: Check the i.MX51 IIM clock before reading the revision
Subsystems (5)
PATCH 1/1 clk: imx: Check the i.MX51 IIM clock before reading the revision
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.
--- 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(-)
arch/arm/mach-imx/cpu-imx5.c +30 -11
@@ -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" ); }return 0 ; }
@@ -106,10 +125,10 @@ static int get_mx53_srev(void)*/ int mx53_revision (void ) { -if (mx5_cpu_rev ==-1 ) - mx5_cpu_rev =get_mx53_srev (); +if (mx53_cpu_rev ==-1 ) + mx53_cpu_rev =get_mx53_srev (); -return mx5_cpu_rev; +return mx53_cpu_rev; }EXPORT_SYMBOL (mx53_revision);
drivers/clk/imx/clk-imx5.c +1 -2
@@ -445,9 +445,8 @@ static void __init mx51_clocks_init(struct device_node *np)clk_set_rate (clk[IMX5_CLK_ESDHC_A_PODF ],166250000 );clk_set_rate (clk[IMX5_CLK_ESDHC_B_PODF ],166250000 ); -clk_prepare_enable (clk[IMX5_CLK_IIM_GATE ]); +mx51_revision_init (clk[IMX5_CLK_IIM_GATE ]);imx_print_silicon_rev ("i.MX51" ,mx51_revision ()); -clk_disable_unprepare (clk[IMX5_CLK_IIM_GATE ]);/* * Reference Manual says: Functionality of CCDR[18] and CLPCR[23] is no
include/soc/imx/revision.h +3 -0
@@ -6,6 +6,8 @@#ifndef __SOC_IMX_REVISION_H__#define __SOC_IMX_REVISION_H__ +struct clk ; +#define IMX_CHIP_REVISION_1_0 0x10#define IMX_CHIP_REVISION_1_1 0x11#define IMX_CHIP_REVISION_1_2 0x12
@@ -27,6 +29,7 @@ int mx27_revision(void);int mx31_revision (void );int mx35_revision (void );int mx51_revision (void ); +void mx51_revision_init (struct clk *iim_clk);int mx53_revision (void );unsigned int imx_get_soc_revision (void );
Signature · 1 line
2.34.1
Quoted 17 lines · Jiawen Liu
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 withCONFIG_NEONenabled and disabled, git diff --check, and checkpatch. Runtime and hardware reproduction were not performed.
Quoted 8 lines
Fixes b8d4176fa59e ("ARM i.MX5: implement clocks using common clock framework")Signed-off-by Jiawen Liu <[email protected]>--- 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(-)
You sent multiple independent patches, to multiple independent subsystems. The amount of these patches clearly suggest this was AI generated and most likely not tested.
More importantly, you sent all this work without properly organizing relevant patches into patchsets. This makes reviewing difficult and might cause multiple reviewers to address the same issue. Replying to the entire set is impossible and requires handling each patch independently, instead of applying or discarding the set. Maintainers also won't see the bigger picture of your work. Quite worrying.
Please read kernel documentation BEFORE posting more work. It will explain you how to identify subsystems, how to organize your work per subsystem (so a patchset grouping multiple patches with a short cover letter), how to document the issue discovery method and what was or was not tested.
Best regards,
Krzysztof
Quoted 83 lines · On Sun, 29 Nov 2026 19:25:33 +0000 Jiawen Liu <[email protected]> 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 withCONFIG_NEONenabled 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 <[email protected]>--- 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(-)arch/arm/mach-imx/cpu-imx5.c +22
-5@@ -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 )
arch/arm/mach-imx/cpu-imx5.c EXPORT_SYMBOL(mx51_revision); · line 99
Quoted 10 lines
arch/arm/mach-imx/cpu-imx5.c +5
-3{ -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