45e84a0
From 9b81fbdbb0cc930aacec343c6ab37adfd60c9e76 Mon Sep 17 00:00:00 2001
45e84a0
From: "Cao,Bing Bu" <mars@linux.vnet.ibm.com>
45e84a0
Date: Tue, 13 Dec 2011 09:22:20 +0800
45e84a0
Subject: [PATCH 15/25] Fix parse of usb device description with multiple
45e84a0
 configurations
45e84a0
45e84a0
Changed From V1:
45e84a0
Use DPRINTF instead of fprintf,because it is not an error.
45e84a0
45e84a0
When testing ipod on QEMU by He Jie Xu<xuhj@linux.vnet.ibm.com>,qemu made a assertion.
45e84a0
We found that the ipod with 2 configurations,and the usb-linux did not parse the descriptor correctly.
45e84a0
The descr_len returned is the total length of the all configurations,not one configuration.
45e84a0
The older version will through the other configurations instead of skip,continue parsing the descriptor of interfaces/endpoints in other configurations,then went wrong.
45e84a0
45e84a0
This patch will put the configuration descriptor parse in loop outside and dispel the other configurations not requested.
45e84a0
45e84a0
Signed-off-by: Cao,Bing Bu <mars@linux.vnet.ibm.com>
45e84a0
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
45e84a0
---
45e84a0
 usb-linux.c |   19 +++++++++++--------
45e84a0
 1 files changed, 11 insertions(+), 8 deletions(-)
45e84a0
45e84a0
diff --git a/usb-linux.c b/usb-linux.c
45e84a0
index ab4c693..ed14bb1 100644
45e84a0
--- a/usb-linux.c
45e84a0
+++ b/usb-linux.c
45e84a0
@@ -1141,15 +1141,18 @@ static int usb_linux_update_endp_table(USBHostDevice *s)
45e84a0
     length = s->descr_len - 18;
45e84a0
     i = 0;
45e84a0
45e84a0
-    if (descriptors[i + 1] != USB_DT_CONFIG ||
45e84a0
-        descriptors[i + 5] != s->configuration) {
45e84a0
-        fprintf(stderr, "invalid descriptor data - configuration %d\n",
45e84a0
-                s->configuration);
45e84a0
-        return 1;
45e84a0
-    }
45e84a0
-    i += descriptors[i];
45e84a0
-
45e84a0
     while (i < length) {
45e84a0
+        if (descriptors[i + 1] != USB_DT_CONFIG) {
45e84a0
+            fprintf(stderr, "invalid descriptor data\n");
45e84a0
+            return 1;
45e84a0
+        } else if (descriptors[i + 5] != s->configuration) {
45e84a0
+            DPRINTF("not requested configuration %d\n", s->configuration);
45e84a0
+            i += (descriptors[i + 3] << 8) + descriptors[i + 2];
45e84a0
+            continue;
45e84a0
+        }
45e84a0
+
45e84a0
+        i += descriptors[i];
45e84a0
+
45e84a0
         if (descriptors[i + 1] != USB_DT_INTERFACE ||
45e84a0
             (descriptors[i + 1] == USB_DT_INTERFACE &&
45e84a0
              descriptors[i + 4] == 0)) {
45e84a0
-- 
45e84a0
1.7.7.5
45e84a0