From patchwork Fri Aug 3 03:17:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 10554517 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 247FC157D for ; Fri, 3 Aug 2018 03:17:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02B742C08D for ; Fri, 3 Aug 2018 03:17:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA2A02C08F; Fri, 3 Aug 2018 03:17:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67BDD2C08D for ; Fri, 3 Aug 2018 03:17:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726291AbeHCFLc (ORCPT ); Fri, 3 Aug 2018 01:11:32 -0400 Received: from smtprelay.synopsys.com ([198.182.60.111]:59377 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725773AbeHCFLc (ORCPT ); Fri, 3 Aug 2018 01:11:32 -0400 Received: from mailhost.synopsys.com (mailhost3.synopsys.com [10.12.238.238]) by smtprelay.synopsys.com (Postfix) with ESMTP id 7853210C08CC; Thu, 2 Aug 2018 20:17:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1533266241; bh=kK9eNYv9rzQ2BduKdy1cjaHZ8un/vFOTGOLMmgFc70s=; h=Date:From:Subject:To:CC:From; b=Lvw6CwtXI9PRjpzo//PLKcjdNfBIsiBGxLanGynt4krW3eWPLDQzRkj4TNRX4S1ym T0AYceV9xdDc+fVenxm8SsBoXsmzljBoMfD4iSJ8Go53sxenAozaEk7Xmk5Qupl8y8 X2z+Vgx/foR1DJNr06ZuOSDvhHt1K8zS6mlCVQzY07csBJbeabZGtonFS3plduIIHn qJR1sBzH+K5D9Z63FEjFcg+9i0hRQaduEiOxWiZdJyN+KxWVSlV0HkwJTbgB+yjpVz +S/THj/QgGKoqq8yd+AW//DcehM5l4l8RhW8mg5Cf/4QOCC9cxqkZfVVZHt34yZH1L rMLqYqYQZXpxQ== Received: from US01WEHTC3.internal.synopsys.com (us01wehtc3.internal.synopsys.com [10.15.84.232]) by mailhost.synopsys.com (Postfix) with ESMTP id 61E58325B; Thu, 2 Aug 2018 20:17:21 -0700 (PDT) Received: from US01WEHTC2.internal.synopsys.com (10.12.239.237) by US01WEHTC3.internal.synopsys.com (10.15.84.232) with Microsoft SMTP Server (TLS) id 14.3.361.1; Thu, 2 Aug 2018 20:17:18 -0700 Received: from te-lab16 (10.13.184.19) by US01WEHTC2.internal.synopsys.com (10.12.239.238) with Microsoft SMTP Server (TLS) id 14.3.361.1; Thu, 2 Aug 2018 20:17:16 -0700 Received: by te-lab16 (sSMTP sendmail emulation); Thu, 02 Aug 2018 20:17:16 -0700 Date: Thu, 2 Aug 2018 20:17:16 -0700 Message-ID: From: Thinh Nguyen Subject: [PATCH] usb: dwc3: gadget: Properly check last unaligned/zero chain TRB To: Felipe Balbi , CC: John Youn , MIME-Version: 1.0 X-Originating-IP: [10.13.184.19] Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Current check for the last extra TRB for zero and unaligned transfers does not account for isoc OUT. The last TRB of the Buffer Descriptor for isoc OUT transfers will be retired with HWO=0. As a result, we won't return early. The req->remaining will be updated to include the BUFSIZ count of the extra TRB, and the actual number of transferred bytes calculation will be wrong. To fix this, check whether it's a short or zero packet and the last TRB chain bit to return early. Cc: stable@vger.kernel.org Fixes: c6267a51639b ("usb: dwc3: gadget: align transfers to wMaxPacketSize") Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 032ea7d709ba..c09e4f784810 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2251,7 +2251,7 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct dwc3_ep *dep, * with one TRB pending in the ring. We need to manually clear HWO bit * from that TRB. */ - if ((req->zero || req->unaligned) && (trb->ctrl & DWC3_TRB_CTRL_HWO)) { + if ((req->zero || req->unaligned) && !(trb->ctrl & DWC3_TRB_CTRL_CHN)) { trb->ctrl &= ~DWC3_TRB_CTRL_HWO; return 1; }