Patchwork [v2,14/30] xen/xen_platform: QOM casting sweep

login
register
mail settings
Submitter Peter Crosthwaite
Date June 24, 2013, 7 a.m.
Message ID <9d1116516fd0d5c38ff376df4b8437e197eb8295.1372055322.git.peter.crosthwaite@xilinx.com>
Download mbox | patch
Permalink /patch/253672/
State New
Headers show

Comments

Peter Crosthwaite - June 24, 2013, 7 a.m.
From: Peter Crosthwaite <peter.crosthwaite@xilinx.com>

Define and use standard QOM cast macro. Remove usages of DO_UPCAST
and direct -> style upcasting.

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

 hw/xen/xen_platform.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)
Andreas Färber - June 30, 2013, 9:32 a.m.
Am 24.06.2013 09:00, schrieb peter.crosthwaite@xilinx.com:
> From: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
> 
> Define and use standard QOM cast macro. Remove usages of DO_UPCAST
> and direct -> style upcasting.
> 
> Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
> ---
> 
>  hw/xen/xen_platform.c | 28 ++++++++++++++++------------
>  1 file changed, 16 insertions(+), 12 deletions(-)
> 
> diff --git a/hw/xen/xen_platform.c b/hw/xen/xen_platform.c
> index b6c6793..f119c44 100644
> --- a/hw/xen/xen_platform.c
> +++ b/hw/xen/xen_platform.c
> @@ -62,6 +62,10 @@ typedef struct PCIXenPlatformState {
>      int log_buffer_off;
>  } PCIXenPlatformState;
>  
> +#define TYPE_XEN_PLATFORM "xen-platform"
> +#define XEN_PLATFORM(obj) \
> +    OBJECT_CHECK(PCIXenPlatformState, (obj), TYPE_XEN_PLATFORM)
> +
>  #define XEN_PLATFORM_IOPORT 0x10
>  
>  /* Send bytes to syslog */
> @@ -88,7 +92,7 @@ static void unplug_nic(PCIBus *b, PCIDevice *d, void *o)
>      if (pci_get_word(d->config + PCI_CLASS_DEVICE) ==
>              PCI_CLASS_NETWORK_ETHERNET
>              && strcmp(d->name, "xen-pci-passthrough") != 0) {
> -        qdev_free(&d->qdev);
> +        qdev_free(DEVICE(d));
>      }
>  }
>  
> @@ -103,7 +107,7 @@ static void unplug_disks(PCIBus *b, PCIDevice *d, void *o)
>      if (pci_get_word(d->config + PCI_CLASS_DEVICE) ==
>              PCI_CLASS_STORAGE_IDE
>              && strcmp(d->name, "xen-pci-passthrough") != 0) {
> -        qdev_unplug(&(d->qdev), NULL);
> +        qdev_unplug(DEVICE(d), NULL);
>      }
>  }
>  
> @@ -114,7 +118,7 @@ static void pci_unplug_disks(PCIBus *bus)
>  
>  static void platform_fixed_ioport_writew(void *opaque, uint32_t addr, uint32_t val)
>  {
> -    PCIXenPlatformState *s = opaque;
> +    PCIXenPlatformState *s = XEN_PLATFORM(opaque);

These are superfluous since PCIXenPlatformState is passed for both
MemoryRegionOps. Dropping these hunks.

Some usages of the parent field are still left behind.

Thanks, applied to qom-next:
https://github.com/afaerber/qemu-cpu/commits/qom-next

Andreas

>  
>      switch (addr) {
>      case 0:
> @@ -164,7 +168,7 @@ static void platform_fixed_ioport_writel(void *opaque, uint32_t addr,
>  
>  static void platform_fixed_ioport_writeb(void *opaque, uint32_t addr, uint32_t val)
>  {
> -    PCIXenPlatformState *s = opaque;
> +    PCIXenPlatformState *s = XEN_PLATFORM(opaque);
>  
>      switch (addr) {
>      case 0: /* Platform flags */ {
> @@ -187,7 +191,7 @@ static void platform_fixed_ioport_writeb(void *opaque, uint32_t addr, uint32_t v
>  
>  static uint32_t platform_fixed_ioport_readw(void *opaque, uint32_t addr)
>  {
> -    PCIXenPlatformState *s = opaque;
> +    PCIXenPlatformState *s = XEN_PLATFORM(opaque);
>  
>      switch (addr) {
>      case 0:
> @@ -206,7 +210,7 @@ static uint32_t platform_fixed_ioport_readw(void *opaque, uint32_t addr)
>  
>  static uint32_t platform_fixed_ioport_readb(void *opaque, uint32_t addr)
>  {
> -    PCIXenPlatformState *s = opaque;
> +    PCIXenPlatformState *s = XEN_PLATFORM(opaque);
>  
>      switch (addr) {
>      case 0:
> @@ -222,7 +226,7 @@ static uint32_t platform_fixed_ioport_readb(void *opaque, uint32_t addr)
>  
>  static void platform_fixed_ioport_reset(void *opaque)
>  {
> -    PCIXenPlatformState *s = opaque;
> +    PCIXenPlatformState *s = XEN_PLATFORM(opaque);
>  
>      platform_fixed_ioport_writeb(s, 0, 0);
>  }
> @@ -292,7 +296,7 @@ static uint64_t xen_platform_ioport_readb(void *opaque, hwaddr addr,
>  static void xen_platform_ioport_writeb(void *opaque, hwaddr addr,
>                                         uint64_t val, unsigned int size)
>  {
> -    PCIXenPlatformState *s = opaque;
> +    PCIXenPlatformState *s = XEN_PLATFORM(opaque);
>  
>      switch (addr) {
>      case 0: /* Platform flags */
> @@ -349,7 +353,7 @@ static void platform_mmio_setup(PCIXenPlatformState *d)
>  
>  static int xen_platform_post_load(void *opaque, int version_id)
>  {
> -    PCIXenPlatformState *s = opaque;
> +    PCIXenPlatformState *s = XEN_PLATFORM(opaque);
>  
>      platform_fixed_ioport_writeb(s, 0, s->flags);
>  
> @@ -371,7 +375,7 @@ static const VMStateDescription vmstate_xen_platform = {
>  
>  static int xen_platform_initfn(PCIDevice *dev)
>  {
> -    PCIXenPlatformState *d = DO_UPCAST(PCIXenPlatformState, pci_dev, dev);
> +    PCIXenPlatformState *d = XEN_PLATFORM(dev);
>      uint8_t *pci_conf;
>  
>      pci_conf = d->pci_dev.config;
> @@ -397,7 +401,7 @@ static int xen_platform_initfn(PCIDevice *dev)
>  
>  static void platform_reset(DeviceState *dev)
>  {
> -    PCIXenPlatformState *s = DO_UPCAST(PCIXenPlatformState, pci_dev.qdev, dev);
> +    PCIXenPlatformState *s = XEN_PLATFORM(dev);
>  
>      platform_fixed_ioport_reset(s);
>  }
> @@ -420,7 +424,7 @@ static void xen_platform_class_init(ObjectClass *klass, void *data)
>  }
>  
>  static const TypeInfo xen_platform_info = {
> -    .name          = "xen-platform",
> +    .name          = TYPE_XEN_PLATFORM,
>      .parent        = TYPE_PCI_DEVICE,
>      .instance_size = sizeof(PCIXenPlatformState),
>      .class_init    = xen_platform_class_init,
>

Patch

diff --git a/hw/xen/xen_platform.c b/hw/xen/xen_platform.c
index b6c6793..f119c44 100644
--- a/hw/xen/xen_platform.c
+++ b/hw/xen/xen_platform.c
@@ -62,6 +62,10 @@  typedef struct PCIXenPlatformState {
     int log_buffer_off;
 } PCIXenPlatformState;
 
+#define TYPE_XEN_PLATFORM "xen-platform"
+#define XEN_PLATFORM(obj) \
+    OBJECT_CHECK(PCIXenPlatformState, (obj), TYPE_XEN_PLATFORM)
+
 #define XEN_PLATFORM_IOPORT 0x10
 
 /* Send bytes to syslog */
@@ -88,7 +92,7 @@  static void unplug_nic(PCIBus *b, PCIDevice *d, void *o)
     if (pci_get_word(d->config + PCI_CLASS_DEVICE) ==
             PCI_CLASS_NETWORK_ETHERNET
             && strcmp(d->name, "xen-pci-passthrough") != 0) {
-        qdev_free(&d->qdev);
+        qdev_free(DEVICE(d));
     }
 }
 
@@ -103,7 +107,7 @@  static void unplug_disks(PCIBus *b, PCIDevice *d, void *o)
     if (pci_get_word(d->config + PCI_CLASS_DEVICE) ==
             PCI_CLASS_STORAGE_IDE
             && strcmp(d->name, "xen-pci-passthrough") != 0) {
-        qdev_unplug(&(d->qdev), NULL);
+        qdev_unplug(DEVICE(d), NULL);
     }
 }
 
@@ -114,7 +118,7 @@  static void pci_unplug_disks(PCIBus *bus)
 
 static void platform_fixed_ioport_writew(void *opaque, uint32_t addr, uint32_t val)
 {
-    PCIXenPlatformState *s = opaque;
+    PCIXenPlatformState *s = XEN_PLATFORM(opaque);
 
     switch (addr) {
     case 0:
@@ -164,7 +168,7 @@  static void platform_fixed_ioport_writel(void *opaque, uint32_t addr,
 
 static void platform_fixed_ioport_writeb(void *opaque, uint32_t addr, uint32_t val)
 {
-    PCIXenPlatformState *s = opaque;
+    PCIXenPlatformState *s = XEN_PLATFORM(opaque);
 
     switch (addr) {
     case 0: /* Platform flags */ {
@@ -187,7 +191,7 @@  static void platform_fixed_ioport_writeb(void *opaque, uint32_t addr, uint32_t v
 
 static uint32_t platform_fixed_ioport_readw(void *opaque, uint32_t addr)
 {
-    PCIXenPlatformState *s = opaque;
+    PCIXenPlatformState *s = XEN_PLATFORM(opaque);
 
     switch (addr) {
     case 0:
@@ -206,7 +210,7 @@  static uint32_t platform_fixed_ioport_readw(void *opaque, uint32_t addr)
 
 static uint32_t platform_fixed_ioport_readb(void *opaque, uint32_t addr)
 {
-    PCIXenPlatformState *s = opaque;
+    PCIXenPlatformState *s = XEN_PLATFORM(opaque);
 
     switch (addr) {
     case 0:
@@ -222,7 +226,7 @@  static uint32_t platform_fixed_ioport_readb(void *opaque, uint32_t addr)
 
 static void platform_fixed_ioport_reset(void *opaque)
 {
-    PCIXenPlatformState *s = opaque;
+    PCIXenPlatformState *s = XEN_PLATFORM(opaque);
 
     platform_fixed_ioport_writeb(s, 0, 0);
 }
@@ -292,7 +296,7 @@  static uint64_t xen_platform_ioport_readb(void *opaque, hwaddr addr,
 static void xen_platform_ioport_writeb(void *opaque, hwaddr addr,
                                        uint64_t val, unsigned int size)
 {
-    PCIXenPlatformState *s = opaque;
+    PCIXenPlatformState *s = XEN_PLATFORM(opaque);
 
     switch (addr) {
     case 0: /* Platform flags */
@@ -349,7 +353,7 @@  static void platform_mmio_setup(PCIXenPlatformState *d)
 
 static int xen_platform_post_load(void *opaque, int version_id)
 {
-    PCIXenPlatformState *s = opaque;
+    PCIXenPlatformState *s = XEN_PLATFORM(opaque);
 
     platform_fixed_ioport_writeb(s, 0, s->flags);
 
@@ -371,7 +375,7 @@  static const VMStateDescription vmstate_xen_platform = {
 
 static int xen_platform_initfn(PCIDevice *dev)
 {
-    PCIXenPlatformState *d = DO_UPCAST(PCIXenPlatformState, pci_dev, dev);
+    PCIXenPlatformState *d = XEN_PLATFORM(dev);
     uint8_t *pci_conf;
 
     pci_conf = d->pci_dev.config;
@@ -397,7 +401,7 @@  static int xen_platform_initfn(PCIDevice *dev)
 
 static void platform_reset(DeviceState *dev)
 {
-    PCIXenPlatformState *s = DO_UPCAST(PCIXenPlatformState, pci_dev.qdev, dev);
+    PCIXenPlatformState *s = XEN_PLATFORM(dev);
 
     platform_fixed_ioport_reset(s);
 }
@@ -420,7 +424,7 @@  static void xen_platform_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo xen_platform_info = {
-    .name          = "xen-platform",
+    .name          = TYPE_XEN_PLATFORM,
     .parent        = TYPE_PCI_DEVICE,
     .instance_size = sizeof(PCIXenPlatformState),
     .class_init    = xen_platform_class_init,