Linux USB
 help / color / mirror / Atom feed
From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Konrad Dybcio <konradybcio@kernel.org>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiazi Liu <jiazi.liu1984@gmail.com>,
	Wesley Cheng <quic_wcheng@quicinc.com>,
	Felipe Balbi <balbi@kernel.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Subject: Re: [PATCH v2 2/4] usb: dwc3: gadget: clear softconnect on stop and failed pullup
Date: Sat, 5 Dec 2026 00:19:53 +0000	[thread overview]
Message-ID: <axNDXh9V8uw4doEM@vbox> (raw)
In-Reply-To: <20261126-topic-usb_dwc3_fixups-v2-2-c0cc2b75c518@oss.qualcomm.com>

On Thu, Nov 26, 2026, Konrad Dybcio wrote:
> From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
> 
> dwc3_gadget_pullup() sets softconnect before its runtime PM check, so
> a failed pullup(1) leaves it set while gadget->connected stays false.
> The unbind path then skips pullup(0), and softconnect is never cleared.
> 
> Clear softconnect in dwc3_gadget_stop(), so a stopped controller is not
> reconnected by err_recovery_work. Take connect_mutex around the clear,
> since err_recovery_work reads softconnect under that mutex and would
> otherwise race with the store.

The store itself isn't the issue. Do you mean the mutex ensures
err_recovery_work either finishes before the controller is stopped, or
sees softconnect cleared and doesn't reconnect?

> 
> Also clear softconnect when pullup(1) fails, both on the runtime PM
> error path and when dwc3_gadget_soft_connect() fails, so a failed
> connect does not leave softconnect set for stop or err_recovery_work to
> act on.
> 
> Fixes: 8217f07a5023 ("usb: dwc3: gadget: Avoid starting DWC3 gadget during UDC unbind")
> Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
> ---
>  drivers/usb/dwc3/gadget.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index 4fab2d57e7d3..d7e22b559876 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -2884,8 +2884,12 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
>  	ret = pm_runtime_get_sync(dwc->dev);
>  	if (!ret || ret < 0) {
>  		pm_runtime_put(dwc->dev);
> -		if (ret < 0)
> +		if (ret < 0) {
>  			pm_runtime_set_suspended(dwc->dev);
> +			spin_lock_irqsave(&dwc->lock, flags);

After changing dwc->softconnect to bool, the spin_lock is not needed. We
can remove them.

> +			dwc->softconnect = 0;
> +			spin_unlock_irqrestore(&dwc->lock, flags);
> +		}
>  		return ret;
>  	}
>  
> @@ -2902,6 +2906,11 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
>  		ret = dwc3_gadget_soft_disconnect(dwc);
>  	else
>  		ret = dwc3_gadget_soft_connect(dwc);
> +	if (ret) {
> +		spin_lock_irqsave(&dwc->lock, flags);

Same here.

> +		dwc->softconnect = 0;
> +		spin_unlock_irqrestore(&dwc->lock, flags);
> +	}
>  	mutex_unlock(&dwc->connect_mutex);
>  
>  	pm_runtime_put(dwc->dev);
> @@ -3130,10 +3139,13 @@ static int dwc3_gadget_stop(struct usb_gadget *g)
>  	if (dwc->sys_wakeup)
>  		device_wakeup_disable(dwc->sysdev);
>  
> +	mutex_lock(&dwc->connect_mutex);
>  	spin_lock_irqsave(&dwc->lock, flags);
>  	dwc->gadget_driver	= NULL;
> +	dwc->softconnect = 0;
>  	dwc->max_cfg_eps = 0;
>  	spin_unlock_irqrestore(&dwc->lock, flags);
> +	mutex_unlock(&dwc->connect_mutex);
>  
>  	free_irq(dwc->irq_gadget, dwc->ev_buf);
>  
> 
> -- 
> 2.56.1
> 

Thanks,
Thinh

  parent reply	other threads:[~2026-12-05  0:20 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 13:01 [PATCH v2 0/4] DWC3 concurrency fixes Konrad Dybcio
2026-11-26 13:01 ` [PATCH v2 1/4] usb: dwc3: gadget: serialize connection bitfield writes Konrad Dybcio
2026-12-04 20:43   ` Thinh Nguyen
2026-11-26 13:01 ` [PATCH v2 2/4] usb: dwc3: gadget: clear softconnect on stop and failed pullup Konrad Dybcio
2026-11-26 13:22   ` sashiko-bot
2026-12-05  0:19   ` Thinh Nguyen [this message]
2026-11-26 13:01 ` [PATCH v2 3/4] usb: dwc3: gadget: serialize resume against error recovery Konrad Dybcio
2026-11-26 13:22   ` sashiko-bot
2026-12-05  0:51   ` Thinh Nguyen
2026-11-26 13:01 ` [PATCH v2 4/4] usb: dwc3: gadget: cancel err_recovery_work after usb_del_gadget Konrad Dybcio
2026-11-26 13:15   ` sashiko-bot
2026-12-05  0:59   ` Thinh Nguyen
2026-11-26 13:22 ` [PATCH v2 0/4] DWC3 concurrency fixes sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=axNDXh9V8uw4doEM@vbox \
    --to=thinh.nguyen@synopsys.com \
    --cc=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jiazi.liu1984@gmail.com \
    --cc=konrad.dybcio@oss.qualcomm.com \
    --cc=konradybcio@kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=quic_wcheng@quicinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox