From patchwork Fri Sep 9 07:16:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 75841 Delivered-To: patch@linaro.org Received: by 10.140.106.11 with SMTP id d11csp205299qgf; Fri, 9 Sep 2016 00:17:38 -0700 (PDT) X-Received: by 10.66.54.132 with SMTP id j4mr3915006pap.110.1473405457582; Fri, 09 Sep 2016 00:17:37 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xv4si2555016pab.153.2016.09.09.00.17.37; Fri, 09 Sep 2016 00:17:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752565AbcIIHRg (ORCPT + 4 others); Fri, 9 Sep 2016 03:17:36 -0400 Received: from mail-pf0-f181.google.com ([209.85.192.181]:36544 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752462AbcIIHRd (ORCPT ); Fri, 9 Sep 2016 03:17:33 -0400 Received: by mail-pf0-f181.google.com with SMTP id 128so26638362pfb.3 for ; Fri, 09 Sep 2016 00:17:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=SaDUROS5xOcIjNPF/WdubVs0D0Q41eS70jXppshlZUo=; b=AOOIGpo7KPowFFCte2pxIAFhIsZxMlEzPnaPDejPRvlyA+Q1XNcnkSEDM6NR259r0Z BjTjRDqWjHtQsfeq4UQBkOgjgrA07lbRXefx193KlMlzylpqemZFDeMf+WToe48/gmkR Y6A2GUvmVm/DIwePLF1emn59fhkFCXxgwPJA8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=SaDUROS5xOcIjNPF/WdubVs0D0Q41eS70jXppshlZUo=; b=HqQZBevgImsimf8AzTORk0Tqagh3MyQW7sAhNkHM37/Jv3vyizJBo1f9MxTjujkhIo pvXhhB5szmKsDGiO4AUbVMp85HTBdxpbg8dU05+EisV8muAYpD2WIuBeW4THe3C4Mgh7 4XkWfEM4fgQZ7/PgeB90oYxFfTX/bwBt6As+dWFMKMgWw0ly8sScbmxvWm5MQeDNM8x4 jYEBJh3DnWoxq//OtlRkgmaw06JL9BqEvPV4zXulP+HfA0JNVToPxZkQbddAEG65Ci0f nN0C9OT6VgO2JZ7D+C38R2Uagoc1r1MQJQ1WefEBqgIlGMAkL7lq+2+cflhOhpxqrPTZ XxBQ== X-Gm-Message-State: AE9vXwM6+szV3k/nfUixjsSY/QbKMVH/NYBIUTR30dytABe5o5e0R5+CEFMejogVt7lisk6r X-Received: by 10.98.28.138 with SMTP id c132mr3970596pfc.118.1473405447394; Fri, 09 Sep 2016 00:17:27 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id hs7sm2577789pad.24.2016.09.09.00.17.23 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Sep 2016 00:17:26 -0700 (PDT) From: Baolin Wang To: balbi@kernel.org, gregkh@linuxfoundation.org Cc: broonie@kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org Subject: [PATCH v2 1/2] usb: dwc3: gadget: Add disconnect checking when changing function dynamically Date: Fri, 9 Sep 2016 15:16:35 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org When system has stpped the gadget, we should avoid queuing any requests which will cause tranfer failed. Thus adding some disconnect checking to avoid this situation. Signed-off-by: Baolin Wang --- Changes since v1: - Split into 2 separate ptaches. - Choose complete mechanism instead of polling. --- drivers/usb/dwc3/ep0.c | 8 ++++++++ drivers/usb/dwc3/gadget.c | 12 +++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c index fe79d77..632e5a4 100644 --- a/drivers/usb/dwc3/ep0.c +++ b/drivers/usb/dwc3/ep0.c @@ -228,6 +228,14 @@ int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request, int ret; spin_lock_irqsave(&dwc->lock, flags); + if (!dwc->pullups_connected) { + dwc3_trace(trace_dwc3_ep0, + "queuing request %p to %s when gadget is disconnected", + request, dep->name); + ret = -ESHUTDOWN; + goto out; + } + if (!dep->endpoint.desc) { dwc3_trace(trace_dwc3_ep0, "trying to queue request %p to disabled %s", diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 1783406..1a33308 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1040,6 +1040,13 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req) struct dwc3 *dwc = dep->dwc; int ret; + if (!dwc->pullups_connected) { + dwc3_trace(trace_dwc3_gadget, + "queuing request %p to %s when gadget is disconnected", + &req->request, dep->endpoint.name); + return -ESHUTDOWN; + } + if (!dep->endpoint.desc) { dwc3_trace(trace_dwc3_gadget, "trying to queue request %p to disabled %s", @@ -1984,13 +1991,12 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, struct dwc3_ep *dep, if (ret) break; } - /* * Our endpoint might get disabled by another thread during * dwc3_gadget_giveback(). If that happens, we're just gonna return 1 * early on so DWC3_EP_BUSY flag gets cleared */ - if (!dep->endpoint.desc) + if (!dep->endpoint.desc || !dwc->pullups_connected) return 1; if (usb_endpoint_xfer_isoc(dep->endpoint.desc) && @@ -2064,7 +2070,7 @@ static void dwc3_endpoint_transfer_complete(struct dwc3 *dwc, * dwc3_gadget_giveback(). If that happens, we're just gonna return 1 * early on so DWC3_EP_BUSY flag gets cleared */ - if (!dep->endpoint.desc) + if (!dep->endpoint.desc || !dwc->pullups_connected) return; if (!usb_endpoint_xfer_isoc(dep->endpoint.desc)) {