qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Zhenzhong Duan <zhenzhong.duan@intel.com>, qemu-devel@nongnu.org
Cc: alex.williamson@redhat.com, clg@redhat.com,
	eric.auger@redhat.com, chao.p.peng@intel.com
Subject: Re: [PATCH] vfio: Introduce helper vfio_device_to_vfio_pci()
Date: Thu, 31 Jul 2025 10:26:07 +0200	[thread overview]
Message-ID: <1e5263cc-23fb-44cf-a8c1-f01b6fbb6ef3@linaro.org> (raw)
In-Reply-To: <20250731033123.1093663-1-zhenzhong.duan@intel.com>

Hi,

On 31/7/25 05:31, Zhenzhong Duan wrote:
> Introduce helper vfio_device_to_vfio_pci() to transform from VFIODevice to
> VFIOPCIDevice, also to hide low level VFIO_DEVICE_TYPE_PCI type check.
> 
> Suggested-by: Cédric Le Goater <clg@redhat.com>
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
> ---
>   include/hw/vfio/vfio-device.h |  1 +
>   hw/vfio/container.c           |  4 ++--
>   hw/vfio/device.c              | 10 +++++++++-
>   hw/vfio/iommufd.c             |  4 ++--
>   hw/vfio/listener.c            |  4 ++--
>   5 files changed, 16 insertions(+), 7 deletions(-)
> 
> diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h
> index 6e4d5ccdac..00df40d997 100644
> --- a/include/hw/vfio/vfio-device.h
> +++ b/include/hw/vfio/vfio-device.h
> @@ -157,6 +157,7 @@ bool vfio_device_attach_by_iommu_type(const char *iommu_type, char *name,
>                                         Error **errp);
>   void vfio_device_detach(VFIODevice *vbasedev);
>   VFIODevice *vfio_get_vfio_device(Object *obj);
> +struct VFIOPCIDevice *vfio_device_to_vfio_pci(VFIODevice *vbasedev);

Please return the typedef (like in the implementation), not the struct.

A one line comment describing what this helper does would he helpful.

Regards,

Phil.

> diff --git a/hw/vfio/device.c b/hw/vfio/device.c
> index 52a1996dc4..a4f9c9216c 100644
> --- a/hw/vfio/device.c
> +++ b/hw/vfio/device.c


> @@ -429,6 +429,14 @@ VFIODevice *vfio_get_vfio_device(Object *obj)
>       }
>   }
>   
> +VFIOPCIDevice *vfio_device_to_vfio_pci(VFIODevice *vbasedev)
> +{
> +    if (vbasedev && vbasedev->type == VFIO_DEVICE_TYPE_PCI) {
> +        return container_of(vbasedev, VFIOPCIDevice, vbasedev);
> +    }
> +    return NULL;
> +}



  parent reply	other threads:[~2025-07-31  8:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-31  3:31 [PATCH] vfio: Introduce helper vfio_device_to_vfio_pci() Zhenzhong Duan
2025-07-31  8:01 ` Cédric Le Goater
2025-07-31  8:26 ` Philippe Mathieu-Daudé [this message]
2025-07-31  8:49   ` Duan, Zhenzhong
2025-07-31 11:24     ` Philippe Mathieu-Daudé
2025-07-31 12:03       ` Cédric Le Goater

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=1e5263cc-23fb-44cf-a8c1-f01b6fbb6ef3@linaro.org \
    --to=philmd@linaro.org \
    --cc=alex.williamson@redhat.com \
    --cc=chao.p.peng@intel.com \
    --cc=clg@redhat.com \
    --cc=eric.auger@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=zhenzhong.duan@intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).