From patchwork Sun Mar 29 10:28:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Kocialkowski X-Patchwork-Id: 455744 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id F146B1400B6 for ; Sun, 29 Mar 2015 21:29:02 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 24BB4A749F; Sun, 29 Mar 2015 12:28:54 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oLJlHVjebQpt; Sun, 29 Mar 2015 12:28:54 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id AD862A74AF; Sun, 29 Mar 2015 12:28:50 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D98D9A7456 for ; Sun, 29 Mar 2015 12:28:42 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id U-kkw7pPKF60 for ; Sun, 29 Mar 2015 12:28:42 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from gagarine.paulk.fr (gagarine.paulk.fr [109.190.93.129]) by theia.denx.de (Postfix) with ESMTPS id 84F534B6CD for ; Sun, 29 Mar 2015 12:28:41 +0200 (CEST) Received: by gagarine.paulk.fr (Postfix, from userid 65534) id C03722040A; Sun, 29 Mar 2015 12:28:40 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on gagarine.paulk.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from armstrong.paulk.fr (armstrong.paulk.fr [82.233.88.171]) by gagarine.paulk.fr (Postfix) with ESMTPS id 81DB320581; Sun, 29 Mar 2015 12:28:37 +0200 (CEST) Received: from localhost.localdomain (aldrin [192.168.0.128]) by armstrong.paulk.fr (Postfix) with ESMTP id BC6893762D; Sun, 29 Mar 2015 12:28:36 +0200 (CEST) From: Paul Kocialkowski To: u-boot@lists.denx.de Date: Sun, 29 Mar 2015 12:28:19 +0200 Message-Id: <1427624899-9537-3-git-send-email-contact@paulk.fr> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1427624899-9537-1-git-send-email-contact@paulk.fr> References: <1427624899-9537-1-git-send-email-contact@paulk.fr> Cc: Marek Vasut , Tom Rini Subject: [U-Boot] [PATCH v2 3/3] usb: Early failure when the first descriptor read fails or is invalid X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This may happen when using an USB1 device on a controller that only supports USB2 (e.g. EHCI). Reading the first descriptor will fail (read 0 byte), so we can abort the process at this point instead of failing later and wasting time. Signed-off-by: Paul Kocialkowski --- common/usb.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/common/usb.c b/common/usb.c index 67e2350..fb00c95 100644 --- a/common/usb.c +++ b/common/usb.c @@ -956,8 +956,8 @@ int usb_new_device(struct usb_device *dev) */ #ifndef CONFIG_USB_XHCI err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, 64); - if (err < 0) { - debug("usb_new_device: usb_get_descriptor() failed\n"); + if (err < sizeof(struct usb_device_descriptor)) { + printf("usb_new_device: usb_get_descriptor() failed\n"); return -1; } @@ -996,6 +996,9 @@ int usb_new_device(struct usb_device *dev) case 64: dev->maxpacketsize = PACKET_SIZE_64; break; + default: + printf("usb_new_device: invalid max packet size\n"); + return -1; } dev->devnum = addr;