Received: from eggs.gnu.org ([2001:4830:134:3::10]:50739) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xj3Eg-0004Mz-NP for qemu-devel@nongnu.org; Tue, 28 Oct 2014 05:38:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xj3Ec-0004xV-49 for qemu-devel@nongnu.org; Tue, 28 Oct 2014 05:38:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58979) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xj3Eb-0004xR-Tn for qemu-devel@nongnu.org; Tue, 28 Oct 2014 05:38:38 -0400 From: Markus Armbruster References: <1414481739-19939-1-git-send-email-armbru@redhat.com> <1414481739-19939-2-git-send-email-armbru@redhat.com> <544F54BB.2080508@huawei.com> Date: Tue, 28 Oct 2014 10:38:26 +0100 In-Reply-To: <544F54BB.2080508@huawei.com> (Gonglei's message of "Tue, 28 Oct 2014 16:32:59 +0800") Message-ID: <8761f4sfe5.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH RFC 01/10] pci: Convert core to realize List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gonglei Cc: "pbonzini@redhat.com" , "mst@redhat.com" , "kraxel@redhat.com" , "afaerber@suse.de" , "qemu-devel@nongnu.org" Gonglei writes: > On 2014/10/28 15:35, Markus Armbruster wrote: > >> Implement DeviceClass methods realize() and unrealize() instead of >> init() and exit(). The core's initialization errors now get >> propagated properly, and QMP sends them instead of an unspecific >> "Device initialization failed" error. Unrealize can't fail, so no >> change there. >> >> PCIDeviceClass is unchanged: it still provides init() and exit(). >> Therefore, device models' errors are still not propagated. >> >> Signed-off-by: Markus Armbruster >> --- >> hw/pci/pci.c | 91 +++++++++++++++++++++++++++++++----------------------------- >> 1 file changed, 47 insertions(+), 44 deletions(-) >> >> diff --git a/hw/pci/pci.c b/hw/pci/pci.c >> index cd7a403..aef95c3 100644 >> --- a/hw/pci/pci.c >> +++ b/hw/pci/pci.c [...] >> void pci_register_bar(PCIDevice *pci_dev, int region_num, >> @@ -1742,10 +1747,11 @@ PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn) >> return bus->devices[devfn]; >> } >> >> -static int pci_qdev_init(DeviceState *qdev) >> +static void pci_qdev_realize(DeviceState *qdev, Error **errp) >> { >> PCIDevice *pci_dev = (PCIDevice *)qdev; >> PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(pci_dev); >> + Error *local_err = NULL; >> PCIBus *bus; >> int rc; >> bool is_default_rom; >> @@ -1758,15 +1764,16 @@ static int pci_qdev_init(DeviceState *qdev) >> bus = PCI_BUS(qdev_get_parent_bus(qdev)); >> pci_dev = do_pci_register_device(pci_dev, bus, >> object_get_typename(OBJECT(qdev)), >> - pci_dev->devfn); >> + pci_dev->devfn, errp); >> if (pci_dev == NULL) > >> - return -1; >> + return; >> > > Maybe we can use '{}' for if statement follow Qemu's coding style. scripts/checkpatch.pl is happy with the patch as is. I prefer to add braces only when I touch the conditional. Naturally, I also add them when a maintainer asks me to :) >> if (pc->init) { >> rc = pc->init(pci_dev); >> if (rc != 0) { >> do_pci_unregister_device(pci_dev); >> - return rc; >> + error_setg(errp, "Device initialization failed"); >> + return; >> } >> } >> [...] Thanks!