usb: gadget: core: do not try to disconnect gadget if it is not connected
authorPeter Chen <peter.chen@nxp.com>
Tue, 11 Aug 2020 02:00:26 +0000 (10:00 +0800)
committerFelipe Balbi <balbi@kernel.org>
Fri, 2 Oct 2020 06:57:43 +0000 (09:57 +0300)
Current UDC core connects gadget during the loading gadget flow
(udc_bind_to_driver->usb_udc_connect_control), but for
platforms which do not connect gadget if the VBUS is not there,
they call usb_gadget_disconnect, but the gadget is not connected
at this time, notify disconnecton for the gadget driver is meaningless
at this situation.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
drivers/usb/gadget/udc/core.c

index bf1b0efcfaac97137c5794b9cd885b9eca145127..debf54205d22e3660fcd99f8e22429a4f6299e72 100644 (file)
@@ -715,6 +715,9 @@ int usb_gadget_disconnect(struct usb_gadget *gadget)
                goto out;
        }
 
+       if (!gadget->connected)
+               goto out;
+
        if (gadget->deactivated) {
                /*
                 * If gadget is deactivated we only save new state.