Received: by 2002:a05:7412:bb8d:b0:d7:7d3a:4fe2 with SMTP id js13csp2693259rdb; Fri, 18 Aug 2023 07:58:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHDdiGDL8303j3goMjOexrzDosZ+ocSGe5PGBU0lBMGwDLk2nElTi+qMFm75QTdcE6gt3oU X-Received: by 2002:a05:6e02:d09:b0:345:6ce1:d259 with SMTP id g9-20020a056e020d0900b003456ce1d259mr2746590ilj.28.1692370738238; Fri, 18 Aug 2023 07:58:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692370738; cv=none; d=google.com; s=arc-20160816; b=Vk2oIqoMeHxLixu9B5lAmN8FJjssQIaKI6ngA0olKRsQ5WPFYw2KMkP2q6K+z0OMvY Bt5QrK/Y7Uvi5BCJAUuznrWhbGpSRSuV2xP5Q/iH42cXebZbIf37s9lyBIuFm06YoUxg hHDOyBLkWRHDLLAQE1k9+RmYLVOXgyfBd75PvO3R60MNuoos0gT0pT50L+Q+1lneucR7 RR5oeZJ0NAuYK+0JNS3oZtM6Z6PnnQLKahyMmTqF5uL992KYUKl0c+kCZPHsYPaXXnBY KueLuptreYISIyW2JwoGDziamIeXfftI/Ma0TOFGn5YjC8e2VHm9V7WrDYdqmyTh1335 1yng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=wY4+HeDKD3eikmpTOB3F6DNwqPiTQqGxh8Fqd9OsZrE=; fh=5Jt7mUJosclwHX8k4XbaJ7ZUhOm/LtsUwfFRpGUJhys=; b=fnX+hLAkJLjolUNUaxEU42syZ+PWPjed4Lk1UAjkfvAQxJ1KYbvIYJbVSjGjEKjkZI unsY+rsCbkKiFcryWwMEAtEvyaCZfk4uJRadWNJiy0GLf9yMx3cPNXGI8zD0KJ3OOU3X i8RLsZcQAbwf4OQQPBZsh/4QIC7R1fcLb4Sob97YUrXt8iohhV155pjTk/qsmgcsyIx4 afkq664dJJW/astZUv8wCOZZPRdxQfSpeXOnW470T/uF38Lte+aRqJgYtUFeQtJuJLYW 3v3yYy/74gYbLN+Ai8J11YovRnqeNr3E2jQKe0QrSlc4qJ+sgkDt2SYQ5CC4qT5OgKQ2 RSdg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k130-20020a636f88000000b00565e56713c7si1499910pgc.91.2023.08.18.07.58.44; Fri, 18 Aug 2023 07:58:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237508AbjHOOHG (ORCPT + 99 others); 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: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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/sysreg.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 = (u32)(r); \ asm volatile(__mrs_s("%0", r) : "=r" (__val)); \ __val; \ }) #define write_sysreg_s(v, r) do { \ u64 __val = (u64)(v); \ + u32 __maybe_unused __check_r = (u32)(r); \ asm volatile(__msr_s(r, "%x0") : : "rZ" (__val)); \ } while (0) -- 2.34.1