All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2 0/2] Convert pxb initfn to Error
@ 2016-03-23  7:26 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
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Wei Jiangang @ 2016-03-23  7:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: marcel, Wei Jiangang, armbru

v1 -> v2:

- Extract a separate bugfix patch
- Squash v1 patches 1-3 together
- Drop the period and exclamation mark
- Modify commit message 

v1: cover-letter

The original patch named '[PATCH v3] PXB: convert to realize()'
was raised by Cao jin <caoj.fnst@cn.fujitsu.com>,
and reviewed by Marcel Apfelbaum <marcel@redhat.com>.

It conflicts with 02b0743 that had been merged,
so resend a newer version, including the following,

hw/pci-bridge: modify pxb_dev_init_common
pxb: convert to realize()
pxb-pcie: convert to realize()

Wei Jiangang (2):
  hw/pci-bridge: Add missing unref in case register-bus fails
  hw/pci-bridge: Convert pxb initialization functions to Error

 hw/pci-bridge/pci_expander_bridge.c | 57 +++++++++++++++++++------------------
 1 file changed, 30 insertions(+), 27 deletions(-)

-- 
1.9.3

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Qemu-devel] [PATCH v2 1/2] hw/pci-bridge: Add missing unref in case register-bus fails
  2016-03-23  7:26 [Qemu-devel] [PATCH v2 0/2] Convert pxb initfn to Error Wei Jiangang
@ 2016-03-23  7:26 ` 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 11:56 ` [Qemu-devel] [PATCH v2 0/2] Convert pxb initfn " Markus Armbruster
  2 siblings, 1 reply; 15+ messages in thread
From: Wei Jiangang @ 2016-03-23  7:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: marcel, Cao jin, Wei Jiangang, armbru

The error paths after a successful qdev_create/pci_bus_new
should contain a object_unref/object_unparent.
pxb_dev_init_common() did not yet, so add it.

Signed-off-by: Wei Jiangang <weijg.fnst@cn.fujitsu.com>
Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
---
 hw/pci-bridge/pci_expander_bridge.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/hw/pci-bridge/pci_expander_bridge.c b/hw/pci-bridge/pci_expander_bridge.c
index 5e7e546..ba320bd 100644
--- a/hw/pci-bridge/pci_expander_bridge.c
+++ b/hw/pci-bridge/pci_expander_bridge.c
@@ -249,7 +249,7 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
     PCI_HOST_BRIDGE(ds)->bus = bus;
 
     if (pxb_register_bus(dev, bus)) {
-        return -EINVAL;
+        goto err_register_bus;
     }
 
     qdev_init_nofail(ds);
@@ -263,6 +263,12 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
 
     pxb_dev_list = g_list_insert_sorted(pxb_dev_list, pxb, pxb_compare);
     return 0;
+
+err_register_bus:
+    object_unref(OBJECT(bds));
+    object_unparent(OBJECT(bus));
+    object_unref(OBJECT(ds));
+    return -EINVAL;
 }
 
 static int pxb_dev_initfn(PCIDevice *dev)
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [PATCH v2 2/2] hw/pci-bridge: Convert pxb initialization functions to Error
  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-23  7:26 ` Wei Jiangang
  2016-03-23  7:52   ` Cao jin
  2016-03-27 15:21   ` Marcel Apfelbaum
  2016-03-23 11:56 ` [Qemu-devel] [PATCH v2 0/2] Convert pxb initfn " Markus Armbruster
  2 siblings, 2 replies; 15+ messages in thread
From: Wei Jiangang @ 2016-03-23  7:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: marcel, Cao jin, Wei Jiangang, armbru

Firstly, convert pxb_dev_init_common() to Error and rename
it to pxb_dev_realize_common().
Actually, pxb_register_bus() is converted as well.

And then,
convert pxb_dev_initfn() and pxb_pcie_dev_initfn() to Error,
rename them to pxb_dev_realize() and pxb_pcie_dev_realize()
respectively.

