Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MbHBS-00029G-QP for qemu-devel@nongnu.org; Wed, 12 Aug 2009 13:00:18 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MbHBO-00022z-3w for qemu-devel@nongnu.org; Wed, 12 Aug 2009 13:00:18 -0400 Received: from [199.232.76.173] (port=54838 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MbHBN-00022Y-Sx for qemu-devel@nongnu.org; Wed, 12 Aug 2009 13:00:13 -0400 Received: from mx2.redhat.com ([66.187.237.31]:47631) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MbHBN-0001bB-0B for qemu-devel@nongnu.org; Wed, 12 Aug 2009 13:00:13 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n7CH0BiA027981 for ; Wed, 12 Aug 2009 13:00:11 -0400 Subject: Re: [Qemu-devel] [PATCH] qdev: add return value to init() callbacks. References: <1250092766-23986-1-git-send-email-kraxel@redhat.com> From: Markus Armbruster Date: Wed, 12 Aug 2009 19:00:09 +0200 In-Reply-To: <1250092766-23986-1-git-send-email-kraxel@redhat.com> (Gerd Hoffmann's message of "Wed\, 12 Aug 2009 17\:59\:26 +0200") Message-ID: <87d4713r3a.fsf@pike.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gerd Hoffmann Cc: qemu-devel@nongnu.org Gerd Hoffmann writes: > 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. Yupp. > 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 I verified that we either * change a function returning void to return int instead, or * insert return 0 at the end of a function, or * change F() to return F(), for some F() that now returns int, or * insert return -1 instead of continuing to a crash, in virtio_blk_init_pci(), or * handle a failed device init(), in qdev_device_add(). [...] > diff --git a/hw/vga.c b/hw/vga.c > index 4a0f197..12c0424 100644 > --- a/hw/vga.c > +++ b/hw/vga.c > @@ -2480,7 +2480,7 @@ static void pci_vga_write_config(PCIDevice *d, > s->map_addr = 0; > } > > -static void pci_vga_initfn(PCIDevice *dev) > +static int pci_vga_initfn(PCIDevice *dev) > { > PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, dev); > VGAState *s = &d->vga_state; > @@ -2511,7 +2511,8 @@ static void pci_vga_initfn(PCIDevice *dev) > bios_total_size <<= 1; > pci_register_bar(&d->dev, PCI_ROM_SLOT, bios_total_size, > PCI_ADDRESS_SPACE_MEM_PREFETCH, vga_map); > - } > + } > + return 0; > } > > int pci_vga_init(PCIBus *bus, Looks like slight white-space damage, but isn't; the whole function is indented weirdly. [...] Acked-by: Markus Armbruster