All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicola Vetrini <nicola.vetrini@bugseng.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	xen-devel@lists.xenproject.org, michal.orzel@amd.com,
	xenia.ragiadakou@amd.com, ayan.kumar.halder@amd.com,
	consulting@bugseng.com, jbeulich@suse.com, roger.pau@citrix.com,
	George Dunlap <george.dunlap@citrix.com>,
	Julien Grall <julien@xen.org>, Wei Liu <wl@xen.org>
Subject: Re: [XEN PATCH 9/9] xen/compat: address Rule 10.1 for macros CHECK_SIZE
Date: Tue, 10 Oct 2023 18:06:18 +0200	[thread overview]
Message-ID: <b40d9faac462c21e91392017b81bc68c@bugseng.com> (raw)
In-Reply-To: <9ee8d16c-d34c-45c2-b5f7-53725bdc01c8@citrix.com>

On 10/10/2023 18:00, Andrew Cooper wrote:
> On 10/10/2023 9:02 am, Stefano Stabellini wrote:
>> On Fri, 6 Oct 2023, Nicola Vetrini wrote:
>>> The essential type of the result of an inequality operator is
>>> essentially boolean, therefore it shouldn't be used as an argument of
>>> the multiplication operator, which expects an integer.
>>> 
>>> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
>>> ---
>>>  xen/include/xen/compat.h | 10 ++++++----
>>>  1 file changed, 6 insertions(+), 4 deletions(-)
>>> 
>>> diff --git a/xen/include/xen/compat.h b/xen/include/xen/compat.h
>>> index f2ce5bb3580a..5ffee6a9fed1 100644
>>> --- a/xen/include/xen/compat.h
>>> +++ b/xen/include/xen/compat.h
>>> @@ -151,12 +151,14 @@ CHECK_NAME_(k, n, T)(k xen_ ## n *x, \
>>>      return x == c; \
>>>  }
>>> 
>>> +#define SIZE_NEQUAL(a, b) \
>>> +    (sizeof(a) != sizeof(b) ? 1 : 0)
>>>  #define CHECK_SIZE(name) \
>>> -    typedef int CHECK_NAME(name, S)[1 - (sizeof(xen_ ## name ## _t) 
>>> != \
>>> -                                         sizeof(compat_ ## name ## 
>>> _t)) * 2]
>>> +    typedef int CHECK_NAME(name, S)[1 - (SIZE_NEQUAL(xen_ ## name ## 
>>> _t, \
>>> +                                                     compat_ ## name 
>>> ## _t)) * 2]
>>>  #define CHECK_SIZE_(k, n) \
>>> -    typedef int CHECK_NAME_(k, n, S)[1 - (sizeof(k xen_ ## n) != \
>>> -                                          sizeof(k compat_ ## n)) * 
>>> 2]
>>> +    typedef int CHECK_NAME_(k, n, S)[1 - (SIZE_NEQUAL(k xen_ ## n, \
>>> +                                                      k compat_ ## 
>>> n)) * 2]
>> I think this style is easier to read but I'll let the x86 maintainers
>> decide
>> 
>>     typedef int CHECK_NAME(name, S)[(sizeof(xen_ ## name ## _t) == \
>>                                      sizeof(compat_ ## name ## _t)) ? 
>> 1 : -1]
>> 
>> Also am I reading this correctly that we are using -1 as array index? 
>> I
>> must have made a calculation mistake?
> 
> This is a NIH BUILD_BUG_ON().  It should be rewritten as
> 
> BUILD_BUG_ON(sizeof(xen ...) != sizeof(compat ...));
> 
> which will use _Static_assert() in modern compilers.
> 
> ~Andrew

Ok, thanks.

-- 
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)


  reply	other threads:[~2023-10-10 16:06 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-06  8:26 [XEN PATCH 0/9] address violations of MISRA C:2012 Rule 10.1 Nicola Vetrini
2023-10-06  8:26 ` [XEN PATCH][for-4.19 1/9] xen/include: add macro LOWEST_POW2 Nicola Vetrini
2023-10-06  9:29   ` Julien Grall
2023-10-06 10:02     ` Nicola Vetrini
2023-10-06 10:22       ` Julien Grall
2023-10-06 10:34         ` Nicola Vetrini
2023-10-06 14:35           ` Julien Grall
2023-10-06 15:36             ` Nicola Vetrini
2023-10-07  0:05             ` Stefano Stabellini
2023-10-07  0:29               ` Stefano Stabellini
2023-10-09  8:23                 ` Nicola Vetrini
2023-10-06 16:35   ` andrew.cooper3
2023-10-09  7:08     ` Nicola Vetrini
2023-10-06  8:26 ` [XEN PATCH][for-4.19 2/9] arm/bitops: encapsulate violation of MISRA C:2012 Rule 10.1 Nicola Vetrini
2023-10-10  0:45   ` Stefano Stabellini
2023-10-06  8:26 ` [XEN PATCH][for-4.19 3/9] xen/pdx: amend definition of PDX_GROUP_COUNT Nicola Vetrini
2023-10-06  8:26 ` [XEN PATCH 4/9] x86_64/mm: express macro CNT using LOWEST_POW2 Nicola Vetrini
2023-10-06  8:26 ` [XEN PATCH 5/9] x86/cpu-policy: address violations of MISRA C Rule 10.1 Nicola Vetrini
2023-10-06 17:57   ` Andrew Cooper
2023-10-09  7:13     ` Nicola Vetrini
2023-10-06  8:26 ` [XEN PATCH 6/9] x86/io_apic: address violation of MISRA C:2012 " Nicola Vetrini
2023-10-10  0:48   ` Stefano Stabellini
2023-10-06  8:26 ` [XEN PATCH 7/9] x86/mce: Move MC_NCLASSES into the enum mctelem_class Nicola Vetrini
2023-10-06 19:11   ` andrew.cooper3
2023-10-09  7:15     ` Nicola Vetrini
2023-10-06  8:26 ` [XEN PATCH][for-4.19 8/9] xen/types: address Rule 10.1 for DECLARE_BITMAP use Nicola Vetrini
2023-10-06  9:34   ` Julien Grall
2023-10-06 10:10     ` Nicola Vetrini
2023-10-06 14:47       ` Julien Grall
2023-10-07  1:04         ` Stefano Stabellini
2023-10-09  7:48           ` Nicola Vetrini
2023-10-09  9:09           ` Julien Grall
2023-10-10  1:09             ` Stefano Stabellini
2023-10-10 10:53               ` Julien Grall
2023-10-10 12:07                 ` Nicola Vetrini
2023-10-10 12:13                   ` Julien Grall
2023-10-10 12:15                     ` Julien Grall
2023-10-10 12:55                       ` Nicola Vetrini
2023-10-10 14:20                 ` Nicola Vetrini
2023-10-09  7:44         ` Nicola Vetrini
2023-10-06  8:26 ` [XEN PATCH 9/9] xen/compat: address Rule 10.1 for macros CHECK_SIZE Nicola Vetrini
2023-10-10  1:02   ` Stefano Stabellini
2023-10-10 16:00     ` Andrew Cooper
2023-10-10 16:06       ` Nicola Vetrini [this message]
2023-10-10 16:19         ` Andrew Cooper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b40d9faac462c21e91392017b81bc68c@bugseng.com \
    --to=nicola.vetrini@bugseng.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=ayan.kumar.halder@amd.com \
    --cc=consulting@bugseng.com \
    --cc=george.dunlap@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=michal.orzel@amd.com \
    --cc=roger.pau@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    --cc=xenia.ragiadakou@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.