]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c
Fixed potential issues to release resources when error occurs.
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / EhciDxe / Ehci.c
index 32ae6b6cdcfd040f2ef004ab95c55beaf0577535..e37cf719d7fcb9dc3a2a7a28cacd9b5471949640 100644 (file)
@@ -1496,6 +1496,7 @@ EhcDriverBindingStart (
   EFI_PCI_IO_PROTOCOL     *PciIo;\r
   UINT64                  Supports;\r
   UINT64                  OriginalPciAttributes;\r
   EFI_PCI_IO_PROTOCOL     *PciIo;\r
   UINT64                  Supports;\r
   UINT64                  OriginalPciAttributes;\r
+  BOOLEAN                 PciAttributesSaved;\r
 \r
   //\r
   // Open the PciIo Protocol, then enable the USB host controller\r
 \r
   //\r
   // Open the PciIo Protocol, then enable the USB host controller\r
@@ -1514,6 +1515,7 @@ EhcDriverBindingStart (
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
+  PciAttributesSaved = FALSE;\r
   //\r
   // Save original PCI attributes\r
   //\r
   //\r
   // Save original PCI attributes\r
   //\r
@@ -1525,8 +1527,9 @@ EhcDriverBindingStart (
                     );\r
 \r
   if (EFI_ERROR (Status)) {\r
                     );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto CLOSE_PCIIO;\r
   }\r
   }\r
+  PciAttributesSaved = TRUE;\r
 \r
   Status = PciIo->Attributes (\r
                     PciIo,\r
 \r
   Status = PciIo->Attributes (\r
                     PciIo,\r
@@ -1634,15 +1637,17 @@ FREE_POOL:
   gBS->FreePool (Ehc);\r
 \r
 CLOSE_PCIIO:\r
   gBS->FreePool (Ehc);\r
 \r
 CLOSE_PCIIO:\r
-  //\r
-  // Restore original PCI attributes\r
-  //\r
-  PciIo->Attributes (\r
-                  PciIo,\r
-                  EfiPciIoAttributeOperationSet,\r
-                  OriginalPciAttributes,\r
-                  NULL\r
-                  );\r
+  if (PciAttributesSaved == TRUE) {\r
+    //\r
+    // Restore original PCI attributes\r
+    //\r
+    PciIo->Attributes (\r
+                    PciIo,\r
+                    EfiPciIoAttributeOperationSet,\r
+                    OriginalPciAttributes,\r
+                    NULL\r
+                    );\r
+  }\r
 \r
   gBS->CloseProtocol (\r
          Controller,\r
 \r
   gBS->CloseProtocol (\r
          Controller,\r