Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2394816imu; Thu, 10 Jan 2019 13:27:12 -0800 (PST) X-Google-Smtp-Source: ALg8bN5KRgb4lUx9NefoebGxeZ3JEYGr+aRLcQMhB66Th2q6Jkeu/vBCgBvWXDRNB0glE0sHQnev X-Received: by 2002:a63:314d:: with SMTP id x74mr10798278pgx.10.1547155632687; Thu, 10 Jan 2019 13:27:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547155632; cv=none; d=google.com; s=arc-20160816; b=JnZMGJpxZVc6Im9MOGK8KLxRrk81iiSaxyqiImIxRtP3mNnMZH8kYbJQSLgj31JLSE 8p/xhxhmW0RLbB10LJ+Uc/f8/j5nCWklzbH7nSQGN0xdqKMqOB5a/1ULQ3iyzF1dJVc9 QxJgDqootGrISAfRZvL8A82at27maUX0HPs7jOFGXMhN1xxTkE9T9IPa07CRxGI4KAn8 YOgdINRHXVbLVVfACuVg3pX3M2wBI7OOcw49XnfuMDmMIdkk2rGLVPsKiMLbt8ic0YPz H2tXA0cKRE5f2SgJMN+xbecdsQKWtYU0kRi3oFEixlZ9YpxTQu4X8xdewQKgbcn39iLM y6Zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature:dkim-signature; bh=u4T8zFO0appxwr4ya5HJQyz96vezX1szlwWSxVBuNT0=; b=LEvoVWZ4lR21fGjp4tMMIP6rYzmB32fnMau0vcsqcC+tpoOwFGPYYV2BrwP8rHro4H 1gvBKM97AY8jpTIpgJhlPJZBja3/tgG8mcMgntYv2xIIXWKLfnIQLuC6W88N6asxrE20 fNdeOeFuHLpAltlDa4LhlEDTbLvjkqgSXke5R6dabs88Qox85P1DM+gFud/YX2DWsY2U HOrs+s1yZZn7qjWfRjdYbxmDSnn/HmF87PTtNtJLQijuV7oNs6CwnuJfR0XRqh2VVXEK DeR/ttxN7GYvV29CtuwKiOL+35SdE75zWLupOXiwXy3vpy1++Mhp4a2GQzltpgE/TTqM wrPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=Xo7zfHVB; dkim=pass header.i=@codeaurora.org header.s=default header.b=UVhDHMh0; 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 k33si8407001pgb.424.2019.01.10.13.26.56; Thu, 10 Jan 2019 13:27:12 -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=@codeaurora.org header.s=default header.b=Xo7zfHVB; dkim=pass header.i=@codeaurora.org header.s=default header.b=UVhDHMh0; 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 S1730472AbfAJUkP (ORCPT + 99 others); Thu, 10 Jan 2019 15:40:15 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:41170 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730219AbfAJUkP (ORCPT ); Thu, 10 Jan 2019 15:40:15 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 5F7346055A; Thu, 10 Jan 2019 20:40:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1547152814; bh=xMnvTGCTdIG4CkZNAHo7OB4PW/yqZ15fzZRJSuiKI1k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xo7zfHVBADe1TLeeyK5WjrI6z4PJwnmZN8dLNTifKKIB6JM3ZuFCCfDi+hSphDaDb mQSKP3czQ8PI9aMBqpNbFo+otKJkGpMfwNe12NTT1W5E6W0ds5cTbttspPuYjPnkpz AtVxU7y7r6bpCq/Z8a3QamWD47EIoqtcU3OK4iTo= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.0 Received: from jackp-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: jackp@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 514C5601B4; Thu, 10 Jan 2019 20:40:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1547152813; bh=xMnvTGCTdIG4CkZNAHo7OB4PW/yqZ15fzZRJSuiKI1k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UVhDHMh02RAFxnvRqUET7CZg1FY1M+rm3YwpndchAkr7uhGDseuy4AdCahZ0Wso+R JzEYED6efi98zjhEkaj1KSYuJRoBdtFjVn3yhBrWBey+cneKBEnwiKM5OLEr/l3rvU SUv9LCBfndQRahMUCjmtLWAb0CO6RPLdJKgIaig8= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 514C5601B4 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=jackp@codeaurora.org From: Jack Pham To: Felipe Balbi Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Jack Pham , stable@vger.kernel.org Subject: [PATCH v2] usb: dwc3: gadget: Clear req->needs_extra_trb flag on cleanup Date: Thu, 10 Jan 2019 12:39:55 -0800 Message-Id: <20190110203955.10724-1-jackp@codeaurora.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <87pnt5c53o.fsf@linux.intel.com> References: <87pnt5c53o.fsf@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org OUT endpoint requests may somtimes have this flag set when preparing to be submitted to HW indicating that there is an additional TRB chained to the request for alignment purposes. If that request is removed before the controller can execute the transfer (e.g. ep_dequeue/ep_disable), the request will not go through the dwc3_gadget_ep_cleanup_completed_request() handler and will not have its needs_extra_trb flag cleared when dwc3_gadget_giveback() is called. This same request could be later requeued for a new transfer that does not require an extra TRB and if it is successfully completed, the cleanup and TRB reclamation will incorrectly process the additional TRB which belongs to the next request, and incorrectly advances the TRB dequeue pointer, thereby messing up calculation of the next requeust's actual/remaining count when it completes. The right thing to do here is to ensure that the flag is cleared before it is given back to the function driver. A good place to do that is in dwc3_gadget_del_and_unmap_request(). Fixes: c6267a51639b ("usb: dwc3: gadget: align transfers to wMaxPacketSize") Cc: stable@vger.kernel.org Signed-off-by: Jack Pham --- v2: Added Fixes tag and Cc: stable Felipe, as I mentioned in the cover for v1, for stable (from 4.11 where c6267a51639b first landed through 4.20), the fix needs to be modified to assign to the separate req->unaligned and req->zero flags in lieu of needs_extra_trb which appeared in 5.0-rc1 in: commit 1a22ec643580626f439c8583edafdcc73798f2fb Author: Felipe Balbi Date: Wed Aug 1 13:15:05 2018 +0300 usb: dwc3: gadget: combine unaligned and zero flags Do I need to send a separate patch for <= 4.20 or will you handle it? It's straightforward really, the code change should instead be + req->unaligned = false; + req->zero = false; Thanks, Jack drivers/usb/dwc3/gadget.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 2ecde30ad0b7..e97b14f444c8 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -177,6 +177,7 @@ static void dwc3_gadget_del_and_unmap_request(struct dwc3_ep *dep, req->started = false; list_del(&req->list); req->remaining = 0; + req->needs_extra_trb = false; if (req->request.status == -EINPROGRESS) req->request.status = status; -- The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project