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

Re: [PATCH v2] PCI: initialize SBDF without casting away const


  • To: Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Mykyta Poturai <Mykyta_Poturai@xxxxxxxx>
  • Date: Tue, 1 Dec 2026 08:22:01 +0000
  • Accept-language: en-US
  • 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=7bGnoTTSRSSyhw3gvip/KHh/fXU2tXlItkWTI/oSR80=; b=vzOh1/g6Fqp8pgGMnHp8wLPoTEPotlPoOH09RVFj6rBzLWRMwmblhDfnOpbXyZqNAV3wN4Cc1vYUECZTLJxDUnzOcNuXQ2tlPJNMh35QqZLMMQvWidXCje7Jxro+PplmgyMHUK3A6N5I32V7dfmpQuG1ARigcr8+B+3F7FgbHJQ+mOWMkbB9dnvTSUrSa6Le1dbqIqA3bGV3tXerTPDbpAzu9rFWqIOMRQXVTjigul4HhHGinw4LcymL6c8BAwAsaP3s9gextBeHrVB84GVWhsv4RveRjHszV8IfL+HaG8E+7gF9RvbbQVdxceE+AFA66CnY5rIGc82cPzURk+kLEw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=O8Ei3ytmKqp2D8lxiOqADbD5jyXG2YLno7rWkKywqigB5EtKRafffEnTzX2Otn+MVEbLezxggTf2hzJm684U2euphEGYGIhjzpemD4Wcvz3wVOwsO6pdXY2hELC4fi8P/Zf1EGVMPdZWMQWm7bqqb0arqLc+XuNgAxwr7pPTVEJRPs7+PxrCl+Sw+KAso54mxYNonZVbUgMhLWuCt8XBhLIPXu6QSLPK3kNAJ25DXBJW6GFz1ogKAuUdmbAYGxLQutmMNIfRXsRZXfQxmhHSZQM3pcfNiDUlgkUFOhV5LgCjLklN3DA9hgVMRX8p5Y0IZXwJxCsLYetP6iDA9S1bKw==
  • 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: 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>, Xen-devel <xen-devel-bounces@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 01 Dec 2026 08:22:13 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHdeqIC3nwGz5PvKUKiqmQO+EeUyrdH5M4A
  • Thread-topic: [PATCH v2] PCI: initialize SBDF without casting away const

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@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;

Reviewed-by: Mykyta Poturai <mykyta_poturai@xxxxxxxx>

 


Rackspace

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