From patchwork Wed Oct 18 14:18:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simone Ballarin X-Patchwork-Id: 13427162 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CD67DCDB484 for ; Wed, 18 Oct 2023 14:19:19 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.618598.962470 (Exim 4.92) (envelope-from ) id 1qt7O0-0006C5-U0; Wed, 18 Oct 2023 14:19:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 618598.962470; Wed, 18 Oct 2023 14:19:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qt7O0-0006Al-Qa; Wed, 18 Oct 2023 14:19:00 +0000 Received: by outflank-mailman (input) for mailman id 618598; Wed, 18 Oct 2023 14:18:59 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qt7Nz-0004vw-BS for xen-devel@lists.xenproject.org; Wed, 18 Oct 2023 14:18:59 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 4570c89c-6dc1-11ee-9b0e-b553b5be7939; Wed, 18 Oct 2023 16:18:55 +0200 (CEST) Received: from beta.station (net-188-218-250-245.cust.vodafonedsl.it [188.218.250.245]) by support.bugseng.com (Postfix) with ESMTPSA id 2CA834EE0741; Wed, 18 Oct 2023 16:18:55 +0200 (CEST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4570c89c-6dc1-11ee-9b0e-b553b5be7939 From: Simone Ballarin To: xen-devel@lists.xenproject.org Cc: consulting@bugseng.com, sstabellini@kernel.org, Simone Ballarin , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Wei Liu Subject: [XEN PATCH 3/4] xen/include: add pure and const attributes Date: Wed, 18 Oct 2023 16:18:50 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Add const and pure attributes to address reports of MISRA C:2012 Rule 13.1: Initializer lists shall not contain persistent side effects Add pure attribute to function pdx_to_pfn. Add const attribute to functions generated by TYPE_SAFE. These functions are used in initializer lists: adding the attributes ensures that no effect will be performed by them. Signed-off-by: Simone Ballarin Reviewed-by: Stefano Stabellini --- Function attributes pure and const do not need to be added as GCC attributes, they can be added using ECLAIR configurations. --- xen/include/xen/pdx.h | 2 +- xen/include/xen/typesafe.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/xen/include/xen/pdx.h b/xen/include/xen/pdx.h index f3fbc4273a..5d1050967a 100644 --- a/xen/include/xen/pdx.h +++ b/xen/include/xen/pdx.h @@ -164,7 +164,7 @@ static inline unsigned long pfn_to_pdx(unsigned long pfn) * @param pdx Page index * @return Obtained pfn after decompressing the pdx */ -static inline unsigned long pdx_to_pfn(unsigned long pdx) +static inline __attribute_pure__ unsigned long pdx_to_pfn(unsigned long pdx) { return (pdx & pfn_pdx_bottom_mask) | ((pdx << pfn_pdx_hole_shift) & pfn_top_mask); diff --git a/xen/include/xen/typesafe.h b/xen/include/xen/typesafe.h index 7ecd3b4a8d..615df6f944 100644 --- a/xen/include/xen/typesafe.h +++ b/xen/include/xen/typesafe.h @@ -21,8 +21,8 @@ #define TYPE_SAFE(_type, _name) \ typedef struct { _type _name; } _name##_t; \ - static inline _name##_t _##_name(_type n) { return (_name##_t) { n }; } \ - static inline _type _name##_x(_name##_t n) { return n._name; } + static inline __attribute_const__ _name##_t _##_name(_type n) { return (_name##_t) { n }; } \ + static inline __attribute_const__ _type _name##_x(_name##_t n) { return n._name; } #else