public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: Xu Yang <xu.yang_2@nxp.com>
To: gregkh@linuxfoundation.org, khtsai@google.com,
	kexinsun@smail.nju.edu.cn, hhhuuu@google.com, kees@kernel.org
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	imx@lists.linux.dev, jun.li@nxp.com
Subject: [PATCH] usb: gadget: udc: skip pullup() if already connected
Date: Tue, 21 Apr 2026 16:20:50 +0800	[thread overview]
Message-ID: <20260421082050.1260823-1-xu.yang_2@nxp.com> (raw)

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.

Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
---
 drivers/usb/gadget/udc/core.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index e8861eaad907..be29daa7ad3c 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,
-- 
2.34.1


             reply	other threads:[~2026-04-21  8:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-21  8:20 Xu Yang [this message]
2026-04-21 14:37 ` [PATCH] usb: gadget: udc: skip pullup() if already connected Alan Stern
2026-04-21 15:27   ` Bjørn Mork
2026-04-21 20:18     ` Alan Stern

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=20260421082050.1260823-1-xu.yang_2@nxp.com \
    --to=xu.yang_2@nxp.com \
    --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 \
    /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