>-----Original Message----- >From: Philippe Mathieu-Daudé <phi...@linaro.org> >Subject: Re: [PATCH] vfio: Introduce helper vfio_device_to_vfio_pci() > >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 <c...@redhat.com> >> Signed-off-by: Zhenzhong Duan <zhenzhong.d...@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.
That will break build. VFIOPCIDevice is defined in internal header hw/vfio/pci.h, while include/hw/vfio/vfio-device.h is public header, I'm not sure if it's right way to include internal header in public header. > >A one line comment describing what this helper does would he helpful. Will do. Thanks Zhenzhong > >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; >> +}