Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1586022ybv; Thu, 20 Feb 2020 23:47:14 -0800 (PST) X-Google-Smtp-Source: APXvYqyMUSIwo8ukuvaYLYa/5+02GUYEzOGC464jvu8BOZ/bhVELN4LhzBijrEUaob89a0x2UiQT X-Received: by 2002:aca:3857:: with SMTP id f84mr872947oia.150.1582271234520; Thu, 20 Feb 2020 23:47:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582271234; cv=none; d=google.com; s=arc-20160816; b=V0tLWqec4W0uOdKFOv/FA6NGCL5ehskbyw0N3fX0bXIWRxNFBNjWDcG08IOuxZFkAD mx1b9fCkugGVNW4cOZQjCizohCpO/Demyzr9/ic6xrtDRHJkdl+LCcFrKP9MGgPikwKD SrT4S/c5zLtgmclEJ9205enZa4/6NjyMS2jol3qX+xQYgla3QO0XXjUqyXZMSa8I/FBP kbdi+NE/cLPdfnGYHDoVYQ4m8H4KBEfYc+NrFDwL9rq9DlIECyDyl/oymQWBqaGyPW0d J9xxfG7QIUTlkav1KsxvKhRqePez0S1stoFD/OLUcB7ZVqAgK7Xt7MX11O212MJPyn1B K5IA== 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=CAovDj7tLg8OysL6X6JPMRrdVU8C1RDOUKDD3KgkPFY=; b=J2T1cDQtpSYgUCryNFv4bQZsrd/OIh2xQPNcHLm5PUaN5fbMEt2WVFVDER0lDvYhVX UwwKzj2iKztdkbmmvhMNk5Ou+VW9Y4LjJkRT9ah89tBqillSjMOURzmLnzhZb+bE+DSO jCEfMup8SLW+6lTnhkvvAc3Uq4/j8kPp0diyIfDfPDN+ELthVfSWVdTf0hwUrC7iyhf+ po1b4xK3MXc0b97ZLagHDmK1NC9zVQ1vG6kn6Abu6TX0JyZYC8AeaMkb/MnlAPFDrUim DcHwPZ9UYmxX/5LVaErRa6ot3BOCye/TW0p4o6jMC5miU93YEDUW5/Vyi6IoykSGDYC+ AnKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="GBPC6s/P"; 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 n2si1055106otq.315.2020.02.20.23.47.02; Thu, 20 Feb 2020 23:47:14 -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="GBPC6s/P"; 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 S1728672AbgBUHqU (ORCPT + 99 others); Fri, 21 Feb 2020 02:46:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:41740 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728662AbgBUHqS (ORCPT ); Fri, 21 Feb 2020 02:46:18 -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 A7FB020801; Fri, 21 Feb 2020 07:46:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582271178; bh=zbK5P6bE+5w9JpZDIVeW4d4YCT86HCfVE6Z0vyzn7KM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GBPC6s/PIarHS1sGBCKArLxlctKAI8CbzGjVOo4hU/Ew313TfFBN0fHYhR++s75ic S+oLZLT0EmNX15FNd4KVJP7u1bUJQhQsAfn/Gg1djOs0tQdaA592oHJceg1ybcZetB HLyGLiAgen0kqr7J3N/2qP7H9pY9fTK+JgdS3QHc= 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 5.5 067/399] usb: dwc2: Fix IN FIFO allocation Date: Fri, 21 Feb 2020 08:36:32 +0100 Message-Id: <20200221072408.874502323@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072402.315346745@linuxfoundation.org> References: <20200221072402.315346745@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 6be10e496e105..a9133773b89e4 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -4056,11 +4056,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