From 81a322d4a1b68d47908a6630bf22897a289722aa Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Fri, 14 Aug 2009 10:36:05 +0200 Subject: 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 Signed-off-by: Anthony Liguori --- hw/pcnet.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'hw/pcnet.c') diff --git a/hw/pcnet.c b/hw/pcnet.c index 827f6bd81f..107b5b64c3 100644 --- a/hw/pcnet.c +++ b/hw/pcnet.c @@ -1948,7 +1948,7 @@ static void pcnet_common_cleanup(PCNetState *d) qemu_free_timer(d->poll_timer); } -static void pcnet_common_init(DeviceState *dev, PCNetState *s, +static int pcnet_common_init(DeviceState *dev, PCNetState *s, NetCleanup *cleanup) { s->poll_timer = qemu_new_timer(vm_clock, pcnet_poll_timer, s); @@ -1959,6 +1959,7 @@ static void pcnet_common_init(DeviceState *dev, PCNetState *s, cleanup, s); pcnet_h_reset(s); register_savevm("pcnet", -1, 2, pcnet_save, pcnet_load, s); + return 0; } /* PCI interface */ @@ -2015,7 +2016,7 @@ static int pci_pcnet_uninit(PCIDevice *dev) return 0; } -static void pci_pcnet_init(PCIDevice *pci_dev) +static int pci_pcnet_init(PCIDevice *pci_dev) { PCIPCNetState *d = (PCIPCNetState *)pci_dev; PCNetState *s = &d->state; @@ -2061,7 +2062,7 @@ static void pci_pcnet_init(PCIDevice *pci_dev) s->phys_mem_write = pci_physical_memory_write; s->pci_dev = pci_dev; - pcnet_common_init(&pci_dev->qdev, s, pci_pcnet_cleanup); + return pcnet_common_init(&pci_dev->qdev, s, pci_pcnet_cleanup); } /* SPARC32 interface */ @@ -2120,7 +2121,7 @@ static void lance_cleanup(VLANClientState *vc) pcnet_common_cleanup(d); } -static void lance_init(SysBusDevice *dev) +static int lance_init(SysBusDevice *dev) { SysBusPCNetState *d = FROM_SYSBUS(SysBusPCNetState, dev); PCNetState *s = &d->state; @@ -2137,7 +2138,7 @@ static void lance_init(SysBusDevice *dev) s->phys_mem_read = ledma_memory_read; s->phys_mem_write = ledma_memory_write; - pcnet_common_init(&dev->qdev, s, lance_cleanup); + return pcnet_common_init(&dev->qdev, s, lance_cleanup); } static SysBusDeviceInfo lance_info = { -- cgit v1.2.3