All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>, Gerd Hoffmann <kraxel@redhat.com>
Subject: [PULL 55/84] usb: Eliminate usb_try_create_simple()
Date: Mon, 15 Jun 2020 22:39:39 +0200	[thread overview]
Message-ID: <20200615204008.3069956-56-armbru@redhat.com> (raw)
In-Reply-To: <20200615204008.3069956-1-armbru@redhat.com>

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



  parent reply	other threads:[~2020-06-15 21:15 UTC|newest]

Thread overview: 96+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-15 20:38 [PULL 00/84] QOM patches for 2020-06-15 Markus Armbruster
2020-06-15 20:38 ` [PULL 01/84] qom: Constify object_get_canonical_path{, _component}()'s parameter Markus Armbruster
2020-06-15 20:38 ` [PULL 02/84] qom: Make "info qom-tree" show children sorted Markus Armbruster
2020-06-15 20:38 ` [PULL 03/84] arm/stm32f405: Fix realization of "stm32f2xx-adc" devices Markus Armbruster
2020-06-15 20:38 ` [PULL 04/84] display/xlnx_dp: Fix to realize "i2c-ddc" and "aux-to-i2c-bridge" Markus Armbruster
2020-06-15 20:38 ` [PULL 05/84] sd/pxa2xx_mmci: Fix to realize "pxa2xx-mmci" device Markus Armbruster
2020-06-15 20:38 ` [PULL 06/84] arm/aspeed: Compute the number of CPUs from the SoC definition Markus Armbruster
2020-06-15 20:38 ` [PULL 07/84] arm/aspeed: Rework NIC attachment Markus Armbruster
2020-06-15 20:38 ` [PULL 08/84] armv7m: Delete unused "ARM,bitband-memory" devices Markus Armbruster
2020-06-15 20:38 ` [PULL 09/84] auxbus: Fix aux-to-i2c-bridge to be a subtype of aux-slave Markus Armbruster
2020-06-15 20:38 ` [PULL 10/84] mac_via: Fix to realize "mos6522-q800-via*" devices Markus Armbruster
2020-06-15 20:38 ` [PULL 11/84] macio: Fix to realize "mos6522-cuda" and "mos6522-pmu" devices Markus Armbruster
2020-06-15 20:38 ` [PULL 12/84] macio: Delete unused "macio-gpio" devices Markus Armbruster
2020-06-15 20:38 ` [PULL 13/84] pnv/phb4: Delete unused "pnv-phb4-pec-stack" devices Markus Armbruster
2020-06-15 20:38 ` [PULL 14/84] MAINTAINERS: Make section PowerNV cover pci-host/pnv* as well Markus Armbruster
2020-06-15 20:38 ` [PULL 15/84] ppc4xx: Drop redundant device realization Markus Armbruster
2020-06-15 20:39 ` [PULL 16/84] macio: Put "macio-nvram" device on the macio bus Markus Armbruster
2020-06-15 20:58   ` BALATON Zoltan
2020-06-16  6:48     ` Philippe Mathieu-Daudé
2020-06-15 20:39 ` [PULL 17/84] macio: Fix macio-bus to be a subtype of System bus Markus Armbruster
2020-06-15 20:39 ` [PULL 18/84] ppc/pnv: Put "*-pnv-chip" and "pnv-xive" on the main system bus Markus Armbruster
2020-06-15 20:39 ` [PULL 19/84] pnv/psi: Correct the pnv-psi* devices not to be sysbus devices Markus Armbruster
2020-06-15 20:39 ` [PULL 20/84] display/sm501 display/ati: Fix to realize "i2c-ddc" Markus Armbruster
2020-06-15 20:39 ` [PULL 21/84] riscv: Fix to put "riscv.hart_array" devices on sysbus Markus Armbruster
2020-06-15 20:39   ` Markus Armbruster
2020-06-15 20:39 ` [PULL 22/84] riscv: Fix type of SiFive[EU]SocState, member parent_obj Markus Armbruster
2020-06-15 20:39   ` Markus Armbruster
2020-06-15 20:39 ` [PULL 23/84] sparc/leon3: Fix to put grlib,* devices on sysbus Markus Armbruster
2020-06-15 20:39 ` [PULL 24/84] qdev: Assert devices are plugged into a bus that can take them Markus Armbruster
2020-06-15 20:39 ` [PULL 25/84] sd: Hide the qdev-but-not-quite thing created by sd_init() Markus Armbruster
2020-06-15 20:39 ` [PULL 26/84] qdev: Assert onboard devices all get realized properly Markus Armbruster
2020-06-15 20:39 ` [PULL 27/84] qdev: Rename qbus_realize() to qbus_init() Markus Armbruster
2020-06-15 20:39 ` [PULL 28/84] Revert "hw/prep: realize the PCI root bus as part of the prep init" Markus Armbruster
2020-06-15 20:39 ` [PULL 29/84] Revert "hw/versatile: realize the PCI root bus as part of the versatile init" Markus Armbruster
2020-06-15 20:39 ` [PULL 30/84] qdev: New qdev_new(), qdev_realize(), etc Markus Armbruster
2020-06-15 20:39 ` [PULL 31/84] qdev: Put qdev_new() to use with Coccinelle Markus Armbruster
2020-06-15 20:39 ` [PULL 32/84] qdev: Convert to qbus_realize(), qbus_unrealize() Markus Armbruster
2020-06-15 20:39 ` [PULL 33/84] qdev: Convert to qdev_unrealize() with Coccinelle Markus Armbruster
2020-06-15 20:39 ` [PULL 34/84] qdev: Convert to qdev_unrealize() manually Markus Armbruster
2020-06-15 20:39 ` [PULL 35/84] qdev: Convert uses of qdev_create() with Coccinelle Markus Armbruster
2020-06-15 20:39 ` [PULL 36/84] qdev: Convert uses of qdev_create() manually Markus Armbruster
2020-06-15 20:39 ` [PULL 37/84] qdev: Convert uses of qdev_set_parent_bus() with Coccinelle Markus Armbruster
2020-06-15 20:39 ` [PULL 38/84] qdev: Convert uses of qdev_set_parent_bus() manually Markus Armbruster
2020-06-15 20:39 ` [PULL 39/84] pci: New pci_new(), pci_realize_and_unref() etc Markus Armbruster
2020-06-15 20:39 ` [PULL 40/84] hw/ppc: Eliminate two superfluous QOM casts Markus Armbruster
2020-06-15 20:39 ` [PULL 41/84] pci: Convert uses of pci_create() etc. with Coccinelle Markus Armbruster
2020-06-15 20:39 ` [PULL 42/84] pci: Convert uses of pci_create() etc. manually Markus Armbruster
2020-06-15 20:39 ` [PULL 43/84] pci: pci_create(), pci_create_multifunction() are now unused, drop Markus Armbruster
2020-06-15 20:39 ` [PULL 44/84] isa: New isa_new(), isa_realize_and_unref() etc Markus Armbruster
2020-06-15 20:39 ` [PULL 45/84] isa: Convert uses of isa_create() with Coccinelle Markus Armbruster
2020-06-15 20:39 ` [PULL 46/84] isa: Convert uses of isa_create(), isa_try_create() manually Markus Armbruster
2020-06-15 20:39 ` [PULL 47/84] isa: isa_create(), isa_try_create() are now unused, drop Markus Armbruster
2020-06-15 20:39 ` [PULL 48/84] ssi: ssi_auto_connect_slaves() never does anything, drop Markus Armbruster
2020-06-15 20:39 ` [PULL 49/84] ssi: Convert uses of ssi_create_slave_no_init() with Coccinelle Markus Armbruster
2020-06-15 20:39 ` [PULL 50/84] ssi: Convert last use of ssi_create_slave_no_init() manually Markus Armbruster
2020-06-15 20:39 ` [PULL 51/84] ssi: ssi_create_slave_no_init() is now unused, drop Markus Armbruster
2020-06-15 20:39 ` [PULL 52/84] usb: New usb_new(), usb_realize_and_unref() Markus Armbruster
2020-06-15 20:39 ` [PULL 53/84] usb: Convert uses of usb_create() Markus Armbruster
2020-06-15 20:39 ` [PULL 54/84] usb: usb_create() is now unused, drop Markus Armbruster
2020-06-15 20:39 ` Markus Armbruster [this message]
2020-06-15 20:39 ` [PULL 56/84] qdev: qdev_create(), qdev_try_create() are " Markus Armbruster
2020-06-15 20:39 ` [PULL 57/84] auxbus: Rename aux_init_bus() to aux_bus_init() Markus Armbruster
2020-06-15 20:39 ` [PULL 58/84] auxbus: New aux_bus_realize(), pairing with aux_bus_init() Markus Armbruster
2020-06-15 20:39 ` [PULL 59/84] auxbus: Convert a use of qdev_set_parent_bus() Markus Armbruster
2020-06-15 20:39 ` [PULL 60/84] auxbus: Eliminate aux_create_slave() Markus Armbruster
2020-06-15 20:39 ` [PULL 61/84] qom: Tidy up a few object_initialize_child() calls Markus Armbruster
2020-06-15 20:39 ` [PULL 62/84] qom: Less verbose object_initialize_child() Markus Armbruster
2020-06-15 20:39 ` [PULL 63/84] macio: Convert use of qdev_set_parent_bus() Markus Armbruster
2020-06-15 20:39 ` [PULL 64/84] macio: Eliminate macio_init_child_obj() Markus Armbruster
2020-06-15 20:39 ` [PULL 65/84] sysbus: Drop useless OBJECT() in sysbus_init_child_obj() calls Markus Armbruster
2020-06-15 20:39 ` [PULL 66/84] microbit: Tidy up sysbus_init_child_obj() @child argument Markus Armbruster
2020-06-15 20:39 ` [PULL 67/84] sysbus: Tidy up sysbus_init_child_obj()'s @childsize arg, part 1 Markus Armbruster
2020-06-15 20:39 ` [PULL 68/84] hw/arm/armsse: Pass correct child size to sysbus_init_child_obj() Markus Armbruster
2020-06-15 20:39 ` [PULL 69/84] sysbus: Tidy up sysbus_init_child_obj()'s @childsize arg, part 2 Markus Armbruster
2020-06-15 20:39 ` [PULL 70/84] sysbus: New sysbus_realize(), sysbus_realize_and_unref() Markus Armbruster
2020-06-15 20:39 ` [PULL 71/84] sysbus: Convert to sysbus_realize() etc. with Coccinelle Markus Armbruster
2020-06-15 20:39 ` [PULL 72/84] qdev: Drop qdev_realize() support for null bus Markus Armbruster
2020-06-15 20:39 ` [PULL 73/84] sysbus: Convert qdev_set_parent_bus() use with Coccinelle, part 1 Markus Armbruster
2020-06-15 20:39 ` [PULL 74/84] sysbus: Convert qdev_set_parent_bus() use with Coccinelle, part 2 Markus Armbruster
2020-06-15 20:39 ` [PULL 75/84] sysbus: Convert qdev_set_parent_bus() use with Coccinelle, part 3 Markus Armbruster
2020-06-15 20:40 ` [PULL 76/84] sysbus: Convert qdev_set_parent_bus() use with Coccinelle, part 4 Markus Armbruster
2020-06-15 20:40 ` [PULL 77/84] sysbus: sysbus_init_child_obj() is now unused, drop Markus Armbruster
2020-06-15 20:40 ` [PULL 78/84] microbit: Eliminate two local variables in microbit_init() Markus Armbruster
2020-06-15 20:40 ` [PULL 79/84] s390x/event-facility: Simplify creation of SCLP event devices Markus Armbruster
2020-06-15 20:40 ` [PULL 80/84] qdev: Make qdev_realize() support bus-less devices Markus Armbruster
2020-06-15 20:40 ` [PULL 81/84] qdev: Use qdev_realize() in qdev_device_add() Markus Armbruster
2020-06-15 20:40 ` [PULL 82/84] qdev: Convert bus-less devices to qdev_realize() with Coccinelle Markus Armbruster
2020-06-15 20:40 ` [PULL 83/84] qdev: qdev_init_nofail() is now unused, drop Markus Armbruster
2020-06-15 20:40 ` [PULL 84/84] MAINTAINERS: Make section QOM cover hw/core/*bus.c as well Markus Armbruster
2020-06-16 12:26 ` [PULL 00/84] QOM patches for 2020-06-15 Peter Maydell
2020-06-16 15:26   ` Thomas Huth
2020-06-17  3:30     ` Philippe Mathieu-Daudé
2020-06-26 18:28 ` Peter Maydell
2020-06-27 11:53   ` Markus Armbruster
2020-06-27 15:11     ` Peter Maydell
2020-06-29  7:25       ` Philippe Mathieu-Daudé

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=20200615204008.3069956-56-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.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.