Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1614246ybv; Fri, 21 Feb 2020 00:18:45 -0800 (PST) X-Google-Smtp-Source: APXvYqzz5ZxSI2RBBSAFDccrCsV1Ef2dCjfmkSJHflbm7WdksorJp/MQeUQ1pkTXgZOzUuiVDs/i X-Received: by 2002:aca:1108:: with SMTP id 8mr990348oir.127.1582273124679; Fri, 21 Feb 2020 00:18:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582273124; cv=none; d=google.com; s=arc-20160816; b=W80QeyVx6nUTr1+2t3Vj2AKYLfzvsnRXh/180ZqwI4NxtZCJG892XjqSvbte+OMSfu OcrrqX65a1sSvsltdYg4nf6Cl/9/OFVkjfBV8jhHZzp4CYA/ME7KgfWzguZfKJtOs9yj xjc/wxj8ehCyo+atQfRbHmzmQfrCbBZGrPEPtCxNKWXaxGOqBLnjiKC91LdaToodPWzl WhCYLfkAcfH025lTIWbZZbqAxkkrCNnkOCt0lwgjtD9fcH/g5Cl5oji80wGiorJNrG6K m4bcVWKS5JFG1Ojof5tJVM7t+Q3cll7NLjRyY0aQh9LgAhzDWriuCtdU4MAIP2OBAQD+ +BAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BdWhgLnOC10/0V3fwPPR4dj45XfHDrekREZ6BiUH+3w=; b=Z1D4PCOG9STz0143FxsvnxOdRQDCKX5AQw7KjKAMaTUDTNlf9QBUiCie4NOFbGhpQf 6NX1p4mYvqofMiUZe/lkgI2Zo+6juYMSydRtF8fBvPzmRP0SJVAsdfPQSLK9xkqJeEQG F3ifVo4AJw5BNBwWQv/eC7uKgHJIpflP+coMJb1aRboc4TIk3mejvadUswu/lJNr8zne oD8QjZ39/7D1vKLbCiNJuHOxVmnSJB74y4mx7ZUjRv4H63p41UQO836DpF0h0d/hR+1S r28lixWtDcI67hbPWVY6Abx/1svL5M9BbvrNqERhN4X1kh14GpYx74o5Zz0YgdZ4nB2j aDkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="V/ByoyDB"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v10si1032105ote.275.2020.02.21.00.18.32; Fri, 21 Feb 2020 00:18:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="V/ByoyDB"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387736AbgBUIRu (ORCPT + 99 others); Fri, 21 Feb 2020 03:17:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:55280 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387686AbgBUIRo (ORCPT ); Fri, 21 Feb 2020 03:17:44 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E910A24682; Fri, 21 Feb 2020 08:17:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582273063; bh=+vGHe3JDy9xNEfZk9K6/cvGaRyAsbbjFMd+oa+5LXM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V/ByoyDBbQx705PMrq1FXpW7m9fq+EA25d1/S7R7UryWYoRI09gUN6AClAsk8rmi2 5MujLVzZALKYO/gmzc4GGtqMcmSUxpGzc0w3wo9DqE/W9z2cIIwX57lzC4VxElToSt at+8Lx1C2/yQeLx0ajfDhpMXkmJ/USCiQnsao7lY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Minas Harutyunyan , John Keeping , Felipe Balbi , Sasha Levin Subject: [PATCH 4.19 033/191] usb: dwc2: Fix IN FIFO allocation Date: Fri, 21 Feb 2020 08:40:06 +0100 Message-Id: <20200221072255.360053745@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072250.732482588@linuxfoundation.org> References: <20200221072250.732482588@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: John Keeping [ Upstream commit 644139f8b64d818f6345351455f14471510879a5 ] On chips with fewer FIFOs than endpoints (for example RK3288 which has 9 endpoints, but only 6 which are cabable of input), the DPTXFSIZN registers above the FIFO count may return invalid values. With logging added on startup, I see: dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=1 sz=256 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=2 sz=128 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=3 sz=128 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=4 sz=64 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=5 sz=64 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=6 sz=32 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=7 sz=0 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=8 sz=0 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=9 sz=0 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=10 sz=0 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=11 sz=0 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=12 sz=0 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=13 sz=0 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=14 sz=0 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=15 sz=0 but: # cat /sys/kernel/debug/ff580000.usb/fifo Non-periodic FIFOs: RXFIFO: Size 275 NPTXFIFO: Size 16, Start 0x00000113 Periodic TXFIFOs: DPTXFIFO 1: Size 256, Start 0x00000123 DPTXFIFO 2: Size 128, Start 0x00000223 DPTXFIFO 3: Size 128, Start 0x000002a3 DPTXFIFO 4: Size 64, Start 0x00000323 DPTXFIFO 5: Size 64, Start 0x00000363 DPTXFIFO 6: Size 32, Start 0x000003a3 DPTXFIFO 7: Size 0, Start 0x000003e3 DPTXFIFO 8: Size 0, Start 0x000003a3 DPTXFIFO 9: Size 256, Start 0x00000123 so it seems that FIFO 9 is mirroring FIFO 1. Fix the allocation by using the FIFO count instead of the endpoint count when selecting a FIFO for an endpoint. Acked-by: Minas Harutyunyan Signed-off-by: John Keeping Signed-off-by: Felipe Balbi Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/dwc2/gadget.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index f64d1cd08fb67..17f3e7b4d4fed 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -3918,11 +3918,12 @@ static int dwc2_hsotg_ep_enable(struct usb_ep *ep, * a unique tx-fifo even if it is non-periodic. */ if (dir_in && hsotg->dedicated_fifos) { + unsigned fifo_count = dwc2_hsotg_tx_fifo_count(hsotg); u32 fifo_index = 0; u32 fifo_size = UINT_MAX; size = hs_ep->ep.maxpacket * hs_ep->mc; - for (i = 1; i < hsotg->num_of_eps; ++i) { + for (i = 1; i <= fifo_count; ++i) { if (hsotg->fifo_map & (1 << i)) continue; val = dwc2_readl(hsotg, DPTXFSIZN(i)); -- 2.20.1