diff options
author | Markus Armbruster <armbru@redhat.com> | 2020-06-10 07:32:18 +0200 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2020-06-15 22:05:28 +0200 |
commit | 535770518f85e6e8b912c262492a251053491637 (patch) | |
tree | 2dd70505ef97c9d94383ac886ac05f769b69ce46 /hw | |
parent | 8cd81a9e551265dc63fe80aa83af773709e48552 (diff) | |
download | qemu-535770518f85e6e8b912c262492a251053491637.zip qemu-535770518f85e6e8b912c262492a251053491637.tar.gz qemu-535770518f85e6e8b912c262492a251053491637.tar.bz2 |
usb: Eliminate usb_try_create_simple()
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>
Message-Id: <20200610053247.1583243-30-armbru@redhat.com>
Diffstat (limited to 'hw')
-rw-r--r-- | hw/usb/bus.c | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/hw/usb/bus.c b/hw/usb/bus.c index 5c4d316..a81aee2 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)); } -bool usb_realize_and_unref(USBDevice *dev, USBBus *bus, Error **errp) +static USBDevice *usb_try_new(const char *name) { - return qdev_realize_and_unref(&dev->qdev, &bus->qbus, errp); + return USB_DEVICE(qdev_try_new(name)); } -static USBDevice *usb_try_create_simple(USBBus *bus, const char *name, - Error **errp) +bool usb_realize_and_unref(USBDevice *dev, USBBus *bus, 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); + return qdev_realize_and_unref(&dev->qdev, &bus->qbus, errp); } 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 " |