Patchwork [for-next,v2,05/22] virtio: Allow NULL VirtioDeviceClass::init hook

login
register
mail settings
Submitter Andreas Färber
Date Aug. 1, 2013, 2:17 a.m.
Message ID <1375323463-32747-6-git-send-email-afaerber@suse.de>
Download mbox | patch
Permalink /patch/263864/
State New
Headers show

Comments

Andreas Färber - Aug. 1, 2013, 2:17 a.m.
This is a temporary measure to allow mixing VirtioDeviceClass::init with
DeviceClass::realize.

Clean up variable naming in preparation for QOM realize.

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 hw/virtio/virtio.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

Patch

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 09f62c6..c00c224 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -1139,13 +1139,15 @@  void virtio_device_set_child_bus_name(VirtIODevice *vdev, char *bus_name)
     }
 }
 
-static int virtio_device_init(DeviceState *qdev)
+static int virtio_device_init(DeviceState *dev)
 {
-    VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
-    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(qdev);
-    assert(k->init != NULL);
-    if (k->init(vdev) < 0) {
-        return -1;
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+    VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(dev);
+
+    if (vdc->init != NULL) {
+        if (vdc->init(vdev) < 0) {
+            return -1;
+        }
     }
     virtio_bus_plug_device(vdev);
     return 0;