From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:35706) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rj9Fo-0007rr-HG for qemu-devel@nongnu.org; Fri, 06 Jan 2012 07:50:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rj9Fl-0002r4-Vu for qemu-devel@nongnu.org; Fri, 06 Jan 2012 07:50:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34004) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rj9Fl-0002qr-MY for qemu-devel@nongnu.org; Fri, 06 Jan 2012 07:50:37 -0500 From: Gerd Hoffmann Date: Fri, 6 Jan 2012 13:50:29 +0100 Message-Id: <1325854232-17478-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1325854232-17478-1-git-send-email-kraxel@redhat.com> References: <1325854232-17478-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH 1/4] Fix parse of usb device description with multiple configurations List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: "Cao, Bing Bu" , Gerd Hoffmann From: Cao,Bing Bu Changed From V1: Use DPRINTF instead of fprintf,because it is not an error. When testing ipod on QEMU by He Jie Xu,qemu made a assertion. We found that the ipod with 2 configurations,and the usb-linux did not parse the descriptor correctly. The descr_len returned is the total length of the all configurations,not one configuration. The older version will through the other configurations instead of skip,continue parsing the descriptor of interfaces/endpoints in other configurations,then went wrong. This patch will put the configuration descriptor parse in loop outside and dispel the other configurations not requested. Signed-off-by: Cao,Bing Bu Signed-off-by: Gerd Hoffmann --- usb-linux.c | 19 +++++++++++-------- 1 files changed, 11 insertions(+), 8 deletions(-) diff --git a/usb-linux.c b/usb-linux.c index ab4c693..ed14bb1 100644 --- a/usb-linux.c +++ b/usb-linux.c @@ -1141,15 +1141,18 @@ static int usb_linux_update_endp_table(USBHostDevice *s) length = s->descr_len - 18; i = 0; - if (descriptors[i + 1] != USB_DT_CONFIG || - descriptors[i + 5] != s->configuration) { - fprintf(stderr, "invalid descriptor data - configuration %d\n", - s->configuration); - return 1; - } - i += descriptors[i]; - while (i < length) { + if (descriptors[i + 1] != USB_DT_CONFIG) { + fprintf(stderr, "invalid descriptor data\n"); + return 1; + } else if (descriptors[i + 5] != s->configuration) { + DPRINTF("not requested configuration %d\n", s->configuration); + i += (descriptors[i + 3] << 8) + descriptors[i + 2]; + continue; + } + + i += descriptors[i]; + if (descriptors[i + 1] != USB_DT_INTERFACE || (descriptors[i + 1] == USB_DT_INTERFACE && descriptors[i + 4] == 0)) { -- 1.7.1