Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3879082pxb; Tue, 17 Nov 2020 06:04:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJwjjKsdtFd9qEut30WtKW7TytiWPGOT2/yJJXmtnQV9EILGGnmOIfG75zux+FJrB0zfvMIz X-Received: by 2002:a17:906:e96:: with SMTP id p22mr2073877ejf.451.1605621870212; Tue, 17 Nov 2020 06:04:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605621870; cv=none; d=google.com; s=arc-20160816; b=CFlBZCe5ZC2ahDewEP0V/EAFndb6IfHb77qXJbDkRKkyTCsC3cmFDYMw+A+IMTKQVD lLiFku/SFuX0oegupcLT9GEq6gZGLomI9uKYmF6Dv/HkteoTjgRgGYgqxzWxNVlfEMGs rOFM0x0O48ITp1RlT2NVRP2N+FJKb4Zh0uZN5z91rUc8lY/xY56CuPqfovIxS/kjH+XE p33Eq7AiA66/oAcEuM0nZg0RfGiTAQts+VuRAUx0pKt+RnDz0UBtfGR0eSjVw1EHYhjW jhBY1OpjXA/awNCrNPd+RCM1fjBbtDA9S7Bc5lcYeuFdwo/wp/Wf3aS2rhL7ySCCv5Xo 0f1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UT0Pv7K3KfFp1srhDjT/mkh7r6MGQhRMM5Fn+hHxPT0=; b=rlF0VjUEMVJZ+HATJXROkVhq4SPaeEisIQc2jgvWf2V5MGCjsLGDv+hzNorteVckbo KwQ/ypCuWN+fghP94fW8RAU00xcB5ZPTTPUqj/3Qn2DhaV9/zs8xAkZmrLu1l94L51ha QGuD0jfpdWWQzacc1bXF9Z/d5R3JK2JGCvCF1T2vzP5uabPkuzCwrIOfIdq3Su29ueB5 MmYOVtbTC7sAp0QLkKbXKOcqAczk6G/pkfqxCEASTEmQTQijdMACCMpWRyg3MUT2b+IR DwCVw3cdA823oDEtW1qGiVAfw1c5LNQf0D+LM+Vvn32bEnepeBJBVo39iBsvRXAf4viT NtrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=O8n0D0qr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id wn12si4577164ejb.43.2020.11.17.06.04.01; Tue, 17 Nov 2020 06:04:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=O8n0D0qr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731366AbgKQN7p (ORCPT + 99 others); Tue, 17 Nov 2020 08:59:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:49840 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730529AbgKQNRh (ORCPT ); Tue, 17 Nov 2020 08:17:37 -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 BA716241A6; Tue, 17 Nov 2020 13:17:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605619055; bh=vpDr7mDvKW61P+5qPdz8cH995125ReCzW3VrE1uhgjA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O8n0D0qr8SQ/IC4MeDskOntTBC8EuOUn6IqaeS0km5R6gR+gm5wecSnpoF0C9izqM +t64pWywi+XaWgw8lohdxdx8qcFJfHbbuYeVBqGM58raxbtr6TwonGjUSmggPmixFD K6ZMqRJyCxVV8N1zYrw1RMo2jflrkvoST5feLQrU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thinh Nguyen , Felipe Balbi , Sasha Levin Subject: [PATCH 4.19 005/101] usb: dwc3: gadget: Reclaim extra TRBs after request completion Date: Tue, 17 Nov 2020 14:04:32 +0100 Message-Id: <20201117122113.380944173@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122113.128215851@linuxfoundation.org> References: <20201117122113.128215851@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thinh Nguyen [ Upstream commit 690e5c2dc29f8891fcfd30da67e0d5837c2c9df5 ] An SG request may be partially completed (due to no available TRBs). Don't reclaim extra TRBs and clear the needs_extra_trb flag until the request is fully completed. Otherwise, the driver will reclaim the wrong TRB. Cc: stable@vger.kernel.org Fixes: 1f512119a08c ("usb: dwc3: gadget: add remaining sg entries to ring") Signed-off-by: Thinh Nguyen Signed-off-by: Felipe Balbi Signed-off-by: Sasha Levin --- drivers/usb/dwc3/gadget.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index f24cfb3a6907b..6ab5c48f5d873 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2386,6 +2386,11 @@ static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep, ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event, status); + req->request.actual = req->request.length - req->remaining; + + if (!dwc3_gadget_ep_request_completed(req)) + goto out; + if (req->needs_extra_trb) { unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc); @@ -2401,11 +2406,6 @@ static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep, req->needs_extra_trb = false; } - req->request.actual = req->request.length - req->remaining; - - if (!dwc3_gadget_ep_request_completed(req)) - goto out; - dwc3_gadget_giveback(dep, req, status); out: -- 2.27.0