From patchwork Tue Nov 3 20:36:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 316903 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5A89C388F7 for ; Tue, 3 Nov 2020 21:31:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B61E21534 for ; Tue, 3 Nov 2020 21:31:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604439070; bh=71ZehZ3+PO2T+WEyXk27DSKW9Y8mJr4AEfNFxJE53Ak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ing1Rtu5N1vVe7prT+aJ0DTrtWBfVn1drfzatzs/hzEp9LLU6QHVXRqdyNpEvFsgB kCa7fbucRMZBT9+8KWIkged4nNj0muiF1rT7oDDwe8Rw8ASEBOKOoqNtjcSW1pWV0+ gWNaqBGtds1EeYINRA3m+DYVPlOL6sHQmR6f/gqQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731935AbgKCVao (ORCPT ); Tue, 3 Nov 2020 16:30:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:60510 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731057AbgKCU55 (ORCPT ); Tue, 3 Nov 2020 15:57:57 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 52A0B22226; Tue, 3 Nov 2020 20:57:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437076; bh=71ZehZ3+PO2T+WEyXk27DSKW9Y8mJr4AEfNFxJE53Ak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AGvc9otgtd8sBVIBZjUykw1J5I0oIZhU/yroxTzqLL4KlOe2ObrtzzpFsNW7OlTVb KhnTBNIdWd2cLmqDvXEaqZhRBo0/mJRsZjezYmGcPAlGEwJtlDh0xa8f04BcTtj2Os HBIe7OT/OIpr3bAoyfqXL08HcWqOzd2Q/pxW7Fdw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thinh Nguyen , Felipe Balbi Subject: [PATCH 5.4 136/214] usb: dwc3: gadget: Check MPS of the request length Date: Tue, 3 Nov 2020 21:36:24 +0100 Message-Id: <20201103203303.582071131@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203249.448706377@linuxfoundation.org> References: <20201103203249.448706377@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Thinh Nguyen commit ca3df3468eec87f6374662f7de425bc44c3810c1 upstream. 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 Signed-off-by: Felipe Balbi Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/gadget.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1057,6 +1057,8 @@ static void dwc3_prepare_one_trb_sg(stru 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; @@ -1068,8 +1070,6 @@ static void dwc3_prepare_one_trb_sg(stru 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 chain = true;