[Qemu-devel] [PATCH] usb: Simplify the parameter parsing of the legacy usb serial device

Thomas Huth posted 1 patch 6 years, 10 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/1495177204-16808-1-git-send-email-thuth@redhat.com
Test checkpatch passed
Test docker passed
Test s390x passed
hw/usb/dev-serial.c | 21 +++++----------------
1 file changed, 5 insertions(+), 16 deletions(-)
[Qemu-devel] [PATCH] usb: Simplify the parameter parsing of the legacy usb serial device
Posted by Thomas Huth 6 years, 10 months ago
Coverity complains about the current code, so let's get rid of
the now unneeded while loop and simply always emit "unrecognized
serial USB option" for all unsupported options.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 hw/usb/dev-serial.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)

diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c
index 83a4f0e..76ceca1 100644
--- a/hw/usb/dev-serial.c
+++ b/hw/usb/dev-serial.c
@@ -516,27 +516,16 @@ static USBDevice *usb_serial_init(USBBus *bus, const char *filename)
     char label[32];
     static int index;
 
-    while (*filename && *filename != ':') {
-        const char *p;
-
-        if (strstart(filename, "vendorid=", &p)) {
-            error_report("vendorid is not supported anymore");
-            return NULL;
-        } else if (strstart(filename, "productid=", &p)) {
-            error_report("productid is not supported anymore");
-            return NULL;
-        } else {
-            error_report("unrecognized serial USB option %s", filename);
-            return NULL;
-        }
-        while(*filename == ',')
-            filename++;
+    if (*filename == ':') {
+        filename++;
+    } else if (*filename) {
+        error_report("unrecognized serial USB option %s", filename);
+        return NULL;
     }
     if (!*filename) {
         error_report("character device specification needed");
         return NULL;
     }
-    filename++;
 
     snprintf(label, sizeof(label), "usbserial%d", index++);
     cdrv = qemu_chr_new(label, filename);
-- 
1.8.3.1


Re: [Qemu-devel] [PATCH] usb: Simplify the parameter parsing of the legacy usb serial device
Posted by Paolo Bonzini 6 years, 10 months ago

On 19/05/2017 09:00, Thomas Huth wrote:
> Coverity complains about the current code, so let's get rid of
> the now unneeded while loop and simply always emit "unrecognized
> serial USB option" for all unsupported options.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  hw/usb/dev-serial.c | 21 +++++----------------
>  1 file changed, 5 insertions(+), 16 deletions(-)
> 
> diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c
> index 83a4f0e..76ceca1 100644
> --- a/hw/usb/dev-serial.c
> +++ b/hw/usb/dev-serial.c
> @@ -516,27 +516,16 @@ static USBDevice *usb_serial_init(USBBus *bus, const char *filename)
>      char label[32];
>      static int index;
>  
> -    while (*filename && *filename != ':') {
> -        const char *p;
> -
> -        if (strstart(filename, "vendorid=", &p)) {
> -            error_report("vendorid is not supported anymore");
> -            return NULL;
> -        } else if (strstart(filename, "productid=", &p)) {
> -            error_report("productid is not supported anymore");
> -            return NULL;
> -        } else {
> -            error_report("unrecognized serial USB option %s", filename);
> -            return NULL;
> -        }
> -        while(*filename == ',')
> -            filename++;
> +    if (*filename == ':') {
> +        filename++;
> +    } else if (*filename) {
> +        error_report("unrecognized serial USB option %s", filename);
> +        return NULL;
>      }
>      if (!*filename) {
>          error_report("character device specification needed");
>          return NULL;
>      }
> -    filename++;
>  
>      snprintf(label, sizeof(label), "usbserial%d", index++);
>      cdrv = qemu_chr_new(label, filename);
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>