All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicola Vetrini <nicola.vetrini@bugseng.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: sstabellini@kernel.org, michal.orzel@amd.com,
	xenia.ragiadakou@amd.com, ayan.kumar.halder@amd.com,
	consulting@bugseng.com, bertrand.marquis@arm.com, julien@xen.org,
	Anthony PERARD <anthony@xenproject.org>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	George Dunlap <george.dunlap@citrix.com>,
	xen-devel@lists.xenproject.org
Subject: Re: [XEN PATCH v2 2/3] xen/unaligned: address violation of MISRA C Rule 20.7
Date: Tue, 30 Apr 2024 17:25:00 +0200	[thread overview]
Message-ID: <ca372123278bf8c8f4ceaac788ae7610@bugseng.com> (raw)
In-Reply-To: <a3912e5a-1d97-4df6-8718-0bfdb1189f23@suse.com>

On 2024-04-30 17:13, Jan Beulich wrote:
> On 30.04.2024 16:28, Nicola Vetrini wrote:
>> MISRA C Rule 20.7 states: "Expressions resulting from the expansion
>> of macro parameters shall be enclosed in parentheses". Therefore, some
>> macro definitions should gain additional parentheses to ensure that 
>> all
>> current and future users will be safe with respect to expansions that
>> can possibly alter the semantics of the passed-in macro parameter.
>> 
>> No functional change.
>> 
>> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
>> ---
>> Somewhat surprisingly, the change in the tools directory is also 
>> needed, otherwise
>> some CI build jobs fail (see e.g. [1]). This is not undefined 
>> behaviour
>> as long as the two definitions are kept in sync, following section
>> 6.10.3p2 of the C99 standard, but having the definition in 
>> common-macros.h
>> is still a potential problem.
>> 
>> [1] 
>> https://gitlab.com/xen-project/people/bugseng/xen/-/jobs/6742878558
> 
> This is pretty absurd, and the use of the Xen header in
> xg_dom_decompress_unsafe_zstd.c should probably have gone away with the
> introduction of the unaligned macros into ...
> 

I agree. I assumed it was known/deliberate.

>> --- a/tools/include/xen-tools/common-macros.h
>> +++ b/tools/include/xen-tools/common-macros.h
>> @@ -102,7 +102,7 @@
>> 
>>  #define put_unaligned_t(type, val, ptr) do {                        \
>>      struct { type x; } __packed *ptr_ = (typeof(ptr_))(ptr);        \
>> -    ptr_->x = val;                                                  \
>> +    ptr_->x = (val);                                                \
>>  } while (0)
>> 
>>  #define get_unaligned(ptr)      get_unaligned_t(typeof(*(ptr)), ptr)
> 
> ... here. We simply cannot assume the two definitions can indefinitely
> be kept in sync.
> 
>> --- a/xen/include/xen/unaligned.h
>> +++ b/xen/include/xen/unaligned.h
>> @@ -19,7 +19,7 @@
>> 
>>  #define put_unaligned_t(type, val, ptr) do {				\
>>  	struct { type x; } __packed *ptr_ = (typeof(ptr_))(ptr);	\
>> -	ptr_->x = val;							\
>> +	ptr_->x = (val);							\
> 
> Nit: One of the padding tabs then wants dropping.
> 
> Jan

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


  reply	other threads:[~2024-04-30 15:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-30 14:28 [XEN PATCH v2 0/3] address violations of MISRA C Rule 20.7 Nicola Vetrini
2024-04-30 14:28 ` [XEN PATCH v2 1/3] drivers: char: address violation " Nicola Vetrini
2024-05-01 19:57   ` Stefano Stabellini
2024-05-03  7:29     ` Nicola Vetrini
2024-05-03 10:10       ` Jan Beulich
2024-05-03 10:18         ` Nicola Vetrini
2024-04-30 14:28 ` [XEN PATCH v2 2/3] xen/unaligned: " Nicola Vetrini
2024-04-30 15:13   ` Jan Beulich
2024-04-30 15:25     ` Nicola Vetrini [this message]
2024-04-30 14:28 ` [XEN PATCH v2 3/3] xen/pci: address violations " Nicola Vetrini
2024-04-30 15:15   ` Jan Beulich
2024-05-14  9:11   ` Jan Beulich

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=ca372123278bf8c8f4ceaac788ae7610@bugseng.com \
    --to=nicola.vetrini@bugseng.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=anthony@xenproject.org \
    --cc=ayan.kumar.halder@amd.com \
    --cc=bertrand.marquis@arm.com \
    --cc=consulting@bugseng.com \
    --cc=george.dunlap@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=michal.orzel@amd.com \
    --cc=sstabellini@kernel.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.