diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index 2bb7d18ef2d54f11698180c9d1af1f1c67030e00..5c5e9124872f44d2a401b503de359d29e069b55b 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -713,12 +713,12 @@ __acquires(ci->lock)
 {
 	int retval;
 
+	spin_unlock(&ci->lock);
 	if (ci->gadget.speed != USB_SPEED_UNKNOWN) {
 		if (ci->driver)
 			ci->driver->disconnect(&ci->gadget);
 	}
 
-	spin_unlock(&ci->lock);
 	retval = _gadget_stop_activity(&ci->gadget);
 	if (retval)
 		goto done;