From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C333606A31C for ; Sun, 29 Nov 2026 19:29:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=4M/aKDcC; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=hMOzI1qF DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version: Content-Transfer-Encoding:Content-Type:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Unsubscribe-Post:List-Owner; bh=yuFYLNKTLeUjLdH8i7GFwI3EBuwiBqwaiH0Gd/8yz24=; b=4M/aKDcCU1zu+S0Se9vKCwMr2w +sKIhoBcWMOvNmhNlUz4UtD8/vZ4CEyCwezooxwl/2Wubppfw7igcn5szhbZG4E4ldlPKwgwuv0TP Pi4zXij1cGOl7yzLBQcKhmaUfrJziOBLc7yk8nW+dNI84Hiny1hmKCWbSPCtrmCXTiaYop6PNFID2 m5KUNtysHjCi2cXnvijh1yeBWiFqqXGFiOlNOkTU29KVnUrv7tXoR/dV22fBi3wzhaRswG0x8ioVB X9+a2niGYhJENaze1RxYZ9MzQfbUDdb5lOoM2QSBfE+1lmr+fWPgfmlpq5tm7mjDrY9os3QpvFdeJ ObwPlw8Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXkaD-00000002Nyp-1o47; Sun, 29 Nov 2026 19:29:09 +0000 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXka7-00000002Nxh-3VGa for linux-arm-kernel@lists.infradead.org; Sun, 29 Nov 2026 19:29:05 +0000 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-5c17ef1e18cso6306298e87.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.infradead.org; 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=hMOzI1qFGaNvpUsaLXLCiT5XhArZPcDsA40kfTj05las9sX416heL18od8ic1nI2X2 hyk9MBJ6quoYfDeLQKtQQgoKCB+1Yx3zJVbcx5MoGbxe2+A1ic3YXfpvsCNEgWxOPwIW JYij1bKjLV6wzQD/rkqNQ/gzFkIFy4nygvBF1tBzHshJ6Gu8FOgEMxHc9TUdKHsTueRK yuNQcn4TVG8ApLvKFt5StIc38qz9foz9WV2OfWtIU7bEppnz9Od/C4Snhq9birTqD6rT a9waHzUjQxGNrSJBpUxSrSHTndpLLWErwUuThKqXuUAJlK172dXS1O3zJSeYR+Cxd5ln jNKg== 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=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Nn5TixiHd6l5uFqxZFACxpVVpkgNTGENHWkkoQBtJ53 vV2qujUk1bfOgFwcm3XpWdtrAoHsYL6vxEO6fVg9b85nZdPVegDGw7fxELP74imJyoENKfo22Gr i78wof7/m3r1mpvUDEWN/agVwyTAXg== 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-Archived-By: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261129_112903_895103_C44114BF X-CRM114-Status: GOOD ( 18.43 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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