Signed-off-by: Wei Jiangang <weijg.fnst@cn.fujitsu.com>
Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
---
 hw/pci-bridge/pci_expander_bridge.c | 51 +++++++++++++++++--------------------
 1 file changed, 24 insertions(+), 27 deletions(-)

diff --git a/hw/pci-bridge/pci_expander_bridge.c b/hw/pci-bridge/pci_expander_bridge.c
index ba320bd..efb8863 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,17 +208,18 @@ 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;
     PCIBus *bus;
     const char *dev_name = NULL;
+    Error *local_err = NULL;
 
     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,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;
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH v2 2/2] hw/pci-bridge: Convert pxb initialization functions to Error
  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
  2016-03-23 11:56     ` Markus Armbruster
  2016-03-27 15:21   ` Marcel Apfelbaum
  1 sibling, 1 reply; 15+ messages in thread
From: Cao jin @ 2016-03-23  7:52 UTC (permalink / raw)
  To: Wei Jiangang, qemu-devel; +Cc: marcel, armbru



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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH v2 2/2] hw/pci-bridge: Convert pxb initialization functions to Error
  2016-03-23  7:52   ` Cao jin
@ 2016-03-23 11:56     ` Markus Armbruster
  0 siblings, 0 replies; 15+ messages in thread
From: Markus Armbruster @ 2016-03-23 11:56 UTC (permalink / raw)
  To: Cao jin; +Cc: marcel, Wei Jiangang, qemu-devel

Cao jin <caoj.fnst@cn.fujitsu.com> writes:

> 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/

Both styles are in use.  I use err myself, but local_err is okay, too.

>>       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.

No, this is just fine.

If errp is null, error_setg() does nothing, which is exactly what we
want.

However:

>>       }
>>
>>       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;
>>       }
>>

When we need to find out whether the callee set an error, we can't use
(possibly null) errp, because *errp isn't safe.

[...]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH v2 0/2] Convert pxb initfn to Error
  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-23  7:26 ` [Qemu-devel] [PATCH v2 2/2] hw/pci-bridge: Convert pxb initialization functions to Error Wei Jiangang
@ 2016-03-23 11:56 ` Markus Armbruster
  2016-03-27 15:22   ` Marcel Apfelbaum
  2 siblings, 1 reply; 15+ messages in thread
From: Markus Armbruster @ 2016-03-23 11:56 UTC (permalink / raw)
  To: Wei Jiangang; +Cc: marcel, qemu-devel

Wei Jiangang <weijg.fnst@cn.fujitsu.com> writes:

> v1 -> v2:
>
> - Extract a separate bugfix patch
> - Squash v1 patches 1-3 together
> - Drop the period and exclamation mark
> - Modify commit message 
>
> v1: cover-letter
>
> The original patch named '[PATCH v3] PXB: convert to realize()'
> was raised by Cao jin <caoj.fnst@cn.fujitsu.com>,
> and reviewed by Marcel Apfelbaum <marcel@redhat.com>.
>
> It conflicts with 02b0743 that had been merged,
> so resend a newer version, including the following,

Series
Reviewed-by: Markus Armbruster <armbru@redhat.com>

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH v2 1/2] hw/pci-bridge: Add missing unref in case register-bus fails
  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
  0 siblings, 0 replies; 15+ messages in thread
From: Marcel Apfelbaum @ 2016-03-27 15:13 UTC (permalink / raw)
  To: Wei Jiangang, qemu-devel; +Cc: Cao jin, armbru

On 03/23/2016 09:26 AM, Wei Jiangang wrote:
> The error paths after a successful qdev_create/pci_bus_new
> should contain a object_unref/object_unparent.
> pxb_dev_init_common() did not yet, so add it.
>
> Signed-off-by: Wei Jiangang <weijg.fnst@cn.fujitsu.com>
> Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
> ---
>   hw/pci-bridge/pci_expander_bridge.c | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/hw/pci-bridge/pci_expander_bridge.c b/hw/pci-bridge/pci_expander_bridge.c
> index 5e7e546..ba320bd 100644
> --- a/hw/pci-bridge/pci_expander_bridge.c
> +++ b/hw/pci-bridge/pci_expander_bridge.c
> @@ -249,7 +249,7 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
>       PCI_HOST_BRIDGE(ds)->bus = bus;
>
>       if (pxb_register_bus(dev, bus)) {
> -        return -EINVAL;
> +        goto err_register_bus;
>       }
>
>       qdev_init_nofail(ds);
> @@ -263,6 +263,12 @@ static int pxb_dev_init_common(PCIDevice *dev, bool pcie)
>
>       pxb_dev_list = g_list_insert_sorted(pxb_dev_list, pxb, pxb_compare);
>       return 0;
> +
> +err_register_bus:
> +    object_unref(OBJECT(bds));
> +    object_unparent(OBJECT(bus));
> +    object_unref(OBJECT(ds));
> +    return -EINVAL;
>   }
>
>   static int pxb_dev_initfn(PCIDevice *dev)
>


Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>

Thanks,
Marcel

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH v2 2/2] hw/pci-bridge: Convert pxb initialization functions to Error
  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
@ 2016-03-27 15:21   ` Marcel Apfelbaum
  1 sibling, 0 replies; 15+ messages in thread
