]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Usb/UsbBusDxe/usbbus.c
Fixed unexpected timeout in Usb MassStorage Driver.
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbBusDxe / usbbus.c
index 2e2333aa7c6d8787132c956c34195eb8a845c5f9..910ebc5d23b29cfdbdb15353ddf4b7ad47b2a3be 100644 (file)
@@ -1142,6 +1142,24 @@ UsbBusControllerDriverStart (
     goto CLOSE_HC;\r
   }\r
 \r
+  UsbHcReset (UsbBus, EFI_USB_HC_RESET_GLOBAL);\r
+  UsbHcSetState (UsbBus, EfiUsbHcStateOperational);\r
+\r
+  //\r
+  // Install an EFI_USB_BUS_PROTOCOL to host controler to identify it.\r
+  //\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &Controller,\r
+                  &mUsbBusProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  &UsbBus->BusId\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "UsbBusStart: Failed to install bus protocol %r\n", Status));\r
+    goto CLOSE_HC;\r
+  }\r
+\r
   //\r
   // Create a fake usb device for root hub\r
   //\r
@@ -1149,7 +1167,7 @@ UsbBusControllerDriverStart (
 \r
   if (RootHub == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
-    goto CLOSE_HC;\r
+    goto UNINSTALL_USBBUS;\r
   }\r
 \r
   RootIf = AllocateZeroPool (sizeof (USB_INTERFACE));\r
@@ -1157,7 +1175,7 @@ UsbBusControllerDriverStart (
   if (RootIf == NULL) {\r
     gBS->FreePool (RootHub);\r
     Status = EFI_OUT_OF_RESOURCES;\r
-    goto CLOSE_HC;\r
+    goto FREE_ROOTHUB;\r
   }\r
 \r
   RootHub->Bus            = UsbBus;\r
@@ -1166,11 +1184,7 @@ UsbBusControllerDriverStart (
   RootIf->Signature       = USB_INTERFACE_SIGNATURE;\r
   RootIf->Device          = RootHub;\r
   RootIf->DevicePath      = UsbBus->DevicePath;\r
-\r
   \r
-  UsbHcReset (UsbBus, EFI_USB_HC_RESET_GLOBAL);\r
-  UsbHcSetState (UsbBus, EfiUsbHcStateOperational);\r
-\r
   Status                  = mUsbRootHubApi.Init (RootIf);\r
 \r
   if (EFI_ERROR (Status)) {\r
@@ -1180,31 +1194,20 @@ UsbBusControllerDriverStart (
 \r
   UsbBus->Devices[0] = RootHub;\r
 \r
-  //\r
-  // Install an EFI_USB_BUS_PROTOCOL to host controler to identify it.\r
-  //\r
-  Status = gBS->InstallProtocolInterface (\r
-                  &Controller,\r
-                  &mUsbBusProtocolGuid,\r
-                  EFI_NATIVE_INTERFACE,\r
-                  &UsbBus->BusId\r
-                  );\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    DEBUG (( EFI_D_ERROR, "UsbBusStart: Failed to install bus protocol %r\n", Status));\r
-\r
-    mUsbRootHubApi.Release (RootIf);\r
-    goto FREE_ROOTHUB;\r
-  }\r
-\r
-\r
   DEBUG (( EFI_D_INFO, "UsbBusStart: usb bus started on %x, root hub %x\n", Controller, RootIf));\r
   return EFI_SUCCESS;\r
-\r
+  \r
 FREE_ROOTHUB:\r
-  gBS->FreePool (RootIf);\r
-  gBS->FreePool (RootHub);\r
-\r
+  if (RootIf != NULL) {\r
+    gBS->FreePool (RootIf);\r
+  }\r
+  if (RootHub != NULL) {\r
+    gBS->FreePool (RootHub);\r
+  }\r
+  \r
+UNINSTALL_USBBUS:\r
+  gBS->UninstallProtocolInterface (Controller, &mUsbBusProtocolGuid, &UsbBus->BusId);\r
+  \r
 CLOSE_HC:\r
   if (UsbBus->Usb2Hc != NULL) {\r
     gBS->CloseProtocol (\r
@@ -1214,7 +1217,6 @@ CLOSE_HC:
           Controller\r
           );\r
   }\r
-\r
   if (UsbBus->UsbHc != NULL) {\r
     gBS->CloseProtocol (\r
           Controller,\r
@@ -1223,14 +1225,12 @@ CLOSE_HC:
           Controller\r
           );\r
   }\r
-\r
   gBS->CloseProtocol (\r
          Controller,\r
          &gEfiDevicePathProtocolGuid,\r
          This->DriverBindingHandle,\r
          Controller\r
          );\r
-\r
   gBS->FreePool (UsbBus);\r
 \r
   DEBUG (( EFI_D_ERROR, "UsbBusStart: Failed to start bus driver %r\n", Status));\r