]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
usb: gadget: udc: skip pullup() if already connected
authorXu Yang <xu.yang_2@nxp.com>
Thu, 23 Apr 2026 09:53:55 +0000 (17:53 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 27 Apr 2026 11:14:18 +0000 (05:14 -0600)
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>
Link: https://patch.msgid.link/20260423095355.2673035-1-xu.yang_2@nxp.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/udc/core.c

index e8861eaad90775db183feab2735b9f9413862c59..60340ff9edbf0aceb35a1ec3e9d60a14f1f9953c 100644 (file)
@@ -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);