From patchwork Tue Apr 17 01:17:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerry Zhang X-Patchwork-Id: 10344127 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 956ED60216 for ; Tue, 17 Apr 2018 01:18:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92153288FE for ; Tue, 17 Apr 2018 01:18:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 869F028915; Tue, 17 Apr 2018 01:18:16 +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_ADSP_CUSTOM_MED, 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 2D87B288FE for ; Tue, 17 Apr 2018 01:18:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751270AbeDQBSM (ORCPT ); Mon, 16 Apr 2018 21:18:12 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:34606 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751086AbeDQBSM (ORCPT ); Mon, 16 Apr 2018 21:18:12 -0400 Received: by mail-pl0-f66.google.com with SMTP id z12-v6so3565495plo.1 for ; Mon, 16 Apr 2018 18:18:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=X3XbBtmGPJ4so8Rn2qmYXmtUfq2ngbHJ24OAXyPLJ68=; b=GzWVZRVnUBS7zTU3ld5nyLibxSSakLJyYTylj7SDfDqpvB/gRBaQpkUeI2nd7pmpFj FigpUYWwnbbkjOI8ungifeuypFOMzenxjhrjTVYzLhVtdU2a1yd028EHH/vu4Ti454N2 KkJBTxoltXr81MQClK+WPlO2auWMSlqVNMYqpwGEvgbii8AqXxT0eigfnVc7UDHejugk 0mR7NbXVKbfrVJ5PsLuGIVFLJW3oCQpB+trqC/OkGJ2DT8ug/GblhpKPhSct4Iww7fce RnrmDGOhuo1/MBxnAZWuE4LCGT+wpBwSXmZJe9JGv1TyQM5FV6l+PM5A+CYQXpgohnYS eAQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=X3XbBtmGPJ4so8Rn2qmYXmtUfq2ngbHJ24OAXyPLJ68=; b=Peoh+U9f84HbJK/pjiilYw2FnKgA+Oee6sKJ9FiisYBJYs08jAFDQp6FMhhMWvS8Nh bOJs8endjiSuNmaeeW0aYkqVuM1SXti1K+zVDckGxKePGDXMJPm9viLlkfFfQRE+jJ/t ZQnP9CcO0HRm+1s2j850LKqPSAtVYVao5s9dkE9NjYLlxjh+fDTpb/pPRa5kGPN/tCOi MAlka77ooKNaG1VlnHoHvHvAORz3eEhIIai7nPw/UHDBOvncbDK9U0zyVYE3fo+uamYn BBqR2zMM0FpsGJacINwxMesjd9i5cCPQ/4QgMvLxYMVE3CVjsEfeDoCCX+2ZU7Ikd0+t 12og== X-Gm-Message-State: ALQs6tAKobqj4/hLstOvRGXmtqeG9jYwteGkgcmYjlEIMY8qLPQW5Xhn xPqInWNaqSaEStOFMeiunvqE7Q== X-Google-Smtp-Source: AIpwx4+YvAssxZDcy16UVMXgRvjhdehqfczvcvkkYoNXXuk82/lfJJMls4nazYZdekMY8QPggmzz3g== X-Received: by 2002:a17:902:529:: with SMTP id 38-v6mr102312plf.64.1523927891372; Mon, 16 Apr 2018 18:18:11 -0700 (PDT) Received: from zhangjerry.mtv.corp.google.com ([2620:0:1000:1611:ee20:2649:babf:1d14]) by smtp.gmail.com with ESMTPSA id x14sm12694919pgq.50.2018.04.16.18.18.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Apr 2018 18:18:10 -0700 (PDT) From: Jerry Zhang To: Felipe Balbi , Greg Kroah-Hartman , linux-usb@vger.kernel.org Cc: Michal Nazarewicz , Krzysztof Opasiak , Badhri Jagan Sridharan , Andrzej Pietrasiewicz , Lars-Peter Clausen , felixhaedicke@web.de, Jerry Zhang Subject: [PATCH 1/3] usb: gadget: f_fs: Only return delayed status when len is 0 Date: Mon, 16 Apr 2018 18:17:40 -0700 Message-Id: <20180417011742.192184-2-zhangjerry@google.com> X-Mailer: git-send-email 2.17.0.484.g0c8726318c-goog In-Reply-To: <20180417011742.192184-1-zhangjerry@google.com> References: <20180417011742.192184-1-zhangjerry@google.com> 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 Commit 1b9ba000 ("Allow function drivers to pause control transfers") states that USB_GADGET_DELAYED_STATUS is only supported if data phase is 0 bytes. It seems that when the length is not 0 bytes, there is no need to explicitly delay the data stage since the transfer is not completed until the user responds. However, when the length is 0, there is no data stage and the transfer is finished once setup() returns, hence there is a need to explicitly delay completion. This manifests as the following bugs: Prior to 946ef68ad4e4 ('Let setup() return USB_GADGET_DELAYED_STATUS'), when setup is 0 bytes, ffs would require user to queue a 0 byte request in order to clear setup state. However, that 0 byte request was actually not needed and would hang and cause errors in other setup requests. After the above commit, 0 byte setups work since the gadget now accepts empty queues to ep0 to clear the delay, but all other setups hang. Fixes: 946ef68ad4e4 ("Let setup() return USB_GADGET_DELAYED_STATUS") Signed-off-by: Jerry Zhang --- drivers/usb/gadget/function/f_fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c index 7d5b1c448eb2..4b2cb9d93176 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -3271,7 +3271,7 @@ static int ffs_func_setup(struct usb_function *f, __ffs_event_add(ffs, FUNCTIONFS_SETUP); spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags); - return USB_GADGET_DELAYED_STATUS; + return creq->wLength == 0 ? USB_GADGET_DELAYED_STATUS : 0; } static bool ffs_func_req_match(struct usb_function *f,