Patchwork usb-serial: Fail instead of crash when chardev is missing

login
register
mail settings
Submitter Markus Armbruster
Date May 28, 2010, 3:03 p.m.
Message ID <m37hmo6pc5.fsf@blackfin.pond.sub.org>
Download mbox | patch
Permalink /patch/53907/
State New
Headers show

Comments

Markus Armbruster - May 28, 2010, 3:03 p.m.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/usb-serial.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
Gerd Hoffmann - May 31, 2010, 9:24 a.m.
On 05/28/10 17:03, Markus Armbruster wrote:
>
> Signed-off-by: Markus Armbruster<armbru@redhat.com>

Nice catch.

Acked-by: Gerd Hoffmann <kraxel@redhat.com>

cheers,
   Gerd
Aurelien Jarno - June 30, 2010, 6:36 p.m.
On Fri, May 28, 2010 at 05:03:22PM +0200, Markus Armbruster wrote:
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/usb-serial.c |    5 +++++
>  1 files changed, 5 insertions(+), 0 deletions(-)

Thanks, applied.

> diff --git a/hw/usb-serial.c b/hw/usb-serial.c
> index 5b2483a..c19580f 100644
> --- a/hw/usb-serial.c
> +++ b/hw/usb-serial.c
> @@ -545,6 +545,11 @@ static int usb_serial_initfn(USBDevice *dev)
>      USBSerialState *s = DO_UPCAST(USBSerialState, dev, dev);
>      s->dev.speed = USB_SPEED_FULL;
>  
> +    if (!s->cs) {
> +        error_report("Property chardev is required");
> +        return -1;
> +    }
> +
>      qemu_chr_add_handlers(s->cs, usb_serial_can_read, usb_serial_read,
>                            usb_serial_event, s);
>      usb_serial_handle_reset(dev);
> -- 
> 1.6.6.1
> 
> 
>

Patch

diff --git a/hw/usb-serial.c b/hw/usb-serial.c
index 5b2483a..c19580f 100644
--- a/hw/usb-serial.c
+++ b/hw/usb-serial.c
@@ -545,6 +545,11 @@  static int usb_serial_initfn(USBDevice *dev)
     USBSerialState *s = DO_UPCAST(USBSerialState, dev, dev);
     s->dev.speed = USB_SPEED_FULL;
 
+    if (!s->cs) {
+        error_report("Property chardev is required");
+        return -1;
+    }
+
     qemu_chr_add_handlers(s->cs, usb_serial_can_read, usb_serial_read,
                           usb_serial_event, s);
     usb_serial_handle_reset(dev);