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

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


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>
  • Date: Tue, 15 Jul 2025 09:31:42 +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=AbFVt0C7vOHCZC2L6ii2U+O+joo2XPYh+CKP4ivmrJA=; b=Q3X5cr5oSFxj2PAQkns7jNiiXqsyJzu1FW5IqcmR5zpaekeakiITUmDDVcX4n6ggpAvVG7Hgi6rLPOpNwA730UWrqPnpvMHqpbiGK394T/ZrmRCz3hXiWtNKBI3kByhHSY67sOs9DyUOMDT0HknsTGTg9L5SNNGhGYva6wvZNQI+BM3wXWv+ufPURFu/PHmQh/Ivh0A+STLpGSWTvLaf4JTZ8j/ayrJIqLmpzm63me7r+ROzvmhvNvuCe8lGZso0e1r7euAh3PTiH4J/OK5nKytADtBERmPvGCR0sixdCf66/GX6X6mEcRcaU+wxbc6nNl2nmks86W+dke4Z8mfHyw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mM16R93Y0v7ceGhxVLTTNZqfrT9rbmU06c7fzoKgodvdNQX7eebwtK93RF88KR7sSLpot8AEZlMAHQ0difZW47+CwyE+UGB8+rm/955BrdtHl0iWGfxads+ezJE+GvgP9jxORCEmfizC0TqcAEC/ynYB5e7dkqaE8otXxER0WiBN1zjTCgzhK+prQYzDuxj2m7rsJT/pEQlMm7/MTWXd5k63Zg40rtuexZpwzyOnvj2tDOtmG8bSN+2dtR2g2M0tcC1Ax9iS/2N5swfDdj8mSPHUdgBG2zdNP9yIjuZEK25OBcZVy++ZhHggnlF3nQNrWqe8uxSvr6LHB+1L0sFsdQ==
  • 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: Tue, 15 Jul 2025 09:31:56 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHb9WtGauJBpc3EJkaPoqdZvIhy9A==
  • Thread-topic: [XEN PATCH v5] 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.
Suppress analyser tool finding.

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.)

Remove pointless cast '(const unsigned short int *)'.
The source array and the destination pointer are both of the same type.

Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@xxxxxxxx>
---
Changes since v4:
- described dropping cast reason
- updated SAF text
---
 docs/misra/safe.json                  | 8 ++++++++
 xen/common/time.c                     | 3 ++-
 xen/drivers/passthrough/arm/smmu-v3.c | 2 +-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/docs/misra/safe.json b/docs/misra/safe.json
index e3489dba8e..3584cb90c6 100644
--- a/docs/misra/safe.json
+++ b/docs/misra/safe.json
@@ -116,6 +116,14 @@
         },
         {
             "id": "SAF-14-safe",
+            "analyser": {
+                "eclair": "MC3A2.R10.1"
+            },
+            "name": "Rule 10.1: use boolean as an array index",
+            "text": "Using a boolean type as an array index is safe."
+        },
+        {
+            "id": "SAF-15-safe",
             "analyser": {},
             "name": "Sentinel",
             "text": "Next ID to be used"
diff --git a/xen/common/time.c b/xen/common/time.c
index 92f7b72464..c873b5731b 100644
--- a/xen/common/time.c
+++ b/xen/common/time.c
@@ -84,7 +84,8 @@ struct tm gmtime(unsigned long t)
     }
     tbuf.tm_year = y - 1900;
     tbuf.tm_yday = days;
-    ip = (const unsigned short int *)__mon_lengths[__isleap(y)];
+    /* SAF-14-safe use boolean as an array index */
+    ip = __mon_lengths[__isleap(y)];
     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®.