usb: Improve -usbdevice error reporting a bit

Most LegacyUSBFactory usbdevice_init() methods realize with
qdev_init_nofail(), even though their caller usbdevice_create() can
handle failure.  Okay if it really can't fail (I didn't check), but
somewhat brittle.

usb_msd_init() and usb_bt_init() call qdev_init().  The latter
additionally reports an error when qdev_init() fails.

Realization failure produces multiple error reports: a specific one
from qdev_init(), and generic ones from usb_bt_init(),
usb_create_simple(), usbdevice_create() and usb_parse().

Remove realization from the usbdevice_init() methods.  Realize in
usbdevice_create(), and produce exactly one error message there.  You
still get another one from usb_parse().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Markus Armbruster 2015-02-04 13:28:09 +01:00 committed by Gerd Hoffmann
parent 4806ec9b2c
commit 3bc36a401e
6 changed files with 19 additions and 17 deletions

View file

@ -651,10 +651,12 @@ USBDevice *usbdevice_create(const char *cmdline)
{
USBBus *bus = usb_bus_find(-1 /* any */);
LegacyUSBFactory *f = NULL;
Error *err = NULL;
GSList *i;
char driver[32];
const char *params;
int len;
USBDevice *dev;
params = strchr(cmdline,':');
if (params) {
@ -689,14 +691,28 @@ USBDevice *usbdevice_create(const char *cmdline)
return NULL;
}
if (!f->usbdevice_init) {
if (f->usbdevice_init) {
dev = f->usbdevice_init(bus, params);
} else {
if (*params) {
error_report("usbdevice %s accepts no params", driver);
return NULL;
}
return usb_create_simple(bus, f->name);
dev = usb_create(bus, f->name);
}
return f->usbdevice_init(bus, params);
if (!dev) {
error_report("Failed to create USB device '%s'", f->name);
return NULL;
}
object_property_set_bool(OBJECT(dev), true, "realized", &err);
if (err) {
error_report("Failed to initialize USB device '%s': %s",
f->name, error_get_pretty(err));
error_free(err);
object_unparent(OBJECT(dev));
return NULL;
}
return dev;
}
static void usb_device_class_init(ObjectClass *klass, void *data)