Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.208.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795980543; b=lVft4B80HNulr38L/qPzmdnDn4FylPfwoI9PW/TcnMUJ/SRtwWNJW0chJHLXXSKZodiC 6muwNvzCPUncYdfuh2kUFhZfGs2CxfpExvm81EjRGYLrvbRpRqsDHPb67U6v4Y2ETp7V1 TwyE5i1gZFCZgFrcpOg7Gq4WSc5pUEMHqtpRIKhEP/JkCHVSWHBgaXoc98NzQjxNHgdjH /+QKH8XOlGIl/dhLRLKrzg8cVRw+Ao4Z79oYmpQ9FfsEryiC328Lnjr9zXvyDn50Xp12s TPreJL6U1d1mLaxlDhiNTBAAoe63UIcMhhFSGXRz0ktU7aHf2anj/rLw18fnq/vCXJg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795980543; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=yuFYLNKTLeUjLdH8i7GFwI3EBuwiBqwaiH0Gd/8yz24=; b=uvMzVM0XTRvoW0Os9G35b0Z0VTvW5XUtzW2x2KdLjZJp0d32Ozb6zRAhpYmOK73U9GrG cpmPqemP9+8aDWcdeP9/rbLfNfHrmSFTdy+BVUnBtC+NYPwPXKik4BJg3uSUrys9N8hoY oBV9QeQssjktcuT2ccGi0dGHvUgidQrxZHKMVz/o1ibiqegSOO5BDNEBLA43dEj6P5cKE T7d+vkTos2vIrSmun7qWY4Hww6jChSgQU8C6P7PGquIRsfeDEBKRmlY2saX/qSkZc8wmg 1g8yUys+6TrrScntcFEN+smjm97M5vegr+IxWi61PPMaKj4fhJw/XMdLEAxLzcWWQnQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=JNIIMOYB; arc=none smtp.remote-ip=209.85.208.182 Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE070606A323 for ; Sun, 29 Nov 2026 19:29:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AE070606A323 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=JNIIMOYB Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-3ae1fd4252fso95592751fa.0 for ; Sun, 29 Nov 2026 11:29:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795980541; x=1796585341; darn=lists.linux.dev; h=mime-version:content-transfer-encoding:content-type:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=yuFYLNKTLeUjLdH8i7GFwI3EBuwiBqwaiH0Gd/8yz24=; b=JNIIMOYBAg6/sZt32i+OVQOD9bJGzZYjUbQspajQttShfKuEKCsWBpYUzZlUzF91lv pkUjsHqgpMqT3HgoE5VKTpoQ3XfVqVFBhrnzZKSqwtZWGHxH+RvjWIwZnTf8qc4oE+2/ ARrm5QXydEUzXR8A148nv1VqhhCl3OeoyUwO2V809OM003qmwuwaa4FJACOjwOJBznsf KqwTYaXkaQrBSSi8rli0DV2WTSV8KlX3cLCT4TTwLjJKlqdTn5fN/23Z8bAZQxOUzO8K DCz5r+xBNHGHBUfm9w2zmq9oXnAt1F9kAe2OGsdHt6qoqR++8vNXWD1RqAb/v0Ff4g7e zZzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795980541; x=1796585341; h=mime-version:content-transfer-encoding:content-type:message-id:date :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=yuFYLNKTLeUjLdH8i7GFwI3EBuwiBqwaiH0Gd/8yz24=; b=H4pITrmm6/fnSNhN2LL9ZHyEc9tsPZjU7hALU6T+xtQ9Oe4xU/6fuFK4HIgKyDuR9V 0sUFMj1QBvtmsQfjdXkOtOP/Sw8GNENhEGKFIZ2Q0+ZvNsvjYEBW6gtSuSPCw5/XaIw6 hjxLBxB2NSQ4LTvFcpLMR+EVmGkgUtjy+V2u2nExHZXtL85QhSHUbBYkpG4fkmutAY/N 7MF81GSGbPXesltphgviRc4gPSRbeU2zQJDaqYgpsiFNO7XLthViqldUSqiSz2Jp+X9N lzs5bCYyocv66SiDjEQn7kXFflUUx+OGZBQ5J5ByR9LIrFNJa8XGxu/+RJPRYbdvu7YK siig== X-Forwarded-Encrypted: i=1; AL+hErFa4iEsiPlHTuHrEpsNwRFk4Q9jKFpnPbhikP3yuGOHoBMF1FEBBi/eSjdFFK/vNAnahQc=@lists.linux.dev X-Gm-Message-State: APuU4Z/ululhLnuI0zSq0aI/txI0Mnj37I++YR8fY2xhMyz4u4sdy6dn hhdzPNOg4Q7+CiKFrXw1bs0907Iv/k0019IXuN/Sr9rPJzN+AsoPmC8y X-Gm-Gg: AZFdTZdLmTnNlcuxmbSvWR1p7SIPeMpEHD+GiYmW0rdfsi06UdqRZfPCPp71qcLx46U vL9UIduJ9o7SXhr1C1yHZdkxNLi6hXo2+hu1UaBnmGLeiKYP3VKgaEg7lorCqCyid2RKdV0C1C4 jp2b0OLRRamVXP1KJNkd44Jq53sRoB5/qaG4o/PmrKpwDwh2KOATet+/OdOscsXsVI931jTkZO7 lZGCTWfs4C5H0MZdWzBJor0q0skU5wfsLTqa3JuGnuuQiOeK9EKBQPu1BkH4SQS1F6xu2rpBCG5 Q79pBN49WHJzHxAR5A+XlNrhKqL0Bw1kbcGkZl0ywKPwaZnszXxkJxsw/dCxGr/5JFLI8MHhr8s aHw6dizhAj0atrLqxhavkoH98usIyPHy/scN3+/IjBqolSdET0n7YkRDrT3x5o1nd2lDPFZZ8y9 b4I0PvW32J1Bx8Qv0FfTmIcoRyBL0rVwiuvHUeHPV7F5qBz9+lSekN0lyCKmjO8lLu9/nozPFWH 5jvDxBJZuSNVMNc3oE7cFrd3r1bZLWmcgqzANmhmBioGiSnS+7vD//O5wGAe84uctt737v2zTy1 UH2ZQyG7wvA/1InELuS9cr6t8fQ3pA== X-Received: by 2002:a05:6512:6682:10b0:5c1:c3b6:49ca with SMTP id 2adb3069b0e04-5c1c3b64b13mr5757806e87.42.1795980540642; Sun, 29 Nov 2026 11:29:00 -0800 (PST) Received: from [127.0.1.1] ([5.195.0.150]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5c1bd043420sm7561895e87.57.2026.11.29.11.28.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 11:29:00 -0800 (PST) From: Jiawen Liu To: Russell King , Frank Li , Sascha Hauer , Abel Vesa , Stephen Boyd , Brian Masney , Jerome Brunet Cc: Pengutronix Kernel Team , Fabio Estevam , Peng Fan , linux-arm-kernel@lists.infradead.org, imx@lists.linux.dev, linux-clk@vger.kernel.org Subject: [PATCH] clk: imx: Check the i.MX51 IIM clock before reading the revision Date: Sun, 29 Nov 2026 19:25:33 +0000 Message-ID: <179598033589.2.9243721461155150068.pattern-ext-063.5@gmail.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: imx@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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 --- 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 +#include #include #include #include @@ -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); diff --git a/drivers/clk/imx/clk-imx5.c b/drivers/clk/imx/clk-imx5.c index 9c5f489b3975d..fa7c4d698bd30 100644 --- a/drivers/clk/imx/clk-imx5.c +++ b/drivers/clk/imx/clk-imx5.c @@ -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 diff --git a/include/soc/imx/revision.h b/include/soc/imx/revision.h index b122d2fc88812..d92a8f0bbaecf 100644 --- a/include/soc/imx/revision.h +++ b/include/soc/imx/revision.h @@ -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); -- 2.34.1