[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2] PCI: initialize SBDF without casting away const
- To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
- From: Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>
- Date: Sun, 22 Nov 2026 16:53:34 +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=gkDBF1CTxnSXrBSIqR1c9SMz3PtmcZDzhFNiAkQZ2E8=; b=JhIk9KszKA3kcf5vnkb5XYedRbjjqh1oZiu0v8yPOHE4hspG28upJFsjxgdgDninittKMnDxGKVV/O114hcgoaEl0Vpds7Vkbao0y/woGm2FONih4lPVMgxkAd5/K/42WrsiA4MPe09L4FQjSOHiHmMOlmsbaaK7zbAWYMIAhCPZrm5mb7L7RHIh9ENcPN+qK35WJvE0HEgcTarCKVtD0SDlgu+0z/LXtiLs61znvB+iMaKZwTepHh73W3eW5Th025lrq/2wK66NiXAPrN8HvUPI4a3cHn7EzGMVvpvvsVzXHMS4upFnDDw3Te0sPKhLjTIkmuTJsR3cQ2nS1axwvQ==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BlyYGw1Q2cQnt0MuWX5SwIwc9dQfkxyMoarvMZYLo1zFz1EBNOdHF91D59UmYAcP7mTwmJbL0iV7bAPx/MV5viN6wsgJWV8BJBO0GmAJXdt19jnYbZUufZbwVvim7LNnknpsyMSfmKjlg+Ij+seLK6Xe4vH9bEvG5vuH7VgWjlGf7GTqtkDDyw+8ZwjDgDEvPOWCopTGvFKiz8x28tBInRIdm4wErweWVx5rWME09HF+qcdsCFySrKL+6a9QKey598xseQ+c+FMa34UuXEn/IFw8paGG8hOWhXf2J9ztX4FWMg179+tBRXa/EGBEwmVkEXhij0ITyb3q7851QeCBhA==
- 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>, Jan Beulich <jbeulich@xxxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>
- Delivery-date: Sun, 22 Nov 2026 16:53:50 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
- Thread-index: AQHdeqIC3nwGz5PvKUKiqmQO+EeUyg==
- Thread-topic: [PATCH v2] PCI: initialize SBDF without casting away const
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() initializes seg, bus and devfn through casts that remove
const, because those fields are members of a const union.
Drop the const qualifier and assign the whole SBDF once. That removes
the violation and replaces the three casts with a plain assignment.
No functional changes.
Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@xxxxxxxx>
---
Tect CI pipeline:
https://gitlab.com/xen-project/people/dimaprkp4k/xen/-/pipelines/3099958291
Changes in v2:
- drop the SAF-15-safe deviation
- remove const from the pci_dev union and assign the whole SBDF
Link to v1:
https://patchew.org/Xen/ed06386df3f5ae485a409e8c0bed10b01d7fd33d.1794948091.git.dmytro._5Fprokopchuk1@xxxxxxxx/
---
xen/drivers/passthrough/pci.c | 4 +---
xen/include/xen/pci.h | 2 +-
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c
index 578472d068..ca4d631d8d 100644
--- a/xen/drivers/passthrough/pci.c
+++ b/xen/drivers/passthrough/pci.c
@@ -329,9 +329,7 @@ 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;
+ pdev->sbdf = PCI_SBDF(pseg->nr, bus, devfn);
pdev->domain = NULL;
INIT_LIST_HEAD(&pdev->vf_list);
diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h
index b7a35371a7..83cbb96db1 100644
--- a/xen/include/xen/pci.h
+++ b/xen/include/xen/pci.h
@@ -109,7 +109,7 @@ struct pci_dev {
struct domain *domain;
- const union {
+ union {
struct {
uint8_t devfn;
uint8_t bus;
--
2.43.0
|