mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Alexey Charkov <alchark@flipper.net>
Cc: Neill Kapron <nkapron@google.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Xu Yang <xu.yang_2@nxp.com>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Sebastian Reichel <sebastian.reichel@collabora.com>
Subject: Re: [PATCH v3 3/3] usb: gadget: udc: Decide on connecting in one place
Date: Wed, 18 Nov 2026 13:22:28 -0500	[thread overview]
Message-ID: <0790eebe-a009-4617-a62a-e1a6578446a1@rowland.harvard.edu> (raw)
In-Reply-To: <20261117-udc-connect-v3-3-9413b491d213@flipper.net>

On Tue, Nov 17, 2026 at 04:48:09PM +0400, Alexey Charkov wrote:
> The UDC core connects or disconnects the gadget on bind and unbind, on
> VBUS events, in usb_gadget_{de,}activate() and through soft_connect,
> each by its own rules. gadget->connected means both "the pullup is on"
> and "turn it on once possible", so the paths misread each other's state.
> soft_connect also starts and stops the UDC behind the gadget driver's
> back, and its "connect" overrides VBUS and deactivation.
> 
> Allow the gadget to connect only while a driver is bound, VBUS is
> present, the driver hasn't deactivated it and userspace hasn't
> disconnected it, and re-evaluate that in one helper whenever any of
> these changes. Let gadget->connected track only the pullup, as UDC
> drivers already assume, and clear it at unbind even if the pullup
> refuses to switch off, so that the next driver starts clean. That
> supersedes the clearing on UDC start from the previous patch.
> 
> Reduce soft_connect to a disconnect request that is forgotten at unbind
> like the deactivation, and leave the controller alone: the attribute is
> documented to control the pullup. Keep the request if the pullup fails
> to follow, so that the next update retries it, and warn about such
> failures, as nothing else tells the user.
> 
> Treat a UDC without a pullup control as having nothing to switch.
> Binding one has most likely failed with -EOPNOTSUPP since
> commit 0ea39e030a80 ("usb: gadget: udc: Handle gadget_connect failure
> during bind operation"), but I have no affected hardware to confirm it.
> 
> Suggested-by: Alan Stern <stern@rowland.harvard.edu>
> Signed-off-by: Alexey Charkov <alchark@flipper.net>
> ---

Reviewed-by: Alan Stern <stern@rowland.harvard.edu>

> @@ -766,26 +773,20 @@ static int usb_gadget_disconnect_locked(struct usb_gadget *gadget)
>  {
>  	int ret = 0;
>  
> -	if (!gadget->ops->pullup) {
> -		ret = -EOPNOTSUPP;
> -		goto out;
> -	}
> -
>  	if (!gadget->connected)
>  		goto out;
>  
> -	if (gadget->deactivated || !gadget->udc->started) {
> -		/*
> -		 * If gadget is deactivated we only save new state.
> -		 * Gadget will stay disconnected after activation.
> -		 */
> -		gadget->connected = false;
> +	if (!gadget->ops->pullup) {
> +		ret = -EOPNOTSUPP;
>  		goto out;
>  	}
>  
>  	ret = gadget->ops->pullup(gadget, 0);
>  	if (!ret)
>  		gadget->connected = 0;
> +	else if (ret != -EOPNOTSUPP)
> +		dev_warn(&gadget->udc->dev, "failed to disable the pullup: %d\n",
> +			 ret);
>  
>  	mutex_lock(&udc_lock);
>  	if (gadget->udc->driver)
> @@ -809,6 +810,10 @@ static int usb_gadget_disconnect_locked(struct usb_gadget *gadget)
>   * Following a successful disconnect, invoke the ->disconnect() callback
>   * for the current gadget driver so that UDC drivers don't need to.

I wonder if we need to look at this.  The current code and the code in 
this patch both invoke the ->disconnect() callback following 
unsuccessful disconnects as well as successful ones.  This seems like a 
topic for another patch.

Alan Stern

      reply	other threads:[~2026-11-18 18:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 12:48 [PATCH v3 0/3] usb: gadget: udc: Rework when the gadget connects Alexey Charkov
2026-11-17 12:48 ` [PATCH v3 1/3] usb: gadget: udc: Clear a pending connection when starting the UDC Alexey Charkov
2026-11-17 12:48 ` [PATCH v3 2/3] usb: gadget: udc: Forget a deactivation when the gadget driver unbinds Alexey Charkov
2026-11-18 18:03   ` Alan Stern
2026-11-17 12:48 ` [PATCH v3 3/3] usb: gadget: udc: Decide on connecting in one place Alexey Charkov
2026-11-18 18:22   ` Alan Stern [this message]

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=0790eebe-a009-4617-a62a-e1a6578446a1@rowland.harvard.edu \
    --to=stern@rowland.harvard.edu \
    --cc=alchark@flipper.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=nkapron@google.com \
    --cc=sebastian.reichel@collabora.com \
    --cc=xu.yang_2@nxp.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

all inboxes | Powered by JetHome®