Patchwork [RFC,3/3] qdev: Hook up DeviceClass::init to ObjectClass::realize

login
register
mail settings
Submitter Andreas Färber
Date March 26, 2012, 1:46 p.m.
Message ID <1332769612-4247-4-git-send-email-afaerber@suse.de>
Download mbox | patch
Permalink /patch/148744/
State New
Headers show

Comments

Andreas Färber - March 26, 2012, 1:46 p.m.
On realize, call the qdev init function.
If that returns an error, raise QERR_DEVICE_INIT_FAILED.

Signed-off-by: Andreas Färber <afaerber@suse.de>
Cc: Anthony Liguori <anthony@codemonkey.ws>
Cc: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/qdev.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
Andreas Färber - March 26, 2012, 1:54 p.m.
Am 26.03.2012 15:46, schrieb Andreas Färber:
> On realize, call the qdev init function.

> If that returns an error, raise QERR_DEVICE_INIT_FAILED.

Sorry, that sentence is outdated - the error is set in qom/object.c
(patch 1/3) for non-zero return values. It is merely being passed
through here.

Andreas

> 
> Signed-off-by: Andreas Färber <afaerber@suse.de>
> Cc: Anthony Liguori <anthony@codemonkey.ws>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  hw/qdev.c |   13 +++++++++++++
>  1 files changed, 13 insertions(+), 0 deletions(-)
> 
> diff --git a/hw/qdev.c b/hw/qdev.c
> index ee21d90..c84b656 100644
> --- a/hw/qdev.c
> +++ b/hw/qdev.c
> @@ -649,6 +649,13 @@ static void device_finalize(Object *obj)
>      QTAILQ_REMOVE(&dev->parent_bus->children, dev, sibling);
>  }
>  
> +static int device_realize(Object *obj)
> +{
> +    DeviceState *dev = DEVICE(obj);
> +
> +    return qdev_init(dev);
> +}
> +
>  void device_reset(DeviceState *dev)
>  {
>      DeviceClass *klass = DEVICE_GET_CLASS(dev);
[snip]

Patch

diff --git a/hw/qdev.c b/hw/qdev.c
index ee21d90..c84b656 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -649,6 +649,13 @@  static void device_finalize(Object *obj)
     QTAILQ_REMOVE(&dev->parent_bus->children, dev, sibling);
 }
 
+static int device_realize(Object *obj)
+{
+    DeviceState *dev = DEVICE(obj);
+
+    return qdev_init(dev);
+}
+
 void device_reset(DeviceState *dev)
 {
     DeviceClass *klass = DEVICE_GET_CLASS(dev);
@@ -658,6 +665,11 @@  void device_reset(DeviceState *dev)
     }
 }
 
+static void device_class_init(ObjectClass *class, void *data)
+{
+    class->realize = device_realize;
+}
+
 static TypeInfo device_type_info = {
     .name = TYPE_DEVICE,
     .parent = TYPE_OBJECT,
@@ -666,6 +678,7 @@  static TypeInfo device_type_info = {
     .instance_finalize = device_finalize,
     .abstract = true,
     .class_size = sizeof(DeviceClass),
+    .class_init = device_class_init,
 };
 
 static void qdev_register_types(void)