[PATCH 12/22] vfio-user/pci.c: use QOM casts where appropriate

Mark Cave-Ayland posted 22 patches 4 months ago
Maintainers: Nicholas Piggin <npiggin@gmail.com>, Daniel Henrique Barboza <danielhb413@gmail.com>, Harsh Prateek Bora <harshpb@linux.ibm.com>, Matthew Rosato <mjrosato@linux.ibm.com>, Eric Farman <farman@linux.ibm.com>, Richard Henderson <richard.henderson@linaro.org>, David Hildenbrand <david@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>, Thomas Huth <thuth@redhat.com>, Halil Pasic <pasic@linux.ibm.com>, Christian Borntraeger <borntraeger@linux.ibm.com>, John Levon <john.levon@nutanix.com>, Thanos Makatos <thanos.makatos@nutanix.com>, Alex Williamson <alex.williamson@redhat.com>, "Cédric Le Goater" <clg@redhat.com>, Steve Sistare <steven.sistare@oracle.com>, Tomita Moeko <tomitamoeko@gmail.com>
[PATCH 12/22] vfio-user/pci.c: use QOM casts where appropriate
Posted by Mark Cave-Ayland 4 months ago
Use QOM casts to convert between VFIOUserPCIDevice and VFIOPCIDevice instead
of accessing device directly.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
---
 hw/vfio-user/pci.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/hw/vfio-user/pci.c b/hw/vfio-user/pci.c
index da6fe51809..e23a941605 100644
--- a/hw/vfio-user/pci.c
+++ b/hw/vfio-user/pci.c
@@ -214,8 +214,9 @@ static void vfio_user_compute_needs_reset(VFIODevice *vbasedev)
 
 static Object *vfio_user_pci_get_object(VFIODevice *vbasedev)
 {
-    VFIOUserPCIDevice *vdev = container_of(vbasedev, VFIOUserPCIDevice,
-                                           device.vbasedev);
+    VFIOUserPCIDevice *vdev = VFIO_USER_PCI(container_of(vbasedev,
+                                                         VFIOPCIDevice,
+                                                         vbasedev));
 
     return OBJECT(vdev);
 }
@@ -418,7 +419,7 @@ static void vfio_user_pci_set_socket(Object *obj, Visitor *v, const char *name,
     VFIOUserPCIDevice *udev = VFIO_USER_PCI(obj);
     bool success;
 
-    if (udev->device.vbasedev.proxy) {
+    if (VFIO_PCI_BASE(udev)->vbasedev.proxy) {
         error_setg(errp, "Proxy is connected");
         return;
     }
-- 
2.43.0
Re: [PATCH 12/22] vfio-user/pci.c: use QOM casts where appropriate
Posted by John Levon 4 months ago
On Tue, Jul 15, 2025 at 10:25:52AM +0100, Mark Cave-Ayland wrote:

> Use QOM casts to convert between VFIOUserPCIDevice and VFIOPCIDevice instead
> of accessing device directly.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> ---
>  hw/vfio-user/pci.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/vfio-user/pci.c b/hw/vfio-user/pci.c
> index da6fe51809..e23a941605 100644
> --- a/hw/vfio-user/pci.c
> +++ b/hw/vfio-user/pci.c
> @@ -214,8 +214,9 @@ static void vfio_user_compute_needs_reset(VFIODevice *vbasedev)
>  
>  static Object *vfio_user_pci_get_object(VFIODevice *vbasedev)
>  {
> -    VFIOUserPCIDevice *vdev = container_of(vbasedev, VFIOUserPCIDevice,
> -                                           device.vbasedev);
> +    VFIOUserPCIDevice *vdev = VFIO_USER_PCI(container_of(vbasedev,
> +                                                         VFIOPCIDevice,
> +                                                         vbasedev));
>  
>      return OBJECT(vdev);
>  }
> @@ -418,7 +419,7 @@ static void vfio_user_pci_set_socket(Object *obj, Visitor *v, const char *name,
>      VFIOUserPCIDevice *udev = VFIO_USER_PCI(obj);
>      bool success;
>  
> -    if (udev->device.vbasedev.proxy) {
> +    if (VFIO_PCI_BASE(udev)->vbasedev.proxy) {
>          error_setg(errp, "Proxy is connected");
>          return;
>      }

Reviewed-by: John Levon <john.levon@nutanix.com>