Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp259970pxx; Thu, 29 Oct 2020 01:47:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHWYYa8wxbYLNupkrMLE2dfKTF3iz1e00jrt0+38PBD4w4Q3h1SECLKK6eucfQvB0/lJLm X-Received: by 2002:a05:6402:78b:: with SMTP id d11mr1610746edy.82.1603961273875; Thu, 29 Oct 2020 01:47:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603961273; cv=none; d=google.com; s=arc-20160816; b=zr9TVtH9MDjSDHzYsaVq2ycjeQVviZgO6gkEw6zrz3zLRvpKp/DnYLJ8E5j2Zl0rxv LFE1GLvXSWUUX0E0IcOtlAGSeF7l3gFVMdy1xhiW4NG39NkfLVk0WHXrtGGO361BMLtC E+sETpt0s9tW/FBcQKmbppNX/aBVDty1u6A3ME73/2CmYbaOHy147K90eZlkEKL/NjGJ 6E/ZRhLsBxOEx5f2OB7M1prtgzdpgZhvZZFj5aUm/HQeRo13kLxoy87o46Bp+rKEBaxl DH/+3g/HVOTs7sR3aTFHB8vYe2k0qa/C87UAD0lX4Z52Ak3fF0c8raYIWBu6RhYR1h2q IWYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=0b45w2U89UApqtBV1MW3N/ml3Zo102r+gM64GQWl/PM=; b=f3DCHqWc18Gvy3fV2k5CNJftDEBKPUknFDmZHHpp8cpRSDsCp9zWBuVYEQCmHFUPLh neXYpWAR+j+Qq2pcdv7ZZUCiLUXfyGkT3dqd5gW0qbA8adFdTDecYWXl560FvkT0GAUF lTSwout8iWL4Uga3r5nA79pmDc2Z0Gio4QgVBwaaybGDji/gmGFwsQIA0VnGOw3nIiHM I93NAIRMfSHZlshQN7Ijcncm7GupbrSF8NlEo2eL5fYW1fuqbMj1hdaFmpmy9JqWhzQK qeFzYreVmOxGgPMwj/92IE9oTB+9/UFq5zyOc4I+oFpDPk6BRrF1FU8pwXND3g5Dm1rw WoTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m18si1297707ejb.604.2020.10.29.01.47.32; Thu, 29 Oct 2020 01:47:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404270AbgJ2BIw (ORCPT + 99 others); Wed, 28 Oct 2020 21:08:52 -0400 Received: from netrider.rowland.org ([192.131.102.5]:43361 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S2404369AbgJ2BHt (ORCPT ); Wed, 28 Oct 2020 21:07:49 -0400 Received: (qmail 1303612 invoked by uid 1000); 28 Oct 2020 21:07:48 -0400 Date: Wed, 28 Oct 2020 21:07:48 -0400 From: Alan Stern To: Wesley Cheng Cc: balbi@kernel.org, gregkh@linuxfoundation.org, Thinh.Nguyen@synopsys.com, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, jackp@codeaurora.org Subject: Re: [PATCH 1/2] usb: dwc3: gadget: Allow runtime suspend if UDC unbinded Message-ID: <20201029010748.GA1303156@rowland.harvard.edu> References: <20201028234311.6464-1-wcheng@codeaurora.org> <20201028234311.6464-2-wcheng@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201028234311.6464-2-wcheng@codeaurora.org> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 28, 2020 at 04:43:10PM -0700, Wesley Cheng wrote: > The DWC3 runtime suspend routine checks for the USB connected parameter to > determine if the controller can enter into a low power state. The > connected state is only set to false after receiving a disconnect event. > However, in the case of a device initiated disconnect (i.e. UDC unbind), > the controller is halted and a disconnect event is never generated. Set > the connected flag to false if issuing a device initiated disconnect to > allow the controller to be suspended. > > Signed-off-by: Wesley Cheng > --- > drivers/usb/dwc3/gadget.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c > index 5d879b7606d5..6364429b2122 100644 > --- a/drivers/usb/dwc3/gadget.c > +++ b/drivers/usb/dwc3/gadget.c > @@ -1995,6 +1995,11 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) > unsigned long flags; > int ret; > > + if (pm_runtime_suspended(dwc->dev)) { > + pm_request_resume(dwc->dev); > + return 0; > + } Isn't this racy? What happens if the controller was active but a runtime suspend occurs right here? Alan Stern > + > is_on = !!is_on; > > /* > @@ -2050,6 +2055,7 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) > dwc->ev_buf->lpos = (dwc->ev_buf->lpos + count) % > dwc->ev_buf->length; > } > + dwc->connected = false; > } > > ret = dwc3_gadget_run_stop(dwc, is_on, false); > -- > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, > a Linux Foundation Collaborative Project