From 5a1da544e572f58986d7bee03d31c91d1f87f214 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Tue, 11 Aug 2020 10:00:26 +0800 Subject: [PATCH] usb: gadget: core: do not try to disconnect gadget if it is not connected 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 Signed-off-by: Felipe Balbi --- 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 bf1b0efcfaac..debf54205d22 100644 --- a/drivers/usb/gadget/udc/core.c +++ b/drivers/usb/gadget/udc/core.c @@ -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.