From patchwork Mon Mar 14 10:35:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Jiangang X-Patchwork-Id: 8578091 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5F1749F294 for ; Mon, 14 Mar 2016 10:38:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9CE1B20384 for ; Mon, 14 Mar 2016 10:37:59 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BF33720142 for ; Mon, 14 Mar 2016 10:37:58 +0000 (UTC) Received: from localhost ([::1]:40024 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afPss-00085O-7E for patchwork-qemu-devel@patchwork.kernel.org; Mon, 14 Mar 2016 06:37:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58602) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afPqu-0005Sc-OB for qemu-devel@nongnu.org; Mon, 14 Mar 2016 06:35:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1afPqt-0000jl-K5 for qemu-devel@nongnu.org; Mon, 14 Mar 2016 06:35:56 -0400 Received: from [59.151.112.132] (port=8280 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1afPqs-0000jC-NG for qemu-devel@nongnu.org; Mon, 14 Mar 2016 06:35:55 -0400 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="4549236" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 14 Mar 2016 18:35:44 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id 4BE5642B4B00; Mon, 14 Mar 2016 18:35:40 +0800 (CST) Received: from localhost.localdomain (10.167.226.50) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Mon, 14 Mar 2016 18:40:18 +0800 From: Wei Jiangang To: Date: Mon, 14 Mar 2016 18:35:02 +0800 Message-ID: <1457951704-5217-2-git-send-email-weijg.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1457951704-5217-1-git-send-email-weijg.fnst@cn.fujitsu.com> References: <1457951704-5217-1-git-send-email-weijg.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.50] X-yoursite-MailScanner-ID: 4BE5642B4B00.AE27A X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: weijg.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: marcel@redhat.com, caoj.fnst@cn.fujitsu.com, Wei Jiangang , ehabkost@redhat.com, mst@redhat.com Subject: [Qemu-devel] [PATCH 1/3] hw/pci-bridge: modify pxb_dev_init_common X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 1) add Error **errp parameter for it, 2) rename pxb_dev_init_common to pxb_dev_realize_common, and prepare for pxb/pxb-pcie convert to realize. 3) modify the callers, including pxb_dev_initfn and pxb_pcie_dev_initfn. Signed-off-by: Wei Jiangang Signed-off-by: Cao jin --- hw/pci-bridge/pci_expander_bridge.c | 56 ++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/hw/pci-bridge/pci_expander_bridge.c b/hw/pci-bridge/pci_expander_bridge.c index d23b8da..ce5baf8 100644 --- a/hw/pci-bridge/pci_expander_bridge.c +++ b/hw/pci-bridge/pci_expander_bridge.c @@ -160,30 +160,25 @@ static const TypeInfo pxb_host_info = { }; /* - * Registers the PXB bus as a child of the i440fx root bus. - * - * Returns 0 on successs, -1 if i440fx host was not - * found or the bus number is already in use. + * Registers the PXB bus as a child of pci host root bus. */ -static int pxb_register_bus(PCIDevice *dev, PCIBus *pxb_bus) +static void pxb_register_bus(PCIDevice *dev, PCIBus *pxb_bus, Error **errp) { 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."); - return -1; + error_setg(errp, "PXB devices can be attached only to root bus."); + return; } 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); - return -1; + error_setg(errp, "Bus %d is already in use.", pxb_bus_num); + return; } } QLIST_INSERT_HEAD(&dev->bus->child, pxb_bus, sibling); - - return 0; } static int pxb_map_irq_fn(PCIDevice *pci_dev, int pin) @@ -213,7 +208,7 @@ static gint pxb_compare(gconstpointer a, gconstpointer b) 0; } -static int pxb_dev_init_common(PCIDevice *dev, bool pcie) +static void pxb_dev_realize_common(PCIDevice *dev, bool pcie, Error **errp) { PXBDev *pxb = convert_to_pxb(dev); DeviceState *ds, *bds = NULL; @@ -222,8 +217,8 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie) 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) { @@ -248,8 +243,9 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie) PCI_HOST_BRIDGE(ds)->bus = bus; - if (pxb_register_bus(dev, bus)) { - return -EINVAL; + pxb_register_bus(dev, bus, errp); + if (*errp) { + goto err_register_bus; } qdev_init_nofail(ds); @@ -262,17 +258,31 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie) 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; + + return; + +err_register_bus: + object_unref(OBJECT(bds)); + object_unparent(OBJECT(bus)); + object_unref(OBJECT(ds)); } static int pxb_dev_initfn(PCIDevice *dev) { + Error *err = NULL; + if (pci_bus_is_express(dev->bus)) { error_report("pxb devices cannot reside on a PCIe bus!"); return -EINVAL; } - return pxb_dev_init_common(dev, false); + pxb_dev_realize_common(dev, false, &err); + if (err) { + error_report_err(err); + return -EINVAL; + } + + return 0; } static void pxb_dev_exitfn(PCIDevice *pci_dev) @@ -314,12 +324,20 @@ static const TypeInfo pxb_dev_info = { static int pxb_pcie_dev_initfn(PCIDevice *dev) { + Error *err = NULL; + if (!pci_bus_is_express(dev->bus)) { error_report("pxb-pcie devices cannot reside on a PCI bus!"); return -EINVAL; } - return pxb_dev_init_common(dev, true); + pxb_dev_realize_common(dev, true, &err); + if (err) { + error_report_err(err); + return -EINVAL; + } + + return 0; } static void pxb_pcie_dev_class_init(ObjectClass *klass, void *data)