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,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Roger Pau Monné" <roger.pau@citrix.com>,
xen-devel@lists.xenproject.org
Subject: Re: [XEN PATCH 4/6] x86emul: address violations of MISRA C Rule 20.7
Date: Wed, 12 Jun 2024 11:52:19 +0200 [thread overview]
Message-ID: <ac1faf5feded028ce80752ce69983352@bugseng.com> (raw)
In-Reply-To: <12ce10af-cd36-492e-a73b-2b81b5bf60cc@suse.com>
On 2024-06-12 11:19, Jan Beulich wrote:
> On 11.06.2024 17:53, 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>
>> ---
>> These local helpers could in principle be deviated, but the
>> readability
>> and functionality are essentially unchanged by complying with the
>> rule,
>> so I decided to modify the macro definition as the preferred option.
>
> Well, yes, but ...
>
>> --- a/xen/arch/x86/x86_emulate/x86_emulate.c
>> +++ b/xen/arch/x86/x86_emulate/x86_emulate.c
>> @@ -2255,7 +2255,7 @@ x86_emulate(
>> switch ( modrm_reg & 7 )
>> {
>> #define GRP2(name, ext) \
>> - case ext: \
>> + case (ext): \
>> if ( ops->rmw && dst.type == OP_MEM ) \
>> state->rmw = rmw_##name; \
>> else \
>> @@ -8611,7 +8611,7 @@ int x86_emul_rmw(
>> unsigned long dummy;
>>
>> #define XADD(sz, cst, mod) \
>> - case sz: \
>> + case (sz): \
>> asm ( "" \
>> COND_LOCK(xadd) " %"#mod"[reg], %[mem]; " \
>> _POST_EFLAGS("[efl]", "[msk]", "[tmp]") \
>
> ... this is really nitpicky of the rule / tool. What halfway realistic
> ways do you see to actually misuse these macros? What follows the
> "case"
> keyword is just an expression; no precedence related issues are
> possible.
>
I do share the view: no real danger is possible in sensible uses. Often
MISRA rules are stricter than necessary to have a simple formulation, by
avoiding too many special cases.
However, if a deviation is formulated, then it needs to be maintained,
for no real readability benefit in this case, in my opinion. I can be
convinced otherwise, of course.
--
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)
next prev parent reply other threads:[~2024-06-12 9:52 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-11 15:53 [XEN PATCH 0/6] address several violations of MISRA Rule 20.7 Nicola Vetrini
2024-06-11 15:53 ` [XEN PATCH 1/6] automation/eclair: address violations of MISRA C " Nicola Vetrini
2024-06-11 15:53 ` [XEN PATCH 2/6] xen/self-tests: address violations of MISRA rule 20.7 Nicola Vetrini
2024-06-12 9:12 ` Jan Beulich
2024-06-11 15:53 ` [XEN PATCH 3/6] xen/guest_access: " Nicola Vetrini
2024-06-12 9:13 ` Jan Beulich
2024-06-11 15:53 ` [XEN PATCH 4/6] x86emul: address violations of MISRA C Rule 20.7 Nicola Vetrini
2024-06-12 9:19 ` Jan Beulich
2024-06-12 9:52 ` Nicola Vetrini [this message]
2024-06-12 10:36 ` Jan Beulich
2024-06-13 9:41 ` Nicola Vetrini
2024-06-11 15:53 ` [XEN PATCH 5/6] x86/irq: " Nicola Vetrini
2024-06-12 9:22 ` Jan Beulich
2024-06-11 15:53 ` [XEN PATCH 6/6] automation/eclair_analysis: clean ECLAIR configuration scripts Nicola Vetrini
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=ac1faf5feded028ce80752ce69983352@bugseng.com \
--to=nicola.vetrini@bugseng.com \
--cc=andrew.cooper3@citrix.com \
--cc=ayan.kumar.halder@amd.com \
--cc=consulting@bugseng.com \
--cc=jbeulich@suse.com \
--cc=michal.orzel@amd.com \
--cc=roger.pau@citrix.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.