* [PATCH] usb: gadget: udc: skip pullup() if already connected
@ 2026-04-21 8:20 Xu Yang
2026-04-21 14:37 ` Alan Stern
0 siblings, 1 reply; 3+ messages in thread
From: Xu Yang @ 2026-04-21 8:20 UTC (permalink / raw)
To: gregkh, khtsai, kexinsun, hhhuuu, kees
Cc: linux-usb, linux-kernel, imx, jun.li
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] usb: gadget: udc: skip pullup() if already connected
2026-04-21 8:20 [PATCH] usb: gadget: udc: skip pullup() if already connected Xu Yang
@ 2026-04-21 14:37 ` Alan Stern
2026-04-21 15:27 ` Bjørn Mork
0 siblings, 1 reply; 3+ messages in thread
From: Alan Stern @ 2026-04-21 14:37 UTC (permalink / raw)
To: Xu Yang
Cc: gregkh, khtsai, kexinsun, hhhuuu, kees, linux-usb, linux-kernel,
imx, jun.li
On Tue, Apr 21, 2026 at 04:20:50PM +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 patch is wrong. To see why, read the comments just below the end
of the patch and see also usb_gadget_activate().
(Also, is there really anything wrong with calling pullup() twice in a
row?)
Alan Stern
> 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
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] usb: gadget: udc: skip pullup() if already connected
2026-04-21 14:37 ` Alan Stern
@ 2026-04-21 15:27 ` Bjørn Mork
0 siblings, 0 replies; 3+ messages in thread
From: Bjørn Mork @ 2026-04-21 15:27 UTC (permalink / raw)
To: Alan Stern
Cc: Xu Yang, gregkh, khtsai, kexinsun, hhhuuu, kees, linux-usb,
linux-kernel, imx, jun.li
Alan Stern <stern@rowland.harvard.edu> writes:
> This patch is wrong. To see why, read the comments just below the end
> of the patch and see also usb_gadget_activate().
Made me look...
Must say. This strikes me as a nice way to filter out humans from the
rest of the submitters:
gadget->connected = true;
goto out;
}
ret = gadget->ops->pullup(gadget, 1);
if (!ret)
gadget->connected = 1;
The indecisiveness looks strange. There's a nice symmetry with
usb_gadget_disconnect_locked() though:
gadget->connected = false;
goto out;
}
ret = gadget->ops->pullup(gadget, 0);
if (!ret)
gadget->connected = 0;
What surprised me most was that the different variants were added by the
same commit
ccdf138fe3e2 ("usb: gadget: add usb_gadget_activate/deactivate functions").
Bjørn
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-21 15:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-21 8:20 [PATCH] usb: gadget: udc: skip pullup() if already connected Xu Yang
2026-04-21 14:37 ` Alan Stern
2026-04-21 15:27 ` Bjørn Mork
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox