]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/UndiRuntimeDxe/Init.c
Fixed potential issues to release resources when error occurs.
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / UndiRuntimeDxe / Init.c
index b79c5fe7a676f91a632f5f95ff25e4dc3170b675..413ef32a7a8b5f76eb529da8b1636a9c7c6bc8da 100644 (file)
@@ -287,6 +287,7 @@ Returns:
   EFI_PCI_IO_PROTOCOL       *PciIoFncs;\r
   UINTN                     Len;\r
   UINT64                    Supports;\r
   EFI_PCI_IO_PROTOCOL       *PciIoFncs;\r
   UINTN                     Len;\r
   UINT64                    Supports;\r
+  BOOLEAN                   PciAttributesSaved;\r
 \r
   Status = gBS->OpenProtocol (\r
                   Controller,\r
 \r
   Status = gBS->OpenProtocol (\r
                   Controller,\r
@@ -321,6 +322,8 @@ Returns:
     return Status;\r
   }\r
 \r
     return Status;\r
   }\r
 \r
+  PciAttributesSaved = FALSE;\r
+\r
   Status = gBS->AllocatePool (\r
                   EfiRuntimeServicesData,\r
                   sizeof (UNDI32_DEV),\r
   Status = gBS->AllocatePool (\r
                   EfiRuntimeServicesData,\r
                   sizeof (UNDI32_DEV),\r
@@ -344,8 +347,9 @@ Returns:
                     );\r
 \r
   if (EFI_ERROR (Status)) {\r
                     );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto UndiErrorDeleteDevice;\r
   }\r
   }\r
+  PciAttributesSaved = TRUE;\r
 \r
   //\r
   // allocate and initialize both (old and new) the !pxe structures here,\r
 \r
   //\r
   // allocate and initialize both (old and new) the !pxe structures here,\r
@@ -550,15 +554,17 @@ UndiErrorDeletePxe:
   }\r
 \r
 UndiErrorDeleteDevice:\r
   }\r
 \r
 UndiErrorDeleteDevice:\r
-  //\r
-  // Restore original PCI attributes\r
-  //\r
-  PciIoFncs->Attributes (\r
-                  PciIoFncs,\r
-                  EfiPciIoAttributeOperationSet,\r
-                  UNDI32Device->NicInfo.OriginalPciAttributes,\r
-                  NULL\r
-                  );\r
+  if (PciAttributesSaved == TRUE) {\r
+    //\r
+    // Restore original PCI attributes\r
+    //\r
+    PciIoFncs->Attributes (\r
+                    PciIoFncs,\r
+                    EfiPciIoAttributeOperationSet,\r
+                    UNDI32Device->NicInfo.OriginalPciAttributes,\r
+                    NULL\r
+                    );\r
+  }\r
 \r
   gBS->FreePool (UNDI32Device);\r
 \r
 \r
   gBS->FreePool (UNDI32Device);\r
 \r