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 E2A5BC04A68 for ; Thu, 28 Jul 2022 15:37:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.376930.609980 (Exim 4.92) (envelope-from ) id 1oH5Zs-0000PH-S1; Thu, 28 Jul 2022 15:37:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 376930.609980; Thu, 28 Jul 2022 15:37:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oH5Zs-0000PA-OS; Thu, 28 Jul 2022 15:37:32 +0000 Received: by outflank-mailman (input) for mailman id 376930; Thu, 28 Jul 2022 15:37:30 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oH5Zq-0000P2-T9 for xen-devel@lists.xenproject.org; Thu, 28 Jul 2022 15:37:30 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oH5Zq-0003g4-Lt; Thu, 28 Jul 2022 15:37:30 +0000 Received: from 54-240-197-224.amazon.com ([54.240.197.224] helo=[10.7.237.22]) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oH5Zq-0003Hi-Ej; Thu, 28 Jul 2022 15:37:30 +0000 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" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:Cc:To:Subject:MIME-Version:Date:Message-ID; bh=jCQPGZwJWOctcq94X5UREMIRtJipc6y5laeiAZXZ8mg=; b=Ly3nZyL/LWrNBLWHRlDQNXV7mE NxjuVmdvw+aKEtWZ99LCNCRCDQziHZOuybAXmRkrSpjt/c6WzoWmPpJ3cV5YkTynBlpW/VA1z5hb7 40jpbrujSWOBtIWDPFZqD0c0Xv6Ruq8F+2S7Z4Y+0WvDczYL2rfaidtqUyWj7+g3DX7A=; Message-ID: Date: Thu, 28 Jul 2022 16:37:28 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.0.3 Subject: Re: [PATCH] xen/arm64: sysreg.h: Fix MISRA C 2012 Rule 20.7 violation Content-Language: en-US To: Xenia Ragiadakou , xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk References: <20220728134943.1185621-1-burzalodowa@gmail.com> <0a8ff178-280d-717f-dacb-4eb9f57a24eb@xen.org> From: Julien Grall In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 28/07/2022 16:15, Xenia Ragiadakou wrote: > On 7/28/22 16:56, Julien Grall wrote: >> Hi, >> >> On 28/07/2022 14:49, Xenia Ragiadakou wrote: >>> The macro parameter 'v' is used as an expression and needs to be >>> enclosed in >>> parentheses. >>> >>> Signed-off-by: Xenia Ragiadakou >>> --- >>>   xen/arch/arm/include/asm/arm64/sysregs.h | 2 +- >>>   1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/xen/arch/arm/include/asm/arm64/sysregs.h >>> b/xen/arch/arm/include/asm/arm64/sysregs.h >>> index 54670084c3..f5a7269a27 100644 >>> --- a/xen/arch/arm/include/asm/arm64/sysregs.h >>> +++ b/xen/arch/arm/include/asm/arm64/sysregs.h >>> @@ -461,7 +461,7 @@ >>>   /* Access to system registers */ >>>   #define WRITE_SYSREG64(v, name) do {                    \ >>> -    uint64_t _r = v;                                    \ >>> +    uint64_t _r = (v);                                              \ >> >> I am failing to see why the parentheses are necessary here. Could you >> give an example where the lack of them would end up to different code? > > Here v is supposed to be used as an expression. So maybe the rule wants > to enforce that in the macro we will pass an expression and not multiple > statements (?) ... not sure. Do you mean something like below? #include #include #define foo(v) do { \ uint64_t _r = v; \ \ printf("_r %lu\n", _r); \ } while (0) int main(void) { foo(1; printf("Bar\n")); } If yes, then I agree that the compiler will still be happy. Or if you pass "1; 2", v would be set to 1 rather than 2. I am not sure why one would want to write such code. But I guess we want to prevent that. Cheers, -- Julien Grall