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@epam.com>
---
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@epam.com/
---
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