* [PATCH v2] PCI: initialize SBDF without casting away const
@ 2026-11-22 16:53 Dmytro Prokopchuk1
2026-12-01 8:22 ` Mykyta Poturai
0 siblings, 1 reply; 2+ messages in thread
From: Dmytro Prokopchuk1 @ 2026-11-22 16:53 UTC (permalink / raw)
To: xen-devel@lists.xenproject.org
Cc: Dmytro Prokopchuk1, Jan Beulich, Roger Pau Monné,
Andrew Cooper, Anthony PERARD, Michal Orzel, Julien Grall,
Roger Pau Monné, Stefano Stabellini
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2] PCI: initialize SBDF without casting away const
2026-11-22 16:53 [PATCH v2] PCI: initialize SBDF without casting away const Dmytro Prokopchuk1
@ 2026-12-01 8:22 ` Mykyta Poturai
0 siblings, 0 replies; 2+ messages in thread
From: Mykyta Poturai @ 2026-12-01 8:22 UTC (permalink / raw)
To: Dmytro Prokopchuk1, xen-devel@lists.xenproject.org
Cc: Jan Beulich, Roger Pau Monné, Andrew Cooper, Anthony PERARD,
Michal Orzel, Julien Grall, Roger Pau Monné,
Stefano Stabellini, Xen-devel
On Sun Nov 22, 2026 at 6:53 PM EET, Dmytro Prokopchuk1 wrote:
> 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;
Reviewed-by: Mykyta Poturai <mykyta_poturai@epam.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-01 8:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 16:53 [PATCH v2] PCI: initialize SBDF without casting away const Dmytro Prokopchuk1
2026-12-01 8:22 ` Mykyta Poturai
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.