diff mbox

[2/6] hw/char: QOM'ify etraxfs_ser.c

Message ID 1458206430-21917-3-git-send-email-zxq_yx_007@163.com (mailing list archive)
State New, archived
Headers show

Commit Message

zhao xiao qiang March 17, 2016, 9:20 a.m. UTC
Drop the old SysBus init function and use instance_init

Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com>
---
 hw/char/etraxfs_ser.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Comments

Edgar E. Iglesias May 6, 2016, 7:42 a.m. UTC | #1
On Thu, Mar 17, 2016 at 05:20:26PM +0800, xiaoqiang zhao wrote:
> Drop the old SysBus init function and use instance_init
> 
> Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com>

Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Tested-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>


> ---
>  hw/char/etraxfs_ser.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/char/etraxfs_ser.c b/hw/char/etraxfs_ser.c
> index 146b387..ede7024 100644
> --- a/hw/char/etraxfs_ser.c
> +++ b/hw/char/etraxfs_ser.c
> @@ -209,12 +209,13 @@ static void etraxfs_ser_reset(DeviceState *d)
>  
>  }
>  
> -static int etraxfs_ser_init(SysBusDevice *dev)
> +static void etraxfs_ser_init(Object *obj)
>  {
> -    ETRAXSerial *s = ETRAX_SERIAL(dev);
> +    ETRAXSerial *s = ETRAX_SERIAL(obj);
> +    SysBusDevice *dev = SYS_BUS_DEVICE(obj);
>  
>      sysbus_init_irq(dev, &s->irq);
> -    memory_region_init_io(&s->mmio, OBJECT(s), &ser_ops, s,
> +    memory_region_init_io(&s->mmio, obj, &ser_ops, s,
>                            "etraxfs-serial", R_MAX * 4);
>      sysbus_init_mmio(dev, &s->mmio);
>  
> @@ -225,15 +226,12 @@ static int etraxfs_ser_init(SysBusDevice *dev)
>                                serial_can_receive, serial_receive,
>                                serial_event, s);
>      }
> -    return 0;
>  }
>  
>  static void etraxfs_ser_class_init(ObjectClass *klass, void *data)
>  {
>      DeviceClass *dc = DEVICE_CLASS(klass);
> -    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
>  
> -    k->init = etraxfs_ser_init;
>      dc->reset = etraxfs_ser_reset;
>      /* Reason: init() method uses qemu_char_get_next_serial() */
>      dc->cannot_instantiate_with_device_add_yet = true;
> @@ -243,6 +241,7 @@ static const TypeInfo etraxfs_ser_info = {
>      .name          = TYPE_ETRAX_FS_SERIAL,
>      .parent        = TYPE_SYS_BUS_DEVICE,
>      .instance_size = sizeof(ETRAXSerial),
> +    .instance_init = etraxfs_ser_init,
>      .class_init    = etraxfs_ser_class_init,
>  };
>  
> -- 
> 2.1.4
> 
>
Paolo Bonzini May 9, 2016, 10:51 a.m. UTC | #2
On 17/03/2016 10:20, xiaoqiang zhao wrote:
> Drop the old SysBus init function and use instance_init
> 
> Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com>
> ---
>  hw/char/etraxfs_ser.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/char/etraxfs_ser.c b/hw/char/etraxfs_ser.c
> index 146b387..ede7024 100644
> --- a/hw/char/etraxfs_ser.c
> +++ b/hw/char/etraxfs_ser.c
> @@ -209,12 +209,13 @@ static void etraxfs_ser_reset(DeviceState *d)
>  
>  }
>  
> -static int etraxfs_ser_init(SysBusDevice *dev)
> +static void etraxfs_ser_init(Object *obj)
>  {
> -    ETRAXSerial *s = ETRAX_SERIAL(dev);
> +    ETRAXSerial *s = ETRAX_SERIAL(obj);
> +    SysBusDevice *dev = SYS_BUS_DEVICE(obj);
>  
>      sysbus_init_irq(dev, &s->irq);
> -    memory_region_init_io(&s->mmio, OBJECT(s), &ser_ops, s,
> +    memory_region_init_io(&s->mmio, obj, &ser_ops, s,
>                            "etraxfs-serial", R_MAX * 4);
>      sysbus_init_mmio(dev, &s->mmio);
>  
> @@ -225,15 +226,12 @@ static int etraxfs_ser_init(SysBusDevice *dev)
>                                serial_can_receive, serial_receive,
>                                serial_event, s);

The missing context has a qemu_char_get_next_serial() call, so this
patch is not good either.

Paolo

>      }
> -    return 0;
>  }
>  
>  static void etraxfs_ser_class_init(ObjectClass *klass, void *data)
>  {
>      DeviceClass *dc = DEVICE_CLASS(klass);
> -    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
>  
> -    k->init = etraxfs_ser_init;
>      dc->reset = etraxfs_ser_reset;
>      /* Reason: init() method uses qemu_char_get_next_serial() */
>      dc->cannot_instantiate_with_device_add_yet = true;
> @@ -243,6 +241,7 @@ static const TypeInfo etraxfs_ser_info = {
>      .name          = TYPE_ETRAX_FS_SERIAL,
>      .parent        = TYPE_SYS_BUS_DEVICE,
>      .instance_size = sizeof(ETRAXSerial),
> +    .instance_init = etraxfs_ser_init,
>      .class_init    = etraxfs_ser_class_init,
>  };
>  
>
diff mbox

Patch

diff --git a/hw/char/etraxfs_ser.c b/hw/char/etraxfs_ser.c
index 146b387..ede7024 100644
--- a/hw/char/etraxfs_ser.c
+++ b/hw/char/etraxfs_ser.c
@@ -209,12 +209,13 @@  static void etraxfs_ser_reset(DeviceState *d)
 
 }
 
-static int etraxfs_ser_init(SysBusDevice *dev)
+static void etraxfs_ser_init(Object *obj)
 {
-    ETRAXSerial *s = ETRAX_SERIAL(dev);
+    ETRAXSerial *s = ETRAX_SERIAL(obj);
+    SysBusDevice *dev = SYS_BUS_DEVICE(obj);
 
     sysbus_init_irq(dev, &s->irq);
-    memory_region_init_io(&s->mmio, OBJECT(s), &ser_ops, s,
+    memory_region_init_io(&s->mmio, obj, &ser_ops, s,
                           "etraxfs-serial", R_MAX * 4);
     sysbus_init_mmio(dev, &s->mmio);
 
@@ -225,15 +226,12 @@  static int etraxfs_ser_init(SysBusDevice *dev)
                               serial_can_receive, serial_receive,
                               serial_event, s);
     }
-    return 0;
 }
 
 static void etraxfs_ser_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-    k->init = etraxfs_ser_init;
     dc->reset = etraxfs_ser_reset;
     /* Reason: init() method uses qemu_char_get_next_serial() */
     dc->cannot_instantiate_with_device_add_yet = true;
@@ -243,6 +241,7 @@  static const TypeInfo etraxfs_ser_info = {
     .name          = TYPE_ETRAX_FS_SERIAL,
     .parent        = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(ETRAXSerial),
+    .instance_init = etraxfs_ser_init,
     .class_init    = etraxfs_ser_class_init,
 };