usb-host: fix zero-length packets
authorGerd Hoffmann <kraxel@redhat.com>
Thu, 19 Apr 2012 11:36:40 +0000 (13:36 +0200)
committerGerd Hoffmann <kraxel@redhat.com>
Thu, 26 Apr 2012 10:21:16 +0000 (12:21 +0200)
usb-host optimizes away zero-length packets by not entering the
processing loop at all.  Which isn't correct, we should submit a
zero-length urb to the host devicein that case.  This patch makes
sure we run the processing loop at least once.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
hw/usb/host-linux.c

index c3684c8f92e6287ae6f5be85499518dbcf8c9983..048f8ffa8bcd5709c391c023138ef33ff8a58f70 100644 (file)
@@ -887,8 +887,8 @@ static int usb_host_handle_data(USBDevice *dev, USBPacket *p)
     prem = 0;
     pbuf = NULL;
     rem = p->iov.size;
-    while (rem) {
-        if (prem == 0) {
+    do {
+        if (prem == 0 && rem > 0) {
             assert(v < p->iov.niov);
             prem = p->iov.iov[v].iov_len;
             pbuf = p->iov.iov[v].iov_base;
@@ -938,7 +938,7 @@ static int usb_host_handle_data(USBDevice *dev, USBPacket *p)
                 return USB_RET_STALL;
             }
         }
-    }
+    } while (rem > 0);
 
     return USB_RET_ASYNC;
 }