All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mykyta Poturai <Mykyta_Poturai@epam.com>
To: Dmytro Prokopchuk1 <dmytro_prokopchuk1@epam.com>,
	"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: "Jan Beulich" <jbeulich@suse.com>,
	"Roger Pau Monné" <roger@xenproject.com>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Anthony PERARD" <anthony.perard@vates.tech>,
	"Michal Orzel" <michal.orzel@amd.com>,
	"Julien Grall" <julien@xen.org>,
	"Roger Pau Monné" <roger@xenproject.org>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	Xen-devel <xen-devel-bounces@lists.xenproject.org>
Subject: Re: [PATCH v2] PCI: initialize SBDF without casting away const
Date: Tue, 1 Dec 2026 08:22:01 +0000	[thread overview]
Message-ID: <DN9918A0WWT6.3O7HAFB95OBAW@epam.com> (raw)
In-Reply-To: <b5d5894ad6243b23ecf44dd4181ef244a967ee28.1795365039.git.dmytro_prokopchuk1@epam.com>

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>

      reply	other threads:[~2026-12-01  8:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 16:53 [PATCH v2] PCI: initialize SBDF without casting away const Dmytro Prokopchuk1
2026-12-01  8:22 ` Mykyta Poturai [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DN9918A0WWT6.3O7HAFB95OBAW@epam.com \
    --to=mykyta_poturai@epam.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=anthony.perard@vates.tech \
    --cc=dmytro_prokopchuk1@epam.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=michal.orzel@amd.com \
    --cc=roger@xenproject.com \
    --cc=roger@xenproject.org \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel-bounces@lists.xenproject.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.