]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
MdeModulePkg/Usb: All h/w related stop operation at DriverBindingStop() should be...
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbBusDxe / UsbBus.c
index ff6b99c87f9ad88a1a797edc0d139fa57a980d73..ef002f53bb71bbef0efb6cb9e75ae1e0e7f513da 100644 (file)
@@ -1402,6 +1402,7 @@ UsbBusControllerDriverStop (
   EFI_TPL               OldTpl;\r
   UINTN                 Index;\r
   EFI_STATUS            Status;\r
+  EFI_STATUS            ReturnStatus;\r
 \r
   Status  = EFI_SUCCESS;\r
 \r
@@ -1411,6 +1412,7 @@ UsbBusControllerDriverStop (
     //\r
     OldTpl   = gBS->RaiseTPL (TPL_CALLBACK);\r
 \r
+    ReturnStatus = EFI_SUCCESS;\r
     for (Index = 0; Index < NumberOfChildren; Index++) {\r
       Status = gBS->OpenProtocol (\r
                       ChildHandleBuffer[Index],\r
@@ -1434,11 +1436,11 @@ UsbBusControllerDriverStop (
       UsbIf   = USB_INTERFACE_FROM_USBIO (UsbIo);\r
       UsbDev  = UsbIf->Device;\r
 \r
-      UsbRemoveDevice (UsbDev);\r
+      ReturnStatus = UsbRemoveDevice (UsbDev);\r
     }\r
 \r
     gBS->RestoreTPL (OldTpl);\r
-    return EFI_SUCCESS;\r
+    return ReturnStatus;\r
   }\r
 \r
   DEBUG (( EFI_D_INFO, "UsbBusStop: usb bus stopped on %p\n", Controller));\r
@@ -1471,53 +1473,60 @@ UsbBusControllerDriverStop (
   RootHub = Bus->Devices[0];\r
   RootIf  = RootHub->Interfaces[0];\r
 \r
-  mUsbRootHubApi.Release (RootIf);\r
-\r
   ASSERT (Bus->MaxDevices <= 256);\r
+  ReturnStatus = EFI_SUCCESS;\r
   for (Index = 1; Index < Bus->MaxDevices; Index++) {\r
     if (Bus->Devices[Index] != NULL) {\r
-      UsbRemoveDevice (Bus->Devices[Index]);\r
+      Status = UsbRemoveDevice (Bus->Devices[Index]);\r
+      if (EFI_ERROR (Status)) {\r
+        ReturnStatus = Status;\r
+      }\r
     }\r
   }\r
 \r
   gBS->RestoreTPL (OldTpl);\r
 \r
-  gBS->FreePool   (RootIf);\r
-  gBS->FreePool   (RootHub);\r
-  Status = UsbBusFreeUsbDPList (&Bus->WantedUsbIoDPList);\r
-  ASSERT (!EFI_ERROR (Status));\r
+  if (!EFI_ERROR (ReturnStatus)) {\r
+    mUsbRootHubApi.Release (RootIf);\r
+    gBS->FreePool   (RootIf);\r
+    gBS->FreePool   (RootHub);\r
 \r
-  //\r
-  // Uninstall the bus identifier and close USB_HC/USB2_HC protocols\r
-  //\r
-  gBS->UninstallProtocolInterface (Controller, &gEfiCallerIdGuid, &Bus->BusId);\r
+    Status = UsbBusFreeUsbDPList (&Bus->WantedUsbIoDPList);\r
+    ASSERT (!EFI_ERROR (Status));\r
 \r
-  if (Bus->Usb2Hc != NULL) {\r
-    gBS->CloseProtocol (\r
-           Controller,\r
-           &gEfiUsb2HcProtocolGuid,\r
-           This->DriverBindingHandle,\r
-           Controller\r
-           );\r
-  }\r
+    //\r
+    // Uninstall the bus identifier and close USB_HC/USB2_HC protocols\r
+    //\r
+    gBS->UninstallProtocolInterface (Controller, &gEfiCallerIdGuid, &Bus->BusId);\r
 \r
-  if (Bus->UsbHc != NULL) {\r
-    gBS->CloseProtocol (\r
-           Controller,\r
-           &gEfiUsbHcProtocolGuid,\r
-           This->DriverBindingHandle,\r
-           Controller\r
-           );\r
-  }\r
+    if (Bus->Usb2Hc != NULL) {\r
+      Status = gBS->CloseProtocol (\r
+                      Controller,\r
+                      &gEfiUsb2HcProtocolGuid,\r
+                      This->DriverBindingHandle,\r
+                      Controller\r
+                      );\r
+    }\r
 \r
-  gBS->CloseProtocol (\r
-         Controller,\r
-         &gEfiDevicePathProtocolGuid,\r
-         This->DriverBindingHandle,\r
-         Controller\r
-         );\r
+    if (Bus->UsbHc != NULL) {\r
+      Status = gBS->CloseProtocol (\r
+                      Controller,\r
+                      &gEfiUsbHcProtocolGuid,\r
+                      This->DriverBindingHandle,\r
+                      Controller\r
+                      );\r
+    }\r
 \r
-  gBS->FreePool (Bus);\r
+    if (!EFI_ERROR (Status)) {\r
+      gBS->CloseProtocol (\r
+             Controller,\r
+             &gEfiDevicePathProtocolGuid,\r
+             This->DriverBindingHandle,\r
+             Controller\r
+             );\r
 \r
+      gBS->FreePool (Bus);\r
+    }\r
+  }\r
   return Status;\r
 }\r