From: Marcel Apfelbaum @ 2016-03-27 15:21 UTC (permalink / raw)
  To: Wei Jiangang, qemu-devel; +Cc: Cao jin, armbru

On 03/23/2016 09:26 AM, Wei Jiangang wrote:
> Firstly, convert pxb_dev_init_common() to Error and rename
> it to pxb_dev_realize_common().
> Actually, pxb_register_bus() is converted as well.
>
> And then,
> convert pxb_dev_initfn() and pxb_pcie_dev_initfn() to Error,
> rename them to pxb_dev_realize() and pxb_pcie_dev_realize()
> respectively.
>
> Signed-off-by: Wei Jiangang <weijg.fnst@cn.fujitsu.com>
> Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
> ---
>   hw/pci-bridge/pci_expander_bridge.c | 51 +++++++++++++++++--------------------
>   1 file changed, 24 insertions(+), 27 deletions(-)
>
> diff --git a/hw/pci-bridge/pci_expander_bridge.c b/hw/pci-bridge/pci_expander_bridge.c
> index ba320bd..efb8863 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,17 +208,18 @@ 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;
>       PCIBus *bus;
>       const char *dev_name = NULL;
> +    Error *local_err = NULL;
>
>       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,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;
>

Looks good to me.

Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>

Thanks,
Marcel

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH v2 0/2] Convert pxb initfn to Error
  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
  0 siblings, 1 reply; 15+ messages in thread
From: Marcel Apfelbaum @ 2016-03-27 15:22 UTC (permalink / raw)
  To: Markus Armbruster, Wei Jiangang; +Cc: qemu-devel, Michael S. Tsirkin

On 03/23/2016 01:56 PM, Markus Armbruster wrote:
> Wei Jiangang <weijg.fnst@cn.fujitsu.com> writes:
>
>> v1 -> v2:
>>
>> - Extract a separate bugfix patch
>> - Squash v1 patches 1-3 together
>> - Drop the period and exclamation mark
>> - Modify commit message
>>
>> v1: cover-letter
>>
>> The original patch named '[PATCH v3] PXB: convert to realize()'
>> was raised by Cao jin <caoj.fnst@cn.fujitsu.com>,
>> and reviewed by Marcel Apfelbaum <marcel@redhat.com>.
>>
>> It conflicts with 02b0743 that had been merged,
>> so resend a newer version, including the following,
>
> Series
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
>

