From nobody Thu Dec 18 00:05:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99A92C0015E for ; Tue, 15 Aug 2023 14:07:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237514AbjHOOHG (ORCPT ); Tue, 15 Aug 2023 10:07:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237466AbjHOOGw (ORCPT ); Tue, 15 Aug 2023 10:06:52 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 97FBF1B2 for ; Tue, 15 Aug 2023 07:06:51 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 376701063; Tue, 15 Aug 2023 07:07:33 -0700 (PDT) Received: from e127643.arm.com (unknown [10.57.2.104]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 109593F6C4; Tue, 15 Aug 2023 07:06:48 -0700 (PDT) From: James Clark To: mark.rutland@arm.com, linux-arm-kernel@lists.infradead.org, will@kernel.org, anshuman.khandual@arm.com Cc: James Clark , Catalin Marinas , Mark Brown , James Morse , Kristina Martsenko , Rob Herring , Jintack Lim , linux-kernel@vger.kernel.org Subject: [PATCH] arm64: sysreg: Generate C compiler warnings on {read,write}_sysreg_s arguments Date: Tue, 15 Aug 2023 15:06:39 +0100 Message-Id: <20230815140639.614769-1-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Evaluate the register before the asm section so that the C compiler generates warnings when there is an issue with the register argument. This will prevent possible future issues such as the one seen here [1] where a missing bracket caused the shift and addition operators to be evaluated in the wrong order, but no warning was emitted. The GNU assembler has no warning for when expressions evaluate differently to C due to different operator precedence, but the C compiler has some warnings that may suggest something is wrong. For example in this case the following warning would have been emitted: error: operator '>>' has lower precedence than '+'; '+' will be evaluated= first [-Werror,-Wshift-op-parentheses] There are currently no existing warnings that need to be fixed. [1]: https://lore.kernel.org/linux-perf-users/20230728162011.GA22050@willie= -the-truck/ Signed-off-by: James Clark --- arch/arm64/include/asm/sysreg.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysre= g.h index 0c07b03d511f..71eb8ea7c795 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -777,15 +777,21 @@ /* * For registers without architectural names, or simply unsupported by * GAS. + * + * __check_r forces warnings to be generated by the compiler when + * evaluating r which wouldn't normally happen due to being passed to + * the assembler via __stringify(r). */ #define read_sysreg_s(r) ({ \ u64 __val; \ + u32 __maybe_unused __check_r =3D (u32)(r); \ asm volatile(__mrs_s("%0", r) : "=3Dr" (__val)); \ __val; \ }) =20 #define write_sysreg_s(v, r) do { \ u64 __val =3D (u64)(v); \ + u32 __maybe_unused __check_r =3D (u32)(r); \ asm volatile(__msr_s(r, "%x0") : : "rZ" (__val)); \ } while (0) =20 --=20 2.34.1