Patchwork [RFT,v1,12/30] virtio/virtio-pci: QOM casting sweep

login
register
mail settings
Submitter Peter Crosthwaite
Date June 11, 2013, 6:49 a.m.
Message ID <2015a3db86888f2c28f4023ccf196a02c2196762.1370931825.git.peter.crosthwaite@xilinx.com>
Download mbox | patch
Permalink /patch/250460/
State New
Headers show

Comments

Peter Crosthwaite - June 11, 2013, 6:49 a.m.
From: Peter Crosthwaite <peter.crosthwaite@xilinx.com>

Use standard QOM cast macro. Remove usages of container_of() and
direct -> style upcasting.

Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
---

 hw/virtio/virtio-pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fred.konrad@greensocs.com - June 11, 2013, 7:09 a.m.
Hi,

On 11/06/2013 08:49, peter.crosthwaite@xilinx.com wrote:
> From: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
>
> Use standard QOM cast macro. Remove usages of container_of() and
> direct -> style upcasting.
>
> Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
[...]
>   static inline VirtIOPCIProxy *to_virtio_pci_proxy(DeviceState *d)
>   {
> -    return container_of(d, VirtIOPCIProxy, pci_dev.qdev);
> +    return VIRTIO_PCI(d);
>   }

Maybe you can replace each to_virtio_pci_proxy directly with VIRTIO_PCI?
>   
>   /* DeviceState to VirtIOPCIProxy. Note: used on datapath,
> @@ -106,7 +106,7 @@ static inline VirtIOPCIProxy *to_virtio_pci_proxy(DeviceState *d)
>    */
>   static inline VirtIOPCIProxy *to_virtio_pci_proxy_fast(DeviceState *d)
>   {
> -    return container_of(d, VirtIOPCIProxy, pci_dev.qdev);
> +    return VIRTIO_PCI(d);
>   }
>   
>   static void virtio_pci_notify(DeviceState *d, uint16_t vector)
Peter Crosthwaite - June 24, 2013, 5 a.m.
Hi Frederic,

On Tue, Jun 11, 2013 at 5:09 PM, Frederic Konrad
<fred.konrad@greensocs.com> wrote:
> Hi,
>
>
> On 11/06/2013 08:49, peter.crosthwaite@xilinx.com wrote:
>>
>> From: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
>>
>> Use standard QOM cast macro. Remove usages of container_of() and
>> direct -> style upcasting.
>>
>> Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
>
> [...]
>
>>   static inline VirtIOPCIProxy *to_virtio_pci_proxy(DeviceState *d)
>>   {
>> -    return container_of(d, VirtIOPCIProxy, pci_dev.qdev);
>> +    return VIRTIO_PCI(d);
>>   }
>
>
> Maybe you can replace each to_virtio_pci_proxy directly with VIRTIO_PCI?
>

I'm going to drop this one V2 for the moment and revisit is later. Its
more complicated, given the replications between the fast and slow
versions and needs a little more research (and a mini series of its
own).

Regards,
Peter

Patch

diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 444b71a..a6cad0d 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -98,7 +98,7 @@  static void virtio_pci_bus_new(VirtioBusState *bus, VirtIOPCIProxy *dev);
 /* DeviceState to VirtIOPCIProxy. For use off data-path. TODO: use QOM. */
 static inline VirtIOPCIProxy *to_virtio_pci_proxy(DeviceState *d)
 {
-    return container_of(d, VirtIOPCIProxy, pci_dev.qdev);
+    return VIRTIO_PCI(d);
 }
 
 /* DeviceState to VirtIOPCIProxy. Note: used on datapath,
@@ -106,7 +106,7 @@  static inline VirtIOPCIProxy *to_virtio_pci_proxy(DeviceState *d)
  */
 static inline VirtIOPCIProxy *to_virtio_pci_proxy_fast(DeviceState *d)
 {
-    return container_of(d, VirtIOPCIProxy, pci_dev.qdev);
+    return VIRTIO_PCI(d);
 }
 
 static void virtio_pci_notify(DeviceState *d, uint16_t vector)