All of lore.kernel.org
 help / color / mirror / Atom feed
From: Demi Marie Obenour <demiobenour@gmail.com>
To: Stefano Stabellini <sstabellini@kernel.org>,
	Dmytro Prokopchuk1 <dmytro_prokopchuk1@epam.com>
Cc: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
	"Julien Grall" <julien@xen.org>,
	"Bertrand Marquis" <bertrand.marquis@arm.com>,
	"Michal Orzel" <michal.orzel@amd.com>,
	"Volodymyr Babchuk" <Volodymyr_Babchuk@epam.com>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Anthony PERARD" <anthony.perard@vates.tech>,
	"Jan Beulich" <jbeulich@suse.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>,
	"Rahul Singh" <rahul.singh@arm.com>
Subject: Re: [XEN PATCH] xen/arm: address violation of MISRA C Rule 10.1
Date: Thu, 10 Jul 2025 21:25:19 -0400	[thread overview]
Message-ID: <f84fc6f5-e11a-4e00-820c-d8146d4c8aea@gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2507101715030.605088@ubuntu-linux-20-04-desktop>


[-- Attachment #1.1.1: Type: text/plain, Size: 2552 bytes --]

On 7/10/25 20:15, Stefano Stabellini wrote:
> On Thu, 10 Jul 2025, Dmytro Prokopchuk1 wrote:
>> Rule 10.1: Operands shall not be of an
>> inappropriate essential type
>>
>> The following are non-compliant:
>> - unary minus on unsigned type;
>> - boolean used as a numeric value.
>>
>> Replace unary '-' operator with multiplying by '-1L' or '-1LL'.
>> Replace numeric constant '-1UL' with '~0UL'.
>> Replace numeric constant '-1ULL' with '~0ULL'.
>> Cast boolean to numeric value.
>>
>> Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com>
>> ---
>>  xen/arch/arm/gic-vgic.c               | 2 +-
>>  xen/common/memory.c                   | 2 +-
>>  xen/common/page_alloc.c               | 6 +++---
>>  xen/common/time.c                     | 2 +-
>>  xen/drivers/passthrough/arm/smmu-v3.c | 2 +-
>>  xen/lib/strtol.c                      | 2 +-
>>  xen/lib/strtoll.c                     | 2 +-
>>  7 files changed, 9 insertions(+), 9 deletions(-)
>>
>> diff --git a/xen/arch/arm/gic-vgic.c b/xen/arch/arm/gic-vgic.c
>> index ea48c5375a..a35f33c5f2 100644
>> --- a/xen/arch/arm/gic-vgic.c
>> +++ b/xen/arch/arm/gic-vgic.c
>> @@ -17,7 +17,7 @@
>>  #include <asm/vgic.h>
>>  
>>  #define lr_all_full()                                           \
>> -    (this_cpu(lr_mask) == (-1ULL >> (64 - gic_get_nr_lrs())))
>> +    (this_cpu(lr_mask) == (~0ULL >> (64 - gic_get_nr_lrs())))
> 
> I understand this change, I think it is good
> 
> 
> 
>>  #undef GIC_DEBUG
>>  
>> diff --git a/xen/common/memory.c b/xen/common/memory.c
>> index 46620ed825..96086704cb 100644
>> --- a/xen/common/memory.c
>> +++ b/xen/common/memory.c
>> @@ -773,7 +773,7 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)
>>  
>>                  nrspin_lock(&d->page_alloc_lock);
>>                  drop_dom_ref = (dec_count &&
>> -                                !domain_adjust_tot_pages(d, -dec_count));
>> +                                !domain_adjust_tot_pages(d, (-1L) * dec_count));
> 
> ...but I don't understand this? It looks like it would also break 10.1
> and/or 10.3 as well?
> 
> I would rather use casts if needed, which wouldn't change the behavior
> but would highlight the unsigned->signed conversion, making it more
> visible:
> 
>     !domain_adjust_tot_pages(d, -(int)dec_count));

-INT_MIN is undefined behavior, whereas -(unsigned)INT_MIN should be
well-defined.  I'm not sure if that matters here, though.
-- 
Sincerely,
Demi Marie Obenour (she/her/hers)

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 7253 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2025-07-11  1:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-10 22:10 [XEN PATCH] xen/arm: address violation of MISRA C Rule 10.1 Dmytro Prokopchuk1
2025-07-10 22:12 ` Dmytro Prokopchuk1
2025-07-11  0:15 ` Stefano Stabellini
2025-07-11  1:25   ` Demi Marie Obenour [this message]
2025-07-11  6:52   ` 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=f84fc6f5-e11a-4e00-820c-d8146d4c8aea@gmail.com \
    --to=demiobenour@gmail.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=anthony.perard@vates.tech \
    --cc=bertrand.marquis@arm.com \
    --cc=dmytro_prokopchuk1@epam.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=michal.orzel@amd.com \
    --cc=rahul.singh@arm.com \
    --cc=roger.pau@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /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.