From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53170) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aAb8a-0000Rn-Vl for qemu-devel@nongnu.org; Sun, 20 Dec 2015 05:22:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aAb8W-0000p9-Ul for qemu-devel@nongnu.org; Sun, 20 Dec 2015 05:22:48 -0500 Received: from mail-wm0-x233.google.com ([2a00:1450:400c:c09::233]:33280) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aAb8W-0000ox-Ot for qemu-devel@nongnu.org; Sun, 20 Dec 2015 05:22:44 -0500 Received: by mail-wm0-x233.google.com with SMTP id p187so35694175wmp.0 for ; Sun, 20 Dec 2015 02:22:44 -0800 (PST) References: <1450436632-23980-1-git-send-email-caoj.fnst@cn.fujitsu.com> <1450436632-23980-4-git-send-email-caoj.fnst@cn.fujitsu.com> From: Marcel Apfelbaum Message-ID: <56768170.2080602@gmail.com> Date: Sun, 20 Dec 2015 12:22:40 +0200 MIME-Version: 1.0 In-Reply-To: <1450436632-23980-4-git-send-email-caoj.fnst@cn.fujitsu.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 3/5] PXB: convert to realize() Reply-To: marcel@redhat.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Cao jin , qemu-devel@nongnu.org Cc: ehabkost@redhat.com, mst@redhat.com, pbonzini@redhat.com, leon.alrae@imgtec.com, aurelien@aurel32.net, rth@twiddle.net Hi, On 12/18/2015 01:03 PM, Cao jin wrote: > Signed-off-by: Cao jin > --- > hw/pci-bridge/pci_expander_bridge.c | 24 ++++++++++++++---------- > 1 file changed, 14 insertions(+), 10 deletions(-) > > diff --git a/hw/pci-bridge/pci_expander_bridge.c b/hw/pci-bridge/pci_expander_bridge.c > index 57f8a37..cc975f6 100644 > --- a/hw/pci-bridge/pci_expander_bridge.c > +++ b/hw/pci-bridge/pci_expander_bridge.c > @@ -145,19 +145,19 @@ static const TypeInfo pxb_host_info = { > * Returns 0 on successs, -1 if i440fx host was not > * found or the bus number is already in use. > */ > -static int pxb_register_bus(PCIDevice *dev, PCIBus *pxb_bus) > +static int pxb_register_bus(PCIDevice *dev, PCIBus *pxb_bus, Error **errp) If you add an err parameter, maybe the function should return void. > { > PCIBus *bus = dev->bus; > int pxb_bus_num = pci_bus_num(pxb_bus); > > if (bus->parent_dev) { > - error_report("PXB devices can be attached only to root bus."); > + error_setg(errp, "PXB devices can be attached only to root bus."); > return -1; > } > > QLIST_FOREACH(bus, &bus->child, sibling) { > if (pci_bus_num(bus) == pxb_bus_num) { > - error_report("Bus %d is already in use.", pxb_bus_num); > + error_setg(errp, "Bus %d is already in use.", pxb_bus_num); > return -1; > } > } > @@ -193,7 +193,7 @@ static gint pxb_compare(gconstpointer a, gconstpointer b) > 0; > } > > -static int pxb_dev_initfn(PCIDevice *dev) > +static void pxb_dev_realize(PCIDevice *dev, Error **errp) > { > PXBDev *pxb = PXB_DEV(dev); > DeviceState *ds, *bds; > @@ -202,8 +202,8 @@ static int pxb_dev_initfn(PCIDevice *dev) > > if (pxb->numa_node != NUMA_NODE_UNASSIGNED && > pxb->numa_node >= nb_numa_nodes) { > - error_report("Illegal numa node %d.", pxb->numa_node); > - return -EINVAL; > + error_setg(errp, "Illegal numa node %d.", pxb->numa_node); > + return; > } > > if (dev->qdev.id && *dev->qdev.id) { > @@ -225,8 +225,8 @@ static int pxb_dev_initfn(PCIDevice *dev) > > PCI_HOST_BRIDGE(ds)->bus = bus; > > - if (pxb_register_bus(dev, bus)) { > - return -EINVAL; > + if (pxb_register_bus(dev, bus, errp)) { > + goto err_register_bus; > } > > qdev_init_nofail(ds); > @@ -237,7 +237,11 @@ static int pxb_dev_initfn(PCIDevice *dev) > pci_config_set_class(dev->config, PCI_CLASS_BRIDGE_HOST); > > pxb_dev_list = g_list_insert_sorted(pxb_dev_list, pxb, pxb_compare); > - return 0; > + > +err_register_bus: > + object_unref(OBJECT(ds)); > + object_unref(OBJECT(bds)); > + object_unref(OBJECT(bus)); The order should be in the reverse order of creation: bds, bus, ds > } > > static void pxb_dev_exitfn(PCIDevice *pci_dev) > @@ -259,7 +263,7 @@ static void pxb_dev_class_init(ObjectClass *klass, void *data) > DeviceClass *dc = DEVICE_CLASS(klass); > PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); > > - k->init = pxb_dev_initfn; > + k->realize = pxb_dev_realize; > k->exit = pxb_dev_exitfn; If init is converted to realize, maybe the exit should be converted to unrealize? Thanks, Marcel > k->vendor_id = PCI_VENDOR_ID_REDHAT; > k->device_id = PCI_DEVICE_ID_REDHAT_PXB; >