]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c
MdeModulePkg/PciBusDxe: Fix small memory leak in FreePciDevice
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / PciBusDxe / PciOptionRomSupport.c
index 2bc4f8c5e8573a144e05ea21605d17a7479a994a..c2be85a906af289ce694dc5f2114ce6d6be007a4 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   PCI Rom supporting funtions implementation for PCI Bus module.\r
 \r
-Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -305,7 +305,7 @@ GetOpRomInfo (
     return EFI_NOT_FOUND;\r
   }\r
 \r
-  PciIoDevice->RomSize = (UINT64) ((~AllOnes) + 1);\r
+  PciIoDevice->RomSize = (~AllOnes) + 1;\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -342,7 +342,7 @@ ContainEfiImage (
     }\r
 \r
     //\r
-    // The PCI Data Structure must be DWORD aligned. \r
+    // The PCI Data Structure must be DWORD aligned.\r
     //\r
     if (RomHeader->PcirOffset == 0 ||\r
         (RomHeader->PcirOffset & 3) != 0 ||\r
@@ -471,8 +471,8 @@ LoadOpRomImage (
     FirstCheck  = FALSE;\r
     OffsetPcir  = RomHeader->PcirOffset;\r
     //\r
-    // If the pointer to the PCI Data Structure is invalid, no further images can be located. \r
-    // The PCI Data Structure must be DWORD aligned. \r
+    // If the pointer to the PCI Data Structure is invalid, no further images can be located.\r
+    // The PCI Data Structure must be DWORD aligned.\r
     //\r
     if (OffsetPcir == 0 ||\r
         (OffsetPcir & 3) != 0 ||\r
@@ -551,7 +551,7 @@ LoadOpRomImage (
     PciDevice->BusNumber,\r
     PciDevice->DeviceNumber,\r
     PciDevice->FunctionNumber,\r
-    (UINT64) (UINTN) PciDevice->PciIo.RomImage,\r
+    PciDevice->PciIo.RomImage,\r
     PciDevice->PciIo.RomSize\r
     );\r
 \r
@@ -753,30 +753,37 @@ ProcessOpRomImage (
                     BufferSize,\r
                     &ImageHandle\r
                     );\r
-\r
-    FreePool (PciOptionRomImageDevicePath);\r
-\r
-    if (!EFI_ERROR (Status)) {\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // Record the Option ROM Image device path when LoadImage fails.\r
+      // PciOverride.GetDriver() will try to look for the Image Handle using the device path later.\r
+      //\r
+      AddDriver (PciDevice, NULL, PciOptionRomImageDevicePath);\r
+    } else {\r
       Status = gBS->StartImage (ImageHandle, NULL, NULL);\r
       if (!EFI_ERROR (Status)) {\r
-        AddDriver (PciDevice, ImageHandle);\r
+        //\r
+        // Record the Option ROM Image Handle\r
+        //\r
+        AddDriver (PciDevice, ImageHandle, NULL);\r
         PciRomAddImageMapping (\r
           ImageHandle,\r
           PciDevice->PciRootBridgeIo->SegmentNumber,\r
           PciDevice->BusNumber,\r
           PciDevice->DeviceNumber,\r
           PciDevice->FunctionNumber,\r
-          (UINT64) (UINTN) PciDevice->PciIo.RomImage,\r
+          PciDevice->PciIo.RomImage,\r
           PciDevice->PciIo.RomSize\r
           );\r
         RetStatus = EFI_SUCCESS;\r
       }\r
     }\r
+    FreePool (PciOptionRomImageDevicePath);\r
 \r
 NextImage:\r
     RomBarOffset += ImageSize;\r
 \r
-  } while (((Indicator & 0x80) == 0x00) && ((UINTN) (RomBarOffset - (UINT8 *) RomBar) < PciDevice->RomSize));\r
+  } while (((Indicator & 0x80) == 0x00) && (((UINTN) RomBarOffset - (UINTN) RomBar) < PciDevice->RomSize));\r
 \r
   return RetStatus;\r
 }\r