[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [XEN PATCH v2] misra: address violation of MISRA C Rule 10.1


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>
  • Date: Fri, 11 Jul 2025 12:30:38 +0000
  • Accept-language: en-US, uk-UA, ru-RU
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QWR3LNW7/lOtcv1pimKZ0hL69pR7li6rZMCPNiNAhSE=; b=QxBxOUTnR7H6qnKmswXH0jnmPaLdrGfHsPuRtnqbYfUXWFBWwTT4O2yRfclUpVGSli9xJdXcyOV+74krMJOs8q1L5gD6tMX6sIUJClx2GoAbY5hUGkXUbgK4j3v23/x4r2iJPCbcVpGdzKhuEYzKmKqJnXKsc68Oxjhu9QAO68jssW6n1TLCMAWDBHb0s0PWmszX24RO3a+wsIwezko5GTuczKZtW80VR/DtNikJT6buidjeDLbWbIieaNVm9NiDny8N52aXcWuLRau1LstWG5AfvPpgmmi7gbZ7jnjL/aCNH/jBbCg4Ya1QhXnclFywTcMz78LB56UFgUcgt9KrGw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dPOg49nmjQkLsc4FfmzYDYARDw4RFO3io35Zoi5HR+gRX6OnnxtfQ1NY7E5gBN6HJqI3I6SSvr4QMp3xV1/unrIopIo2zmGqLLZafcOxJggNiONOPmOYLE8/ywDpB68LfbWGwYBrSg285iBUFMczqsbC0OVg2UpE8er+xUj1uXWJLVbmwFcuzAhAPaseom+L6GFNyjyahJ493bD3L9Nhu5lrELSSbkLSRN4cDF0H5vMNq5lbGLcfm1H6uIPZs/n7hQy1x+L5l22ToWy6reXOSyseLoaCJ7VH8yngOQhmC9adWQ9RhyF5wA7s+5CV54I4Ywg45OSynThOs1dZI9TlqA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Rahul Singh <rahul.singh@xxxxxxx>
  • Delivery-date: Fri, 11 Jul 2025 12:30:46 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHb8lj8U0c0yIOr5EqfSUQdGwVgzbQsz+YAgAAKnYA=
  • Thread-topic: [XEN PATCH v2] misra: address violation of MISRA C Rule 10.1


On 7/11/25 14:52, Dmytro Prokopchuk wrote:
> Hi All.
> 
> In this 2nd version I made changes according to the
> https://patchew.org/Xen/ 
> d92cf08a64d8197a1d1a45f901e59183105d3da5.1752183472.git.dmytro._5Fprokopchuk1@xxxxxxxx/
> 
> There are 0 violations on the ARM64 as you can see in the report:
> https://saas.eclairit.com:3787/fs/var/local/eclair/xen-project.ecdf/xen- 
> project/people/dimaprkp4k/xen/ECLAIR_normal/fix_10.1_rule/ 
> ARM64/10650097988/PROJECT.ecd;/by_service.html#service&kind
> 
> Jan mentioned:
> "As to the kind of change here - didn't we deviate applying unary minus 
> to unsigned types?"
> 
> Here is that deviation:
> https://patchew.org/ 
> Xen/7c7b7a09e9d5ac1cc6f93fecacd8065fb6f25324.1745427770.git.victorm.lira@xxxxxxx/
> As you can see from report
> https://saas.eclairit.com:3787/fs/var/local/eclair/xen-project.ecdf/xen- 
> project/people/dimaprkp4k/xen/ECLAIR_normal/deviate_10.1_rule/ 
> ARM64/10648749555/PROJECT.ecd;/by_service.html#service&kind
> there are still 2 violations.
> And they can be easily fixed.
> 
> So, Jan and Stefano,
> which approach should we select?

 From the other hands deviation reduces number of violations on x86 from 
170 to 83.

https://saas.eclairit.com:3787/fs/var/local/eclair/xen-project.ecdf/xen-project/people/dimaprkp4k/xen/ECLAIR_normal/fix_10.1_rule/X86_64/10650119508/PROJECT.ecd;/by_service.html#service&kind

https://saas.eclairit.com:3787/fs/var/local/eclair/xen-project.ecdf/xen-project/people/dimaprkp4k/xen/ECLAIR_normal/deviate_10.1_rule/X86_64/10650467651/PROJECT.ecd;/by_service.html#service&kind

> 
> BR, Dmytro.
> 
> On 7/11/25 14:43, 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.
>>
>> Precede unary '-' operator with casting to signed type.
>> Replace numeric constant '-1UL' with '~0UL'.
>> Replace numeric constant '-1ULL' with '~0ULL'.
>> Replace boolean with numeric value.
>>
>> Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@xxxxxxxx>
>> ---
>> Changes since v1:
>> - changed patch subject prefix
>> - multiplication replaced with cast
>> Link to v1: https://eur01.safelinks.protection.outlook.com/? 
>> url=https%3A%2F%2Fpatchew.org%2FXen%2Fd92cf08a64d8197a1d1a45f901e59183105d3da5.1752183472.git.dmytro._5Fprokopchuk1%40epam.com%2F&data=05%7C02%7Cdmytro_prokopchuk1%40epam.com%7C42e7c8ad636c47fb5b6b08ddc0701e86%7Cb41b72d04e9f4c268a69f949f367c91d%7C1%7C0%7C638878309987993462%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=bOqJU%2BVjT4wsu4z20vlHIucpaLhYa4AIvQKNmGjRcXc%3D&reserved=0
>> ---
>>   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())))
>>   #undef GIC_DEBUG
>> diff --git a/xen/common/memory.c b/xen/common/memory.c
>> index 46620ed825..0a5b3fab04 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, - 
>> (long)dec_count));
>>                   nrspin_unlock(&d->page_alloc_lock);
>>                   if ( drop_dom_ref )
>> diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
>> index 8f93a4c354..da8dddf934 100644
>> --- a/xen/common/page_alloc.c
>> +++ b/xen/common/page_alloc.c
>> @@ -691,7 +691,7 @@ size_param("low_mem_virq_limit", opt_low_mem_virq);
>>   /* Thresholds to control hysteresis. In pages */
>>   /* When memory grows above this threshold, reset hysteresis.
>>    * -1 initially to not reset until at least one virq issued. */
>> -static unsigned long low_mem_virq_high      = -1UL;
>> +static unsigned long low_mem_virq_high      = ~0UL;
>>   /* Threshold at which we issue virq */
>>   static unsigned long low_mem_virq_th        = 0;
>>   /* Original threshold after all checks completed */
>> @@ -710,7 +710,7 @@ static void __init setup_low_mem_virq(void)
>>        * to ever trigger. */
>>       if ( opt_low_mem_virq == 0 )
>>       {
>> -        low_mem_virq_th = -1UL;
>> +        low_mem_virq_th = ~0UL;
>>           return;
>>       }
>> @@ -778,7 +778,7 @@ static void check_low_mem_virq(void)
>>           low_mem_virq_th_order++;
>>           low_mem_virq_th = 1UL << low_mem_virq_th_order;
>>           if ( low_mem_virq_th == low_mem_virq_orig )
>> -            low_mem_virq_high = -1UL;
>> +            low_mem_virq_high = ~0UL;
>>           else
>>               low_mem_virq_high = 1UL << (low_mem_virq_th_order + 2);
>>       }
>> diff --git a/xen/common/time.c b/xen/common/time.c
>> index 92f7b72464..980dddee28 100644
>> --- a/xen/common/time.c
>> +++ b/xen/common/time.c
>> @@ -84,7 +84,7 @@ struct tm gmtime(unsigned long t)
>>       }
>>       tbuf.tm_year = y - 1900;
>>       tbuf.tm_yday = days;
>> -    ip = (const unsigned short int *)__mon_lengths[__isleap(y)];
>> +    ip = (const unsigned short int *)__mon_lengths[__isleap(y) ? 1 : 0];
>>       for ( y = 0; days >= ip[y]; ++y )
>>           days -= ip[y];
>>       tbuf.tm_mon = y;
>> diff --git a/xen/drivers/passthrough/arm/smmu-v3.c b/xen/drivers/ 
>> passthrough/arm/smmu-v3.c
>> index df16235057..4058b18f2c 100644
>> --- a/xen/drivers/passthrough/arm/smmu-v3.c
>> +++ b/xen/drivers/passthrough/arm/smmu-v3.c
>> @@ -315,7 +315,7 @@ static int queue_poll_cons(struct arm_smmu_queue 
>> *q, bool sync, bool wfe)
>>       while (queue_sync_cons_in(q),
>>             (sync ? !queue_empty(&q->llq) : queue_full(&q->llq))) {
>> -        if ((NOW() > timeout) > 0)
>> +        if (NOW() > timeout)
>>               return -ETIMEDOUT;
>>           if (wfe) {
>> diff --git a/xen/lib/strtol.c b/xen/lib/strtol.c
>> index 30dca779cf..c68d133657 100644
>> --- a/xen/lib/strtol.c
>> +++ b/xen/lib/strtol.c
>> @@ -13,7 +13,7 @@
>>   long simple_strtol(const char *cp, const char **endp, unsigned int 
>> base)
>>   {
>>       if ( *cp == '-' )
>> -        return -simple_strtoul(cp + 1, endp, base);
>> +        return -(long)simple_strtoul(cp + 1, endp, base);
>>       return simple_strtoul(cp, endp, base);
>>   }
>> diff --git a/xen/lib/strtoll.c b/xen/lib/strtoll.c
>> index 5d23fd80e8..6861d55929 100644
>> --- a/xen/lib/strtoll.c
>> +++ b/xen/lib/strtoll.c
>> @@ -13,7 +13,7 @@
>>   long long simple_strtoll(const char *cp, const char **endp, unsigned 
>> int base)
>>   {
>>       if ( *cp == '-' )
>> -        return -simple_strtoull(cp + 1, endp, base);
>> +        return -(long long)simple_strtoull(cp + 1, endp, base);
>>       return simple_strtoull(cp, endp, base);
>>   }

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.