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

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


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>
  • Date: Mon, 14 Jul 2025 13:26:55 +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=1HYII8dLIgknBpnIAFDugGfe9Sr4+gayrgBb2Ut8MfU=; b=PVVm7sqsB7XpZIvEYNvYfJcxst7WyKwPApk0KIYMX0MfUN9GScUN3o3egNiFoauM4OdwsLGp8/HjbasE0epKMgLTqADUPR9HpmabYjaUvNpq+QKISoR+gT3ZKd4PSwU3DYfIpr1elvod5V9Zbugy3L7Y2UAEypyMcdC6jso9285PdS/fatwirXpRTbHOhJzjHeaawoxVKAEEJ/YXalFowG/6NFmDgfGkxCSSExjvuVZAI5PT76QLsO/NP8IDIzuNAeHGh2WgDtHpde3aU0mxZb8ja+dPVHHQu2bArVSeMYgJSSaLgApt2mIdZMc67cqDceMi7lcV3UAIPcpYFebVHw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AMfbCoofKu7A6bPG4uar0Ek32KsD5wxGCXSEMuUX2Mzrx684G0i8AgCILSp1mFPKWKMhwJLtVlFejMJBzTTIWFnvaGGlypqwkj45h6ixZZh162sn/zqfQjwGiKfk5SP7fIXlV5+w+hBeDakhH+2TaZMCEEwzIWEJPTVVzx08s2RGsEZmeBMyEM92AxKOKQrOjq0Y0TmrnZo2hfIYf3MfVdwLuk+hrknd5LmsX9QAodi8jTJXUBUTJ05tIrbJ12hFZefugQ5amcNJDl3icYmfdsUdJ/Xz3cwp3KRci7yQCMN/sZltz3OVkn3uVxs+CH433HJCYzzFNHlPgJleHMF70A==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Rahul Singh <rahul.singh@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Mon, 14 Jul 2025 13:27:11 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHb9ML3JOK9JlDJdUaOuavuvAHq4g==
  • Thread-topic: [XEN PATCH v3] misra: address violation of MISRA C Rule 10.1

Rule 10.1: Operands shall not be of an
inappropriate essential type

The following are non-compliant:
- boolean used as a numeric value.

The result of the '__isleap' macro is a boolean.
Use a ternary operator to replace it with a numeric value.

The result of 'NOW() > timeout' is a boolean,
which is compared to a numeric value. Fix this.
Regression was introdiced by commit:
be7f047e08 (xen/arm: smmuv3: Replace linux functions with xen functions.)

Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@xxxxxxxx>
---
Changes since v2:
- improve the wording
Link to v2: 
https://patchew.org/Xen/41538b6b19811eb74c183051d3e7a4fd216404e6.1752232902.git.dmytro._5Fprokopchuk1@xxxxxxxx/
Link to the deviation of an unary minus: 
https://patchew.org/Xen/7e6263a15c71aafc41fe72cecd1f15c3ce8846f2.1752492180.git.dmytro._5Fprokopchuk1@xxxxxxxx/

Jan, regarding that:
If an expression is needed here, I'd suggest to use !!, as we have in
(luckily decreasing) number of places elsewhere. Personally I don't
understand though why a boolean cannot be used as an array index.

The '!!' isn't a solution here, we'll have other violation:
`!' logical negation operator has essential type boolean and standard type `int'
(https://saas.eclairit.com:3787/fs/var/local/eclair/xen-project.ecdf/xen-project/people/dimaprkp4k/xen/ECLAIR_normal/deviate_10.1_rule/ARM64/10674114852/PROJECT.ecd;/by_service/MC3A2.R10.1.html#{%22select%22:true,%22selection%22:{%22hiddenAreaKinds%22:[],%22hiddenSubareaKinds%22:[],%22show%22:false,%22selector%22:{%22enabled%22:true,%22negated%22:true,%22kind%22:0,%22domain%22:%22kind%22,%22inputs%22:[{%22enabled%22:true,%22text%22:%22violation%22}]}}})

Well, in our case boolean can be used as an array index.
But index value is limited: 0 or 1.
I guess MISRA wants to predict such errors related to index limitations.
And I think fixing the code is easier here, instead of writing a deviation.

---
 xen/common/time.c                     | 2 +-
 xen/drivers/passthrough/arm/smmu-v3.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

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) {
-- 
2.43.0



 


Rackspace

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