From: Cao jin <caoj.fnst@cn.fujitsu.com>
To: Wei Jiangang <weijg.fnst@cn.fujitsu.com>, qemu-devel@nongnu.org
Cc: marcel@redhat.com, armbru@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 2/2] hw/pci-bridge: Convert pxb initialization functions to Error
Date: Wed, 23 Mar 2016 15:52:10 +0800 [thread overview]
Message-ID: <56F24B2A.6000407@cn.fujitsu.com> (raw)
In-Reply-To: <1458717980-26686-3-git-send-email-weijg.fnst@cn.fujitsu.com>
On 03/23/2016 03:26 PM, Wei Jiangang wrote:
>
> -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;
> PCIBus *bus;
> const char *dev_name = NULL;
> + Error *local_err = NULL;
>
the preferred style I think, is /*err/
> 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;
since we have local /*err/ to avoid null /**errp/ venture, I guess it
should be used here too.
> }
>
> if (dev->qdev.id && *dev->qdev.id) {
> @@ -248,7 +244,9 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
>
> PCI_HOST_BRIDGE(ds)->bus = bus;
>
> - if (pxb_register_bus(dev, bus)) {
> + pxb_register_bus(dev, bus, &local_err);
> + if (local_err) {
> + error_propagate(errp, local_err);
> goto err_register_bus;
> }
>
> @@ -262,23 +260,22 @@ 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));
> - return -EINVAL;
> }
>
> -static int pxb_dev_initfn(PCIDevice *dev)
> +static void pxb_dev_realize(PCIDevice *dev, Error **errp)
> {
> if (pci_bus_is_express(dev->bus)) {
> - error_report("pxb devices cannot reside on a PCIe bus!");
> - return -EINVAL;
> + error_setg(errp, "pxb devices cannot reside on a PCIe bus");
> + return;
> }
>
> - return pxb_dev_init_common(dev, false);
> + pxb_dev_realize_common(dev, false, errp);
> }
>
> static void pxb_dev_exitfn(PCIDevice *pci_dev)
> @@ -300,7 +297,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;
> k->vendor_id = PCI_VENDOR_ID_REDHAT;
> k->device_id = PCI_DEVICE_ID_REDHAT_PXB;
> @@ -318,14 +315,14 @@ static const TypeInfo pxb_dev_info = {
> .class_init = pxb_dev_class_init,
> };
>
> -static int pxb_pcie_dev_initfn(PCIDevice *dev)
> +static void pxb_pcie_dev_realize(PCIDevice *dev, Error **errp)
> {
> if (!pci_bus_is_express(dev->bus)) {
> - error_report("pxb-pcie devices cannot reside on a PCI bus!");
> - return -EINVAL;
> + error_setg(errp, "pxb-pcie devices cannot reside on a PCI bus");
> + return;
> }
>
> - return pxb_dev_init_common(dev, true);
> + pxb_dev_realize_common(dev, true, errp);
> }
>
> static void pxb_pcie_dev_class_init(ObjectClass *klass, void *data)
> @@ -333,7 +330,7 @@ static void pxb_pcie_dev_class_init(ObjectClass *klass, void *data)
> DeviceClass *dc = DEVICE_CLASS(klass);
> PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
>
> - k->init = pxb_pcie_dev_initfn;
> + k->realize = pxb_pcie_dev_realize;
> k->exit = pxb_dev_exitfn;
> k->vendor_id = PCI_VENDOR_ID_REDHAT;
> k->device_id = PCI_DEVICE_ID_REDHAT_PXB_PCIE;
>
--
Yours Sincerely,
Cao jin
next prev parent reply other threads:[~2016-03-23 7:50 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-23 7:26 [Qemu-devel] [PATCH v2 0/2] Convert pxb initfn to Error Wei Jiangang
2016-03-23 7:26 ` [Qemu-devel] [PATCH v2 1/2] hw/pci-bridge: Add missing unref in case register-bus fails Wei Jiangang
2016-03-27 15:13 ` Marcel Apfelbaum
2016-03-23 7:26 ` [Qemu-devel] [PATCH v2 2/2] hw/pci-bridge: Convert pxb initialization functions to Error Wei Jiangang
2016-03-23 7:52 ` Cao jin [this message]
2016-03-23 11:56 ` Markus Armbruster
2016-03-27 15:21 ` Marcel Apfelbaum
2016-03-23 11:56 ` [Qemu-devel] [PATCH v2 0/2] Convert pxb initfn " Markus Armbruster
2016-03-27 15:22 ` Marcel Apfelbaum
2016-04-07 16:39 ` Markus Armbruster
2016-04-07 16:44 ` Michael S. Tsirkin
2016-04-07 16:55 ` Michael S. Tsirkin
2016-04-08 7:55 ` [Qemu-devel] [PATCH v3 2/2] hw/pci-bridge: Convert pxb initialization functions " Wei Jiangang
2016-04-08 9:35 ` Michael S. Tsirkin
2016-04-08 7:58 ` [Qemu-devel] [PATCH v2 0/2] Convert pxb initfn " Wei, Jiangang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56F24B2A.6000407@cn.fujitsu.com \
--to=caoj.fnst@cn.fujitsu.com \
--cc=armbru@redhat.com \
--cc=marcel@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=weijg.fnst@cn.fujitsu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.