From a03c7fb0c711ef8c519dca62580884a8b60cb388 Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Sat, 31 Mar 2012 15:49:26 +0200
Subject: [PATCH 1/8] usb-redir: An interface count of 0 is a valid value
 (rhbz#808760)

RH-Author: Hans de Goede <hdegoede@redhat.com>
Message-id: <1333208966-13669-1-git-send-email-hdegoede@redhat.com>
Patchwork-id: 39062
O-Subject: [RHEL-6.3 qemu-kvm PATCH] usb-redir: An interface count of 0 is a valid value (rhbz#808760)
Bugzilla: 808760
RH-Acked-by: Alon Levy <alevy@redhat.com>
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
RH-Acked-by: Uri Lublin <uril@redhat.com>

An interface-count of 0 happens when a device is in unconfigured state when
it gets redirected. So we should not use 0 to detect not having received
interface info from our peer.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Upstream: http://patchwork.ozlabs.org/patch/149836/
---
 usb-redir.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Signed-off-by: Michal Novotny <mignov@gmail.com>
---
 usb-redir.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/usb-redir.c b/usb-redir.c
index 8349416..f19c374 100644
--- a/usb-redir.c
+++ b/usb-redir.c
@@ -39,6 +39,7 @@
 #include "hw/usb.h"
 
 #define MAX_ENDPOINTS 32
+#define NO_INTERFACE_INFO 255 /* Valid interface_count always <= 32 */
 #define EP2I(ep_address) (((ep_address & 0x80) >> 3) | (ep_address & 0x0f))
 #define I2EP(i) (((i & 0x10) << 3) | (i & 0x0f))
 
@@ -984,7 +985,7 @@ static void usbredir_handle_destroy(USBDevice *udev)
 
 static int usbredir_check_filter(USBRedirDevice *dev)
 {
-    if (dev->interface_info.interface_count == 0) {
+    if (dev->interface_info.interface_count == NO_INTERFACE_INFO) {
         ERROR("No interface info for device\n");
         goto error;
     }
@@ -1148,7 +1149,7 @@ static void usbredir_device_disconnect(void *priv)
     for (i = 0; i < MAX_ENDPOINTS; i++) {
         QTAILQ_INIT(&dev->endpoint[i].bufpq);
     }
-    dev->interface_info.interface_count = 0;
+    dev->interface_info.interface_count = NO_INTERFACE_INFO;
 }
 
 static void usbredir_interface_info(void *priv,
-- 
1.7.7.6