Thanks Markus, will you take it in your tree, or Michael ?
Marcel

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH v2 0/2] Convert pxb initfn to Error
  2016-03-27 15:22   ` Marcel Apfelbaum
@ 2016-04-07 16:39     ` Markus Armbruster
  2016-04-07 16:44       ` Michael S. Tsirkin
  0 siblings, 1 reply; 15+ messages in thread
From: Markus Armbruster @ 2016-04-07 16:39 UTC (permalink / raw)
  To: Marcel Apfelbaum; +Cc: Wei Jiangang, qemu-devel, Michael S. Tsirkin

Marcel Apfelbaum <marcel@redhat.com> writes:

> On 03/23/2016 01:56 PM, Markus Armbruster wrote:
>> Wei Jiangang <weijg.fnst@cn.fujitsu.com> writes:
>>
>>> v1 -> v2:
>>>
>>> - Extract a separate bugfix patch
>>> - Squash v1 patches 1-3 together
>>> - Drop the period and exclamation mark
>>> - Modify commit message
>>>
>>> v1: cover-letter
>>>
>>> The original patch named '[PATCH v3] PXB: convert to realize()'
>>> was raised by Cao jin <caoj.fnst@cn.fujitsu.com>,
>>> and reviewed by Marcel Apfelbaum <marcel@redhat.com>.
>>>
>>> It conflicts with 02b0743 that had been merged,
>>> so resend a newer version, including the following,
>>
>> Series
>> Reviewed-by: Markus Armbruster <armbru@redhat.com>
>>
>
> Thanks Markus, will you take it in your tree, or Michael ?

As error reporting maintainer, I cover error reporting infrastructure.
I also take non-infrastructure error reporting patches that cross
subsystems when no affected maintainer objects, single-subsystem patches
when the maintainer asks me to, and patches to unmaintained code.

I encourage you to take this series through the PCI tree.  But if you
want me to take it through my tree instead, let me know.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH v2 0/2] Convert pxb initfn to Error
  2016-04-07 16:39     ` Markus Armbruster
@ 2016-04-07 16:44       ` Michael S. Tsirkin
  2016-04-07 16:55         ` Michael S. Tsirkin
  0 siblings, 1 reply; 15+ messages in thread
From: Michael S. Tsirkin @ 2016-04-07 16:44 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: Marcel Apfelbaum, Wei Jiangang, qemu-devel

On Thu, Apr 07, 2016 at 06:39:10PM +0200, Markus Armbruster wrote:
> Marcel Apfelbaum <marcel@redhat.com> writes:
> 
> > On 03/23/2016 01:56 PM, Markus Armbruster wrote:
> >> Wei Jiangang <weijg.fnst@cn.fujitsu.com> writes:
> >>
> >>> v1 -> v2:
> >>>
> >>> - Extract a separate bugfix patch
> >>> - Squash v1 patches 1-3 together
> >>> - Drop the period and exclamation mark
> >>> - Modify commit message
> >>>
> >>> v1: cover-letter
> >>>
> >>> The original patch named '[PATCH v3] PXB: convert to realize()'
> >>> was raised by Cao jin <caoj.fnst@cn.fujitsu.com>,
> >>> and reviewed by Marcel Apfelbaum <marcel@redhat.com>.
> >>>
> >>> It conflicts with 02b0743 that had been merged,
> >>> so resend a newer version, including the following,
> >>
> >> Series
> >> Reviewed-by: Markus Armbruster <armbru@redhat.com>
> >>
> >
> > Thanks Markus, will you take it in your tree, or Michael ?
> 
> As error reporting maintainer, I cover error reporting infrastructure.
> I also take non-infrastructure error reporting patches that cross
> subsystems when no affected maintainer objects, single-subsystem patches
> when the maintainer asks me to, and patches to unmaintained code.
> 
> I encourage you to take this series through the PCI tree.  But if you
> want me to take it through my tree instead, let me know.

