From patchwork Mon Dec 10 07:23:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejas Joglekar X-Patchwork-Id: 10720687 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 E57E5112E for ; Mon, 10 Dec 2018 07:23:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C21D528515 for ; Mon, 10 Dec 2018 07:23:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B5B4F2857D; Mon, 10 Dec 2018 07:23:57 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 3EFF128515 for ; Mon, 10 Dec 2018 07:23:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726032AbeLJHX4 (ORCPT ); Mon, 10 Dec 2018 02:23:56 -0500 Received: from us01smtprelay-2.synopsys.com ([198.182.60.111]:53878 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726029AbeLJHX4 (ORCPT ); Mon, 10 Dec 2018 02:23:56 -0500 Received: from mailhost.synopsys.com (mailhost2.synopsys.com [10.13.184.66]) by smtprelay.synopsys.com (Postfix) with ESMTP id 6482B10C0726; Sun, 9 Dec 2018 23:23:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1544426636; bh=BKA61KPVAY8baO4RGz9ZUqiq4RjmUF1G3IeCUTYbXEM=; h=Date:From:Subject:To:CC:From; b=JdhQFKdJQbCnbCTeKBH+qehK+iOaDft1CmJwr9PTu1ztX0KeXo+EJpJFDeJ84uz3a qdF6BXTEdCitIGpBV2Np6LCFlsgE75PUREWENIzzZSChDpfBlwbBdmZTl/N4NZgUnS QONEmr4KR6QUNIL0wzoIA7bxON1cMxysaa1wbL0QkOq0+d6q2ge+5mCjUE9d201xVC FNUzV/qXIYxx1Hh71df4EBA4IQqzT5JSmWhMN2RX08Ph26c31+NAw9SKsaaa02k9Ph KwgsScxX0LrNenIn7LOGlr8KO94w2XSK6xLEYbDRmTuExX2MZQkHc58HhJbm1MfEnd sPxUY5w2BiGPA== Received: from US01WEHTC2.internal.synopsys.com (us01wehtc2.internal.synopsys.com [10.12.239.237]) by mailhost.synopsys.com (Postfix) with ESMTP id 57A353644; Sun, 9 Dec 2018 23:23:56 -0800 (PST) Received: from US01WEHTC1.internal.synopsys.com (10.12.239.236) by US01WEHTC2.internal.synopsys.com (10.12.239.237) with Microsoft SMTP Server (TLS) id 14.3.408.0; Sun, 9 Dec 2018 23:23:56 -0800 Received: from tejas-VirtualBox (10.145.66.15) by us01wehtc1.internal.synopsys.com (10.12.239.231) with Microsoft SMTP Server (TLS) id 14.3.408.0; Sun, 9 Dec 2018 23:23:54 -0800 Received: by tejas-VirtualBox (sSMTP sendmail emulation); Mon, 10 Dec 2018 12:53:48 +0530 Date: Mon, 10 Dec 2018 12:53:48 +0530 From: Tejas Joglekar Subject: [PATCH] usb: dwc3: gadget: Handle 0 xfer length for OUT EP To: Felipe Balbi , CC: John Youn , Tejas Joglekar , MIME-Version: 1.0 Message-ID: X-Originating-IP: [10.145.66.15] 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 For OUT endpoints, zero-length transfers require MaxPacketSize buffer as per the DWC_usb3 programming guide 3.30a section 4.2.3.3. This patch fixes this by explicitly checking zero length transfer to correctly pad up to MaxPacketSize. Signed-off-by: Tejas Joglekar --- drivers/usb/dwc3/gadget.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index e2caf9e..f1089ec 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1069,7 +1069,8 @@ static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, if (sg_is_last(s)) chain = false; - if (rem && usb_endpoint_dir_out(dep->endpoint.desc) && !chain) { + if ((!length || rem) && usb_endpoint_dir_out(dep->endpoint.desc) + && !chain) { struct dwc3 *dwc = dep->dwc; struct dwc3_trb *trb; @@ -1114,7 +1115,7 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc); unsigned int rem = length % maxp; - if (rem && usb_endpoint_dir_out(dep->endpoint.desc)) { + if ((!length || rem) && usb_endpoint_dir_out(dep->endpoint.desc)) { struct dwc3 *dwc = dep->dwc; struct dwc3_trb *trb;