mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Xu Yang <xu.yang_2@nxp.com>
Cc: gregkh@linuxfoundation.org, khtsai@google.com,
	kexinsun@smail.nju.edu.cn, hhhuuu@google.com, kees@kernel.org,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	imx@lists.linux.dev, jun.li@nxp.com
Subject: Re: [PATCH v2] usb: gadget: udc: skip pullup() if already connected
Date: Thu, 23 Apr 2026 10:00:00 -0400	[thread overview]
Message-ID: <89b6a6ca-137b-49e2-a796-443e7cb58245@rowland.harvard.edu> (raw)
In-Reply-To: <20260423095355.2673035-1-xu.yang_2@nxp.com>

On Thu, Apr 23, 2026 at 05:53:55PM +0800, Xu Yang wrote:
> The device controller may update vbus status via usb_udc_vbus_handler(),
> which tries to connect the gadget even though gadget_bind_driver() has
> already called usb_udc_connect_control_locked(). This causes pullup() to
> be called twice. Avoid this by checking if gadget->connected is true.
> 
> This also set gadget->connected as false in usb_gadget_activate() if it
> became connected while it was being deactivated. Otherwise,
> usb_gadget_connect_locked will return early and pullup() won't be called.
> 
> Signed-off-by: Xu Yang <xu.yang_2@nxp.com>

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

> ---
> Changes in v2:
>  - reset gadget->connected as false before calling usb_gadget_connect_locked()
> ---
>  drivers/usb/gadget/udc/core.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
> index e8861eaad907..60340ff9edbf 100644
> --- a/drivers/usb/gadget/udc/core.c
> +++ b/drivers/usb/gadget/udc/core.c
> @@ -712,6 +712,9 @@ static int usb_gadget_connect_locked(struct usb_gadget *gadget)
>  		goto out;
>  	}
>  
> +	if (gadget->connected)
> +		goto out;
> +
>  	if (gadget->deactivated || !gadget->udc->allow_connect || !gadget->udc->started) {
>  		/*
>  		 * If the gadget isn't usable (because it is deactivated,
> @@ -885,8 +888,10 @@ int usb_gadget_activate(struct usb_gadget *gadget)
>  	 * If gadget has been connected before deactivation, or became connected
>  	 * while it was being deactivated, we call usb_gadget_connect().
>  	 */
> -	if (gadget->connected)
> +	if (gadget->connected) {
> +		gadget->connected = false;
>  		ret = usb_gadget_connect_locked(gadget);
> +	}
>  
>  unlock:
>  	mutex_unlock(&gadget->udc->connect_lock);
> -- 
> 2.34.1
> 
> 

      reply	other threads:[~2026-04-23 14:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-23  9:53 Xu Yang
2026-04-23 14:00 ` 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=89b6a6ca-137b-49e2-a796-443e7cb58245@rowland.harvard.edu \
    --to=stern@rowland.harvard.edu \
    --cc=gregkh@linuxfoundation.org \
    --cc=hhhuuu@google.com \
    --cc=imx@lists.linux.dev \
    --cc=jun.li@nxp.com \
    --cc=kees@kernel.org \
    --cc=kexinsun@smail.nju.edu.cn \
    --cc=khtsai@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --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®