I applied this, thanks!

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH v2 0/2] Convert pxb initfn to Error
  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  7:58           ` [Qemu-devel] [PATCH v2 0/2] Convert pxb initfn " Wei, Jiangang
  0 siblings, 2 replies; 15+ messages in thread
From: Michael S. Tsirkin @ 2016-04-07 16:55 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: Marcel Apfelbaum, Wei Jiangang, qemu-devel

On Thu, Apr 07, 2016 at 07:44:17PM +0300, Michael S. Tsirkin wrote:
> On Thu, Apr 07, 2016 at 06:39:10PM +0200, Markus Armbruster wrote:
> > Marcel Apfelbaum <marcel@redhat.com> writes:
> > 
> > > On 03/23/2016 01:56 PM, Markus Armbruster wrote:
> > >> Wei Jiangang <weijg.fnst@cn.fujitsu.com> writes:
> > >>
> > >>> v1 -> v2:
> > >>>
> > >>> - Extract a separate bugfix patch
> > >>> - Squash v1 patches 1-3 together
> > >>> - Drop the period and exclamation mark
> > >>> - Modify commit message
> > >>>
> > >>> v1: cover-letter
> > >>>
> > >>> The original patch named '[PATCH v3] PXB: convert to realize()'
> > >>> was raised by Cao jin <caoj.fnst@cn.fujitsu.com>,
> > >>> and reviewed by Marcel Apfelbaum <marcel@redhat.com>.
> > >>>
> > >>> It conflicts with 02b0743 that had been merged,
> > >>> so resend a newer version, including the following,
> > >>
> > >> Series
> > >> Reviewed-by: Markus Armbruster <armbru@redhat.com>
> > >>
> > >
> > > Thanks Markus, will you take it in your tree, or Michael ?
> > 
> > As error reporting maintainer, I cover error reporting infrastructure.
> > I also take non-infrastructure error reporting patches that cross
> > subsystems when no affected maintainer objects, single-subsystem patches
> > when the maintainer asks me to, and patches to unmaintained code.
> > 
> > I encourage you to take this series through the PCI tree.  But if you
> > want me to take it through my tree instead, let me know.
> 
> I applied this, thanks!

In fact, I applied patch 1/2. 2/2 fails build and is not a bugfix.
I think it's best to defer it to after 2.6.
Pls repost it then.

-- 
MST

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Qemu-devel] [PATCH v3 2/2] hw/pci-bridge: Convert pxb initialization functions to Error
  2016-04-07 16:55         ` Michael S. Tsirkin
@ 2016-04-08  7:55           ` 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
  1 sibling, 1 reply; 15+ messages in thread
From: Wei Jiangang @ 2016-04-08  7:55 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, armbru, marcel, Wei Jiangang, Cao jin

Firstly, convert pxb_dev_init_common() to Error and rename
it to pxb_dev_realize_common().
Actually, pxb_register_bus() is converted as well.

And then,
convert pxb_dev_initfn() and pxb_pcie_dev_initfn() to Error,
rename them to pxb_dev_realize() and pxb_pcie_dev_realize()
respectively.

Signed-off-by: Wei Jiangang <weijg.fnst@cn.fujitsu.com>
Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
---
 hw/pci-bridge/pci_expander_bridge.c | 52 ++++++++++++++++++-------------------
 1 file changed, 25 insertions(+), 27 deletions(-)

diff --git a/hw/pci-bridge/pci_expander_bridge.c b/hw/pci-bridge/pci_expander_bridge.c
index ba320bd..cbea9c1 100644
--- a/hw/pci-bridge/pci_expander_bridge.c
+++ b/hw/pci-bridge/pci_expander_bridge.c
@@ -11,6 +11,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qapi/error.h"
 #include "hw/pci/pci.h"
 #include "hw/pci/pci_bus.h"
 #include "hw/pci/pci_host.h"
@@ -160,30 +161,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,17 +209,18 @@ 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;
     PCIBus *bus;
     const char *dev_name = NULL;
+    Error *local_err = NULL;
 
     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,7 +245,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 +261,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 +298,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 +316,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 +331,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;
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH v2 0/2] Convert pxb initfn to Error
  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  7:58           ` Wei, Jiangang
  1 sibling, 0 replies; 15+ messages in thread
From: Wei, Jiangang @ 2016-04-08  7:58 UTC (permalink / raw)
  To: mst; +Cc: marcel, armbru, qemu-devel

On Thu, 2016-04-07 at 19:55 +0300, Michael S. Tsirkin wrote:
> On Thu, Apr 07, 2016 at 07:44:17PM +0300, Michael S. Tsirkin wrote:
> > On Thu, Apr 07, 2016 at 06:39:10PM +0200, Markus Armbruster wrote:
> > > Marcel Apfelbaum <marcel@redhat.com> writes:
> > > 
> > > > On 03/23/2016 01:56 PM, Markus Armbruster wrote:
> > > >> Wei Jiangang <weijg.fnst@cn.fujitsu.com> writes:
> > > >>
> > > >>> v1 -> v2:
> > > >>>
> > > >>> - Extract a separate bugfix patch
> > > >>> - Squash v1 patches 1-3 together
> > > >>> - Drop the period and exclamation mark
> > > >>> - Modify commit message
> > > >>>
> > > >>> v1: cover-letter
> > > >>>
> > > >>> The original patch named '[PATCH v3] PXB: convert to realize()'
> > > >>> was raised by Cao jin <caoj.fnst@cn.fujitsu.com>,
> > > >>> and reviewed by Marcel Apfelbaum <marcel@redhat.com>.
> > > >>>
> > > >>> It conflicts with 02b0743 that had been merged,
> > > >>> so resend a newer version, including the following,
> > > >>
> > > >> Series
> > > >> Reviewed-by: Markus Armbruster <armbru@redhat.com>
> > > >>
> > > >
> > > > Thanks Markus, will you take it in your tree, or Michael ?
> > > 
> > > As error reporting maintainer, I cover error reporting infrastructure.
> > > I also take non-infrastructure error reporting patches that cross
> > > subsystems when no affected maintainer objects, single-subsystem patches
> > > when the maintainer asks me to, and patches to unmaintained code.
> > > 
> > > I encourage you to take this series through the PCI tree.  But if you
> > > want me to take it through my tree instead, let me know.
> > 
> > I applied this, thanks!
> 
> In fact, I applied patch 1/2. 2/2 fails build and is not a bugfix.
> I think it's best to defer it to after 2.6.
> Pls repost it then.

Hi,
I have fixed the compile error.
In fact, I missed including the qapi/error.h.
May I trouble you to check and apply v3 again ?
Thanks in advance.

wei
> 




^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH v3 2/2] hw/pci-bridge: Convert pxb initialization functions to Error
  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
  0 siblings, 0 replies; 15+ messages in thread
From: Michael S. Tsirkin @ 2016-04-08  9:35 UTC (permalink / raw)
  To: Wei Jiangang; +Cc: qemu-devel, armbru, marcel, Cao jin

On Fri, Apr 08, 2016 at 03:55:54PM +0800, Wei Jiangang wrote:
> Firstly, convert pxb_dev_init_common() to Error and rename
> it to pxb_dev_realize_common().
> Actually, pxb_register_bus() is converted as well.
> 
> And then,
> convert pxb_dev_initfn() and pxb_pcie_dev_initfn() to Error,
> rename them to pxb_dev_realize() and pxb_pcie_dev_realize()
> respectively.
> 
> Signed-off-by: Wei Jiangang <weijg.fnst@cn.fujitsu.com>
> Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>

Pls remember to re-post this after 2.6 is out.
> ---
>  hw/pci-bridge/pci_expander_bridge.c | 52 ++++++++++++++++++-------------------
>  1 file changed, 25 insertions(+), 27 deletions(-)
> 
> diff --git a/hw/pci-bridge/pci_expander_bridge.c b/hw/pci-bridge/pci_expander_bridge.c
> index ba320bd..cbea9c1 100644
> --- a/hw/pci-bridge/pci_expander_bridge.c
> +++ b/hw/pci-bridge/pci_expander_bridge.c
> @@ -11,6 +11,7 @@
>   */
>  
>  #include "qemu/osdep.h"
> +#include "qapi/error.h"
>  #include "hw/pci/pci.h"
>  #include "hw/pci/pci_bus.h"
>  #include "hw/pci/pci_host.h"
> @@ -160,30 +161,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,17 +209,18 @@ 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;
>      PCIBus *bus;
>      const char *dev_name = NULL;
> +    Error *local_err = NULL;
>  
>      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,7 +245,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 +261,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 +298,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 +316,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 +331,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;
> -- 
> 1.9.3
> 
> 

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2016-04-08  9:35 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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.