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

[PATCH] PCI: deviate MISRA R11.8 for the one-time SBDF initialization


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>
  • Date: Tue, 17 Nov 2026 20:55:50 +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=sYkqbDbK7u+marUQNZLoNIgBWgm+pKFGZslX9BnLqqk=; b=C4EW3M4493LsmQz/3vIN35UzuEZqEf0Re2ng3zE2O4w/RGND1BE9lHWELiV9z7XRLWR9BBiqi2a1Q1w5h9WhDPjuaJnZhAngQQlZxZ9Hg16AJ9ONd2Y1U39T6xvsW94PnKsSwT8hR79m7jER7DF0z9yH25aAbLDa1SAj36I3O1e4J0pJ7wJ5kXelvdTZhxu6csI2ZRsfIynROH2sMgRUeP/yr76zovEs5+92ZiJH+ZovQEEdqOc9tsq3d+JcnvZ1zdX2Wbq7/Ns1DMHtcRAbTxS9xAg1lzS9tuc8lnN+ab5toeRRXQjPVsgCCf+Dfod+ecTupg8MAjH6wXK9gWf6Gg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=gUMW3NFzBbmBDDJNTKk2eapQEOGBPtOinfmW+lV5AP3fVhU7f3iJxJakjSM4nA7w0h7UR0olEqjh2qMjH57gG3ixUVLmeS2SLAVAFPki4HzIrs5IoPgO+pcAfGdzl1lu4OYxDQ59z1go5ZtFOR1IRQ0KsIKdKiuoNKezDdjUq95IWbmIofI7Swd07Sq+vMwqKQ47exPM45gLlF4VIrAIZS+5miTVIVBPPTReRVk3xpQWu4fFJmN5+DhIK+uubi/88hHnvO263JEEd/0HZLD40gzUmVhNfjRdMTEhML0d1g19blJwefiW69oztxQGRJpdTwOKQt8U2yUKKao1wTxyTA==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:x-ms-exchange-senderadcheck"
  • Authentication-results: mx.microsoft.com 1; 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@xxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>
  • Delivery-date: Tue, 17 Nov 2026 20:56:10 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHddtYGdAaplnsBm0mPFarnWPL2Rw==
  • Thread-topic: [PATCH] PCI: deviate MISRA R11.8 for the one-time SBDF initialization

MISRA C Rule 11.8 states: "A cast shall not remove any const or volatile
qualification from the type pointed to by a pointer".

alloc_pdev() writes the device identity once. seg, bus and devfn are
members of a const union, so that write goes through a cast that removes
const. Three such casts performed the same initialization.

Store the whole sbdf in one assignment and document that cast with
one-line SAF-15-safe comment.

No functional changes.

Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@xxxxxxxx>
---
Test CI pipeline:
https://gitlab.com/xen-project/people/dimaprkp4k/xen/-/pipelines/3081067362
---
 docs/misra/safe.json          | 8 ++++++++
 xen/drivers/passthrough/pci.c | 5 ++---
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/docs/misra/safe.json b/docs/misra/safe.json
index 3584cb90c6..3503d2e808 100644
--- a/docs/misra/safe.json
+++ b/docs/misra/safe.json
@@ -124,6 +124,14 @@
         },
         {
             "id": "SAF-15-safe",
+            "analyser": {
+                "eclair": "MC3A2.R11.8"
+            },
+            "name": "Rule 11.8: one-time init of a const PCI identity",
+            "text": "The cast removes const only to initialize the const 
pci_dev identity fields (seg, bus, devfn). The const qualification prevents any 
later assignment, and this is the only write, performed before the device is 
published on alldevs_list."
+        },
+        {
+            "id": "SAF-16-safe",
             "analyser": {},
             "name": "Sentinel",
             "text": "Next ID to be used"
diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c
index 578472d068..14d59b1293 100644
--- a/xen/drivers/passthrough/pci.c
+++ b/xen/drivers/passthrough/pci.c
@@ -329,9 +329,8 @@ static struct pci_dev *alloc_pdev(struct pci_seg *pseg, u8 
bus, u8 devfn)
     if ( !pdev )
         return NULL;
 
-    *(u16*) &pdev->seg = pseg->nr;
-    *((u8*) &pdev->bus) = bus;
-    *((u8*) &pdev->devfn) = devfn;
+    /* SAF-15-safe R11.8 one-time init of the const PCI identity */
+    *(pci_sbdf_t *)&pdev->sbdf = PCI_SBDF(pseg->nr, bus, devfn);
     pdev->domain = NULL;
 
     INIT_LIST_HEAD(&pdev->vf_list);
-- 
2.43.0

 


Rackspace

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