All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: Markus Armbruster <armbru@redhat.com>, qemu-devel@nongnu.org
Cc: "Stefano Stabellini" <sstabellini@kernel.org>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"Paul Durrant" <paul@xen.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Laurent Vivier" <laurent@vivier.eu>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	xen-devel@lists.xenproject.org,
	"Anthony Perard" <anthony.perard@citrix.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>
Subject: [PATCH 2/2] qdev: Let BusRealize() return a boolean value to indicate error
Date: Sun, 20 Sep 2020 13:44:16 +0200	[thread overview]
Message-ID: <20200920114416.353277-3-f4bug@amsat.org> (raw)
In-Reply-To: <20200920114416.353277-1-f4bug@amsat.org>

Commit 9940b2cfbc0 introduced qdev_realize() and qbus_realize()
with the ability to return a boolean value if an error occured,
thus the caller does not need to check if the Error* pointer is
set.
Provide the same ability to the BusRealize type.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 include/hw/qdev-core.h | 14 +++++++++++++-
 hw/hyperv/vmbus.c      |  5 +++--
 hw/nubus/nubus-bus.c   |  5 +++--
 hw/pci/pci.c           | 12 +++++++++---
 hw/xen/xen-bus.c       |  5 +++--
 5 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 02ac1c50b7f..eecfe794a71 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -32,7 +32,19 @@ typedef enum DeviceCategory {
 typedef void (*DeviceRealize)(DeviceState *dev, Error **errp);
 typedef void (*DeviceUnrealize)(DeviceState *dev);
 typedef void (*DeviceReset)(DeviceState *dev);
-typedef void (*BusRealize)(BusState *bus, Error **errp);
+/**
+ * BusRealize: Realize @bus.
+ * @bus: bus to realize
+ * @errp: pointer to error object
+ *
+ * On success, return true.
+ * On failure, store an error through @errp and return false.
+ */
+typedef bool (*BusRealize)(BusState *bus, Error **errp);
+/**
+ * BusUnrealize: Unrealize @bus.
+ * @bus: bus to unrealize
+ */
 typedef void (*BusUnrealize)(BusState *bus);
 
 /**
diff --git a/hw/hyperv/vmbus.c b/hw/hyperv/vmbus.c
index 6ef895bc352..8a0452b2464 100644
--- a/hw/hyperv/vmbus.c
+++ b/hw/hyperv/vmbus.c
@@ -2487,7 +2487,7 @@ static const TypeInfo vmbus_dev_type_info = {
     .instance_init = vmbus_dev_instance_init,
 };
 
-static void vmbus_realize(BusState *bus, Error **errp)
+static bool vmbus_realize(BusState *bus, Error **errp)
 {
     int ret = 0;
     Error *local_err = NULL;
@@ -2519,7 +2519,7 @@ static void vmbus_realize(BusState *bus, Error **errp)
         goto clear_event_notifier;
     }
 
-    return;
+    return true;
 
 clear_event_notifier:
     event_notifier_cleanup(&vmbus->notifier);
@@ -2528,6 +2528,7 @@ remove_msg_handler:
 error_out:
     qemu_mutex_destroy(&vmbus->rx_queue_lock);
     error_propagate(errp, local_err);
+    return false;
 }
 
 static void vmbus_unrealize(BusState *bus)
diff --git a/hw/nubus/nubus-bus.c b/hw/nubus/nubus-bus.c
index 942a6d5342d..d20d9c0f72c 100644
--- a/hw/nubus/nubus-bus.c
+++ b/hw/nubus/nubus-bus.c
@@ -65,12 +65,13 @@ static const MemoryRegionOps nubus_super_slot_ops = {
     },
 };
 
-static void nubus_realize(BusState *bus, Error **errp)
+static bool nubus_realize(BusState *bus, Error **errp)
 {
     if (!nubus_find()) {
         error_setg(errp, "at most one %s device is permitted", TYPE_NUBUS_BUS);
-        return;
+        return false;
     }
+    return true;
 }
 
 static void nubus_init(Object *obj)
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index de0fae10ab9..f535ebac847 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -115,7 +115,7 @@ static void pcibus_machine_done(Notifier *notifier, void *data)
     }
 }
 
-static void pci_bus_realize(BusState *qbus, Error **errp)
+static bool pci_bus_realize(BusState *qbus, Error **errp)
 {
     PCIBus *bus = PCI_BUS(qbus);
 
@@ -123,13 +123,17 @@ static void pci_bus_realize(BusState *qbus, Error **errp)
     qemu_add_machine_init_done_notifier(&bus->machine_done);
 
     vmstate_register(NULL, VMSTATE_INSTANCE_ID_ANY, &vmstate_pcibus, bus);
+
+    return true;
 }
 
-static void pcie_bus_realize(BusState *qbus, Error **errp)
+static bool pcie_bus_realize(BusState *qbus, Error **errp)
 {
     PCIBus *bus = PCI_BUS(qbus);
 
-    pci_bus_realize(qbus, errp);
+    if (!pci_bus_realize(qbus, errp)) {
+        return false;
+    }
 
     /*
      * A PCI-E bus can support extended config space if it's the root
@@ -144,6 +148,8 @@ static void pcie_bus_realize(BusState *qbus, Error **errp)
             bus->flags |= PCI_BUS_EXTENDED_CONFIG_SPACE;
         }
     }
+
+    return true;
 }
 
 static void pci_bus_unrealize(BusState *qbus)
diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c
index 9ce1c9540b9..d7ef5d05e37 100644
--- a/hw/xen/xen-bus.c
+++ b/hw/xen/xen-bus.c
@@ -444,7 +444,7 @@ static void xen_bus_unrealize(BusState *bus)
     }
 }
 
-static void xen_bus_realize(BusState *bus, Error **errp)
+static bool xen_bus_realize(BusState *bus, Error **errp)
 {
     XenBus *xenbus = XEN_BUS(bus);
     unsigned int domid;
@@ -478,10 +478,11 @@ static void xen_bus_realize(BusState *bus, Error **errp)
                           "failed to set up enumeration watch: ");
     }
 
-    return;
+    return true;
 
 fail:
     xen_bus_unrealize(bus);
+    return false;
 }
 
 static void xen_bus_unplug_request(HotplugHandler *hotplug,
-- 
2.26.2



WARNING: multiple messages have this Message-ID (diff)
From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: Markus Armbruster <armbru@redhat.com>, qemu-devel@nongnu.org
Cc: "Laurent Vivier" <laurent@vivier.eu>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Anthony Perard" <anthony.perard@citrix.com>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"Paul Durrant" <paul@xen.org>,
	"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	xen-devel@lists.xenproject.org,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>
Subject: [PATCH 2/2] qdev: Let BusRealize() return a boolean value to indicate error
Date: Sun, 20 Sep 2020 13:44:16 +0200	[thread overview]
Message-ID: <20200920114416.353277-3-f4bug@amsat.org> (raw)
In-Reply-To: <20200920114416.353277-1-f4bug@amsat.org>

Commit 9940b2cfbc0 introduced qdev_realize() and qbus_realize()
with the ability to return a boolean value if an error occured,
thus the caller does not need to check if the Error* pointer is
set.
Provide the same ability to the BusRealize type.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 include/hw/qdev-core.h | 14 +++++++++++++-
 hw/hyperv/vmbus.c      |  5 +++--
 hw/nubus/nubus-bus.c   |  5 +++--
 hw/pci/pci.c           | 12 +++++++++---
 hw/xen/xen-bus.c       |  5 +++--
 5 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 02ac1c50b7f..eecfe794a71 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -32,7 +32,19 @@ typedef enum DeviceCategory {
 typedef void (*DeviceRealize)(DeviceState *dev, Error **errp);
 typedef void (*DeviceUnrealize)(DeviceState *dev);
 typedef void (*DeviceReset)(DeviceState *dev);
-typedef void (*BusRealize)(BusState *bus, Error **errp);
+/**
+ * BusRealize: Realize @bus.
+ * @bus: bus to realize
+ * @errp: pointer to error object
+ *
+ * On success, return true.
+ * On failure, store an error through @errp and return false.
+ */
+typedef bool (*BusRealize)(BusState *bus, Error **errp);
+/**
+ * BusUnrealize: Unrealize @bus.
+ * @bus: bus to unrealize
+ */
 typedef void (*BusUnrealize)(BusState *bus);
 
 /**
diff --git a/hw/hyperv/vmbus.c b/hw/hyperv/vmbus.c
index 6ef895bc352..8a0452b2464 100644
--- a/hw/hyperv/vmbus.c
+++ b/hw/hyperv/vmbus.c
@@ -2487,7 +2487,7 @@ static const TypeInfo vmbus_dev_type_info = {
     .instance_init = vmbus_dev_instance_init,
 };
 
-static void vmbus_realize(BusState *bus, Error **errp)
+static bool vmbus_realize(BusState *bus, Error **errp)
 {
     int ret = 0;
     Error *local_err = NULL;
@@ -2519,7 +2519,7 @@ static void vmbus_realize(BusState *bus, Error **errp)
         goto clear_event_notifier;
     }
 
-    return;
+    return true;
 
 clear_event_notifier:
     event_notifier_cleanup(&vmbus->notifier);
@@ -2528,6 +2528,7 @@ remove_msg_handler:
 error_out:
     qemu_mutex_destroy(&vmbus->rx_queue_lock);
     error_propagate(errp, local_err);
+    return false;
 }
 
 static void vmbus_unrealize(BusState *bus)
diff --git a/hw/nubus/nubus-bus.c b/hw/nubus/nubus-bus.c
index 942a6d5342d..d20d9c0f72c 100644
--- a/hw/nubus/nubus-bus.c
+++ b/hw/nubus/nubus-bus.c
@@ -65,12 +65,13 @@ static const MemoryRegionOps nubus_super_slot_ops = {
     },
 };
 
-static void nubus_realize(BusState *bus, Error **errp)
+static bool nubus_realize(BusState *bus, Error **errp)
 {
     if (!nubus_find()) {
         error_setg(errp, "at most one %s device is permitted", TYPE_NUBUS_BUS);
-        return;
+        return false;
     }
+    return true;
 }
 
 static void nubus_init(Object *obj)
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index de0fae10ab9..f535ebac847 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -115,7 +115,7 @@ static void pcibus_machine_done(Notifier *notifier, void *data)
     }
 }
 
-static void pci_bus_realize(BusState *qbus, Error **errp)
+static bool pci_bus_realize(BusState *qbus, Error **errp)
 {
     PCIBus *bus = PCI_BUS(qbus);
 
@@ -123,13 +123,17 @@ static void pci_bus_realize(BusState *qbus, Error **errp)
     qemu_add_machine_init_done_notifier(&bus->machine_done);
 
     vmstate_register(NULL, VMSTATE_INSTANCE_ID_ANY, &vmstate_pcibus, bus);
+
+    return true;
 }
 
-static void pcie_bus_realize(BusState *qbus, Error **errp)
+static bool pcie_bus_realize(BusState *qbus, Error **errp)
 {
     PCIBus *bus = PCI_BUS(qbus);
 
-    pci_bus_realize(qbus, errp);
+    if (!pci_bus_realize(qbus, errp)) {
+        return false;
+    }
 
     /*
      * A PCI-E bus can support extended config space if it's the root
@@ -144,6 +148,8 @@ static void pcie_bus_realize(BusState *qbus, Error **errp)
             bus->flags |= PCI_BUS_EXTENDED_CONFIG_SPACE;
         }
     }
+
+    return true;
 }
 
 static void pci_bus_unrealize(BusState *qbus)
diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c
index 9ce1c9540b9..d7ef5d05e37 100644
--- a/hw/xen/xen-bus.c
+++ b/hw/xen/xen-bus.c
@@ -444,7 +444,7 @@ static void xen_bus_unrealize(BusState *bus)
     }
 }
 
-static void xen_bus_realize(BusState *bus, Error **errp)
+static bool xen_bus_realize(BusState *bus, Error **errp)
 {
     XenBus *xenbus = XEN_BUS(bus);
     unsigned int domid;
@@ -478,10 +478,11 @@ static void xen_bus_realize(BusState *bus, Error **errp)
                           "failed to set up enumeration watch: ");
     }
 
-    return;
+    return true;
 
 fail:
     xen_bus_unrealize(bus);
+    return false;
 }
 
 static void xen_bus_unplug_request(HotplugHandler *hotplug,
-- 
2.26.2



  parent reply	other threads:[~2020-09-20 11:49 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-20 11:44 [PATCH 0/2] qdev: Let BusRealize() return a boolean value to indicate error Philippe Mathieu-Daudé
2020-09-20 11:44 ` Philippe Mathieu-Daudé
2020-09-20 11:44 ` [PATCH 1/2] qdev: Document qbus_realize() and qbus_unrealize() Philippe Mathieu-Daudé
2020-09-20 11:44   ` Philippe Mathieu-Daudé
2020-09-20 11:44 ` Philippe Mathieu-Daudé [this message]
2020-09-20 11:44   ` [PATCH 2/2] qdev: Let BusRealize() return a boolean value to indicate error Philippe Mathieu-Daudé
2020-09-21  7:01   ` Paul Durrant
2020-09-21  7:01     ` Paul Durrant
2020-09-21  8:19   ` Markus Armbruster
2020-09-21  8:19     ` Markus Armbruster
2020-09-21  9:38     ` Philippe Mathieu-Daudé
2020-09-21  9:38       ` Philippe Mathieu-Daudé
2020-09-21 12:58       ` Markus Armbruster
2020-09-21 12:58         ` Markus Armbruster
2020-09-20 22:56 ` [PATCH 0/2] " Richard Henderson
2020-09-20 22:56   ` Richard Henderson

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=20200920114416.353277-3-f4bug@amsat.org \
    --to=f4bug@amsat.org \
    --cc=anthony.perard@citrix.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=laurent@vivier.eu \
    --cc=mst@redhat.com \
    --cc=paul@xen.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /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.