From patchwork Tue Dec 13 01:22:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mars.cao" X-Patchwork-Id: 130963 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C4C781007D3 for ; Tue, 13 Dec 2011 12:22:53 +1100 (EST) Received: from localhost ([::1]:41436 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaH4z-00061I-VL for incoming@patchwork.ozlabs.org; Mon, 12 Dec 2011 20:22:49 -0500 Received: from eggs.gnu.org ([140.186.70.92]:57723) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaH4u-0005x5-Ju for qemu-devel@nongnu.org; Mon, 12 Dec 2011 20:22:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RaH4t-0004ND-Ey for qemu-devel@nongnu.org; Mon, 12 Dec 2011 20:22:44 -0500 Received: from e28smtp01.in.ibm.com ([122.248.162.1]:60549) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaH4s-0004M9-Rr for qemu-devel@nongnu.org; Mon, 12 Dec 2011 20:22:43 -0500 Received: from /spool/local by e28smtp01.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 13 Dec 2011 06:52:35 +0530 Received: from d28relay05.in.ibm.com (9.184.220.62) by e28smtp01.in.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 13 Dec 2011 06:52:31 +0530 Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay05.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pBD1MUQl1732836 for ; Tue, 13 Dec 2011 06:52:30 +0530 Received: from d28av02.in.ibm.com (loopback [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pBD1MT7O016184 for ; Tue, 13 Dec 2011 12:22:29 +1100 Received: from oc2115466153.ibm.com ([9.115.122.76]) by d28av02.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id pBD1MSod016129; Tue, 13 Dec 2011 12:22:28 +1100 From: mars@linux.vnet.ibm.com To: qemu-devel@nongnu.org Date: Tue, 13 Dec 2011 09:22:20 +0800 Message-Id: <1323739340-11364-1-git-send-email-mars@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 x-cbid: 11121301-4790-0000-0000-00000061675A X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 122.248.162.1 Cc: mars@linux.vnet.ibm.com, kraxel@redhat.com Subject: [Qemu-devel] [PATCH V2] Fix parse of usb device description with multiple configurations X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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)) {