From patchwork Thu Dec 8 06:36:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mars.cao" X-Patchwork-Id: 130100 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 305CE1007D1 for ; Thu, 8 Dec 2011 17:37:04 +1100 (EST) Received: from localhost ([::1]:46788 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYXbD-0006Zg-RL for incoming@patchwork.ozlabs.org; Thu, 08 Dec 2011 01:36:55 -0500 Received: from eggs.gnu.org ([140.186.70.92]:36387) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYXb7-0006ZV-8C for qemu-devel@nongnu.org; Thu, 08 Dec 2011 01:36:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RYXb6-0003ah-58 for qemu-devel@nongnu.org; Thu, 08 Dec 2011 01:36:49 -0500 Received: from e23smtp09.au.ibm.com ([202.81.31.142]:46651) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYXb5-0003Zu-GH for qemu-devel@nongnu.org; Thu, 08 Dec 2011 01:36:48 -0500 Received: from /spool/local by e23smtp09.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 8 Dec 2011 07:29:58 +1000 Received: from d23relay03.au.ibm.com ([202.81.31.245]) by e23smtp09.au.ibm.com ([202.81.31.206]) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 8 Dec 2011 07:29:56 +1000 Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pB86aGc63723462 for ; Thu, 8 Dec 2011 17:36:19 +1100 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pB86aG1v016497 for ; Thu, 8 Dec 2011 17:36:16 +1100 Received: from oc2115466153.ibm.com ([9.115.122.76]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id pB86aEii016424; Thu, 8 Dec 2011 17:36:15 +1100 From: "Cao,Bing Bu" To: qemu-devel@nongnu.org Date: Thu, 8 Dec 2011 14:36:15 +0800 Message-Id: <1323326175-25184-1-git-send-email-mars@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 x-cbid: 11120721-3568-0000-0000-000000DBFF46 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 202.81.31.142 Cc: "Cao,Bing Bu" , kraxel@redhat.com Subject: [Qemu-devel] [PATCH] 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 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 | 20 ++++++++++++-------- 1 files changed, 12 insertions(+), 8 deletions(-) diff --git a/usb-linux.c b/usb-linux.c index ab4c693..a53b558 100644 --- a/usb-linux.c +++ b/usb-linux.c @@ -1141,15 +1141,19 @@ 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) { + fprintf(stderr, "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)) {