Fix -usbdevice crash
cover Fix -usbdevice crash
This series fixes bug 573827, which is a segfault when you do:
$ qemu -usbdevice serial
All commits backported from current master, just minimally tested.
PATCH 1/3 Fix -usbdevice crash
From: Paul Brook <[email protected]>
If -usbdevice is used on a machine with no USB busses, usb_create will fail and return NULL. Patch below handles this failure gracefully rather than crashing when we try to init the device.
--- hw/usb-bus.c | 3 +++ hw/usb-msd.c | 3 +++ hw/usb-net.c | 3 +++ hw/usb-serial.c | 3 +++ 4 files changed, 12 insertions(+), 0 deletions(-)
hw/usb-bus.c +3 -0
@@ -102,6 +102,9 @@ USBDevice *usb_create(USBBus *bus, const char *name)USBDevice *usb_create_simple (USBBus *bus,const char *name) {USBDevice *dev =usb_create (bus, name); +if (!dev) { +hw_error ("Failed to create USB device '%s'\n" , name); + }qdev_init_nofail (&dev->qdev);return dev; }
hw/usb-msd.c +3 -0
@@ -592,6 +592,9 @@ static USBDevice *usb_msd_init(const char *filename)/* create guest device */ dev =usb_create (NULL /* FIXME */ ,"usb-storage" ); +if (!dev) { +return NULL ; + }qdev_prop_set_drive (&dev->qdev,"drive" , dinfo);if (qdev_init (&dev->qdev) <0 )return NULL ;
hw/usb-net.c +3 -0
@@ -1491,6 +1491,9 @@ static USBDevice *usb_net_init(const char *cmdline) } dev =usb_create (NULL /* FIXME */ ,"usb-net" ); +if (!dev) { +return NULL ; + }qdev_set_nic_properties (&dev->qdev, &nd_table[idx]);qdev_init_nofail (&dev->qdev);return dev;
hw/usb-serial.c +3 -0
@@ -594,6 +594,9 @@ static USBDevice *usb_serial_init(const char *filename)return NULL ; dev =usb_create (NULL /* FIXME */ ,"usb-serial" ); +if (!dev) { +return NULL ; + }qdev_prop_set_chr (&dev->qdev,"chardev" , cdrv);if (vendorid)qdev_prop_set_uint16 (&dev->qdev,"vendorid" , vendorid);
Signature · 1 line
1.7.1.231.gd0b16
PATCH 2/3 Avoid crash on '-usbdevice <device>' without parameters
In reply to Luiz CapitulinoFrom: Jan Kiszka <[email protected]>
Many usbdevice_init implementors assume params is non-NULL.
--- hw/usb-bus.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
hw/usb-bus.c +3 -1
@@ -264,7 +264,8 @@ USBDevice *usbdevice_create(const char *cmdline)USBBus *bus =usb_bus_find (-1 /* any */ );DeviceInfo *info;USBDeviceInfo *usb; -char driver[32 ], *params; +char driver[32 ]; +const char *params;int len; params =strchr (cmdline,':' );
@@ -275,6 +276,7 @@ USBDevice *usbdevice_create(const char *cmdline) len =sizeof (driver);pstrcpy (driver, len, cmdline); }else { + params ="" ;pstrcpy (driver,sizeof (driver), cmdline); }
Signature · 1 line
1.7.1.231.gd0b16
PATCH 3/3 usb-bus: fix no params
In reply to Luiz CapitulinoAfter commit 702f3e0fb52c124c07f215426eeadb70a716643f, the params is nerver NULL. It should check *params instead of params to determine whether the params is empty.
Conflicts:
hw/usb-bus.c
--- hw/usb-bus.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
hw/usb-bus.c +1 -1
@@ -299,7 +299,7 @@ USBDevice *usbdevice_create(const char *cmdline) }if (!usb->usbdevice_init) { -if (params) { +if (*params) {qemu_error ("usbdevice %s accepts no params\n" , driver);return NULL ; }
Signature · 1 line
1.7.1.231.gd0b16
Aurelien Jarno
AppliedQuoted 6 lines · Luiz Capitulino
This series fixes bug 573827, which is a segfault when you do:
$ qemu -usbdevice serialAll commits backported from current master, just minimally tested.
Thanks, applied.
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net