From patchwork Thu Sep 24 08:21:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11796539 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 83AC16CA for ; Thu, 24 Sep 2020 08:21:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5DA5023787 for ; Thu, 24 Sep 2020 08:21:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="Fk0qmA2S" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727235AbgIXIVT (ORCPT ); Thu, 24 Sep 2020 04:21:19 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:40338 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727089AbgIXIVT (ORCPT ); Thu, 24 Sep 2020 04:21:19 -0400 Received: from mailhost.synopsys.com (sv2-mailhost1.synopsys.com [10.205.2.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 7B0EB402DC; Thu, 24 Sep 2020 08:21:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1600935679; bh=xTLmBPtKTdMjcXU+24f4RxHnyGuBb7ByOH3+djITM4M=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=Fk0qmA2SI5H2OzeZtwg002JHWcNdwMadM0fT+6RKH2amYgVPvyFRHMZ9j2SEApSnh YZllRJBccU3KbHeinpcztCqjrBPY4WwpycGh8imhZ57sfq0mSSmjELIEOMrHlA/jmI d06NT0sC3C7sHN7DXei9XeMA2P90vVW741vfAwXte8h0Yw+2t6v+kbBrqsyLTFfgBf fZq92NPNsL60Sr5YDfB5j3ChZueOEUSuOcyq7EeF4hegDafqLf78uWZgbTm8cXdZNE 2pkTO2eqbHRSDqdhYCQWSpHHuEIz/j2yI5CAaPDEKJb7QObCvOY9FrYWqAltVz0B8G 3HCvZKhKGzKtg== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id 63D1EA0096; Thu, 24 Sep 2020 08:21:18 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Thu, 24 Sep 2020 01:21:18 -0700 Date: Thu, 24 Sep 2020 01:21:18 -0700 Message-Id: <290cbf2ba0fee13ba37cf934bf413795d4bd9a04.1600935293.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 01/10] usb: dwc3: gadget: Check MPS of the request length To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org Cc: John Youn , stable@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org When preparing for SG, not all the entries are prepared at once. When resume, don't use the remaining request length to calculate for MPS alignment. Use the entire request->length to do that. Cc: stable@vger.kernel.org Fixes: 5d187c0454ef ("usb: dwc3: gadget: Don't setup more than requested") Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index cb19d682bbac..44351078f833 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1098,6 +1098,8 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, struct scatterlist *s; int i; unsigned int length = req->request.length; + unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc); + unsigned int rem = length % maxp; unsigned int remaining = req->request.num_mapped_sgs - req->num_queued_sgs; @@ -1109,8 +1111,6 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, length -= sg_dma_len(s); for_each_sg(sg, s, remaining, i) { - unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc); - unsigned int rem = length % maxp; unsigned int trb_length; unsigned int chain = true;