summary refs log tree commit diff stats
path: root/hw/virtio-pci.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2009-08-14 10:36:05 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-08-27 20:43:28 -0500
commit81a322d4a1b68d47908a6630bf22897a289722aa (patch)
treecdca9840d0620d9e0b46d7b81c58abe04a372b78 /hw/virtio-pci.c
parent24e6f3551f3c8ea7cc7524a3e64e84beca59618f (diff)
downloadfocaccia-qemu-81a322d4a1b68d47908a6630bf22897a289722aa.tar.gz
focaccia-qemu-81a322d4a1b68d47908a6630bf22897a289722aa.zip
qdev: add return value to init() callbacks.
Sorry folks, but it has to be.  One more of these invasive qdev patches.

We have a serious design bug in the qdev interface:  device init
callbacks can't signal failure because the init() callback has no
return value.  This patch fixes it.

We have already one case in-tree where this is needed:
Try -device virtio-blk-pci (without drive= specified) and watch qemu
segfault.  This patch fixes it.

With usb+scsi being converted to qdev we'll get more devices where the
init callback can fail for various reasons.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/virtio-pci.c')
-rw-r--r--hw/virtio-pci.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index e95700a485..50765d1ba7 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -424,7 +424,7 @@ static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev,
     virtio_bind_device(vdev, &virtio_pci_bindings, proxy);
 }
 
-static void virtio_blk_init_pci(PCIDevice *pci_dev)
+static int virtio_blk_init_pci(PCIDevice *pci_dev)
 {
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
     VirtIODevice *vdev;
@@ -435,6 +435,7 @@ static void virtio_blk_init_pci(PCIDevice *pci_dev)
 
     if (!proxy->dinfo) {
         fprintf(stderr, "drive property not set\n");
+        return -1;
     }
     vdev = virtio_blk_init(&pci_dev->qdev, proxy->dinfo);
     vdev->nvectors = proxy->nvectors;
@@ -444,9 +445,10 @@ static void virtio_blk_init_pci(PCIDevice *pci_dev)
                     proxy->class_code, 0x00);
     /* make the actual value visible */
     proxy->nvectors = vdev->nvectors;
+    return 0;
 }
 
-static void virtio_console_init_pci(PCIDevice *pci_dev)
+static int virtio_console_init_pci(PCIDevice *pci_dev)
 {
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
     VirtIODevice *vdev;
@@ -461,9 +463,10 @@ static void virtio_console_init_pci(PCIDevice *pci_dev)
                     PCI_VENDOR_ID_REDHAT_QUMRANET,
                     PCI_DEVICE_ID_VIRTIO_CONSOLE,
                     proxy->class_code, 0x00);
+    return 0;
 }
 
-static void virtio_net_init_pci(PCIDevice *pci_dev)
+static int virtio_net_init_pci(PCIDevice *pci_dev)
 {
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
     VirtIODevice *vdev;
@@ -484,9 +487,10 @@ static void virtio_net_init_pci(PCIDevice *pci_dev)
 
     /* make the actual value visible */
     proxy->nvectors = vdev->nvectors;
+    return 0;
 }
 
-static void virtio_balloon_init_pci(PCIDevice *pci_dev)
+static int virtio_balloon_init_pci(PCIDevice *pci_dev)
 {
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
     VirtIODevice *vdev;
@@ -497,6 +501,7 @@ static void virtio_balloon_init_pci(PCIDevice *pci_dev)
                     PCI_DEVICE_ID_VIRTIO_BALLOON,
                     PCI_CLASS_MEMORY_RAM,
                     0x00);
+    return 0;
 }
 
 static PCIDeviceInfo virtio_info[] = {