[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 29/39] usb: Eliminate usb_try_create_simple()
From: |
Markus Armbruster |
Subject: |
[PATCH v3 29/39] usb: Eliminate usb_try_create_simple() |
Date: |
Tue, 9 Jun 2020 18:39:22 +0200 |
usb_try_create_simple() is qdev_try_new() and qdev_realize_and_unref()
with more verbose error messages. Of its two users, one ignores
errors, and the other asserts they are impossible.
Make them use qdev_try_new() and qdev_realize_and_unref() directly,
and eliminate usb_try_create_simple
Cc: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/usb/bus.c | 37 ++++++++++++++-----------------------
1 file changed, 14 insertions(+), 23 deletions(-)
diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index 5c4d31614e..a81aee2051 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -318,35 +318,22 @@ USBDevice *usb_new(const char *name)
return USB_DEVICE(qdev_new(name));
}
+static USBDevice *usb_try_new(const char *name)
+{
+ return USB_DEVICE(qdev_try_new(name));
+}
+
bool usb_realize_and_unref(USBDevice *dev, USBBus *bus, Error **errp)
{
return qdev_realize_and_unref(&dev->qdev, &bus->qbus, errp);
}
-static USBDevice *usb_try_create_simple(USBBus *bus, const char *name,
- Error **errp)
-{
- Error *err = NULL;
- DeviceState *dev;
-
- dev = qdev_try_new(name);
- if (!dev) {
- error_setg(errp, "Failed to create USB device '%s'", name);
- return NULL;
- }
- qdev_realize_and_unref(dev, &bus->qbus, &err);
- if (err) {
- error_propagate_prepend(errp, err,
- "Failed to initialize USB device '%s': ",
- name);
- return NULL;
- }
- return USB_DEVICE(dev);
-}
-
USBDevice *usb_create_simple(USBBus *bus, const char *name)
{
- return usb_try_create_simple(bus, name, &error_abort);
+ USBDevice *dev = usb_new(name);
+
+ usb_realize_and_unref(dev, bus, &error_abort);
+ return dev;
}
static void usb_fill_port(USBPort *port, void *opaque, int index,
@@ -426,6 +413,7 @@ void usb_claim_port(USBDevice *dev, Error **errp)
{
USBBus *bus = usb_bus_from_device(dev);
USBPort *port;
+ USBDevice *hub;
assert(dev->port == NULL);
@@ -443,7 +431,10 @@ void usb_claim_port(USBDevice *dev, Error **errp)
} else {
if (bus->nfree == 1 && strcmp(object_get_typename(OBJECT(dev)),
"usb-hub") != 0) {
/* Create a new hub and chain it on */
- usb_try_create_simple(bus, "usb-hub", NULL);
+ hub = usb_try_new("usb-hub");
+ if (hub) {
+ usb_realize_and_unref(hub, bus, NULL);
+ }
}
if (bus->nfree == 0) {
error_setg(errp, "tried to attach usb device %s to a bus "
--
2.26.2
- [PATCH v3 32/39] auxbus: New aux_bus_realize(), pairing with aux_bus_init(), (continued)
- [PATCH v3 32/39] auxbus: New aux_bus_realize(), pairing with aux_bus_init(), Markus Armbruster, 2020/06/09
- [PATCH v3 37/39] macio: Convert use of qdev_set_parent_bus(), Markus Armbruster, 2020/06/09
- [PATCH v3 35/39] qom: Tidy up a few object_initialize_child() calls, Markus Armbruster, 2020/06/09
- [PATCH v3 26/39] usb: New usb_new(), usb_realize_and_unref(), Markus Armbruster, 2020/06/09
- [PATCH v3 09/39] qdev: Convert uses of qdev_create() with Coccinelle, Markus Armbruster, 2020/06/09
- [PATCH v3 02/39] Revert "hw/prep: realize the PCI root bus as part of the prep init", Markus Armbruster, 2020/06/09
- [PATCH v3 38/39] macio: Eliminate macio_init_child_obj(), Markus Armbruster, 2020/06/09
- [PATCH v3 34/39] auxbus: Eliminate aux_create_slave(), Markus Armbruster, 2020/06/09
- [PATCH v3 28/39] usb: usb_create() is now unused, drop, Markus Armbruster, 2020/06/09
- [PATCH v3 33/39] auxbus: Convert a use of qdev_set_parent_bus(), Markus Armbruster, 2020/06/09
- [PATCH v3 29/39] usb: Eliminate usb_try_create_simple(),
Markus Armbruster <=
- [PATCH v3 17/39] pci: pci_create(), pci_create_multifunction() are now unused, drop, Markus Armbruster, 2020/06/09
- [PATCH v3 13/39] pci: New pci_new(), pci_realize_and_unref() etc., Markus Armbruster, 2020/06/09
- [PATCH v3 22/39] ssi: ssi_auto_connect_slaves() never does anything, drop, Markus Armbruster, 2020/06/09
- [PATCH v3 27/39] usb: Convert uses of usb_create(), Markus Armbruster, 2020/06/09
- [PATCH v3 11/39] qdev: Convert uses of qdev_set_parent_bus() with Coccinelle, Markus Armbruster, 2020/06/09
- [PATCH v3 04/39] qdev: New qdev_new(), qdev_realize(), etc., Markus Armbruster, 2020/06/09
- [PATCH v3 39/39] sysbus: Drop useless OBJECT() in sysbus_init_child_obj() calls, Markus Armbruster, 2020/06/09
- [PATCH v3 36/39] qom: Less verbose object_initialize_child(), Markus Armbruster, 2020/06/09
- [PATCH v3 31/39] auxbus: Rename aux_init_bus() to aux_bus_init(), Markus Armbruster, 2020/06/09
- [PATCH v3 20/39] isa: Convert uses of isa_create(), isa_try_create() manually, Markus Armbruster, 2020/06/09