public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Alcantara, Paulo" <paulo.alc.cavalcanti@hp.com>
To: "edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: Feng Tian <feng.tian@intel.com>, Star Zeng <star.zeng@intel.com>
Subject: [PATCH] MdeModulePkg/PciBusDxe: Remove unnecessary memory allocations
Date: Wed, 26 Oct 2016 01:03:42 +0000	[thread overview]
Message-ID: <CS1PR84MB0230DA9E0F0CAC2CDE073CF3ACAB0@CS1PR84MB0230.NAMPRD84.PROD.OUTLOOK.COM> (raw)

Replace unnecessary heap-based allocations with stack-based ones during
mapping of PCI option ROMs.

Cc: Feng Tian <feng.tian@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Signed-off-by: Paulo Alcantara <paulo.alc.cavalcanti@hp.com>
---
 .../Bus/Pci/PciBusDxe/PciOptionRomSupport.c        | 48 +++++++---------------
 1 file changed, 14 insertions(+), 34 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c
index 2bc4f8c..c525511 100644
--- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c
+++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c
@@ -2,6 +2,7 @@
   PCI Rom supporting funtions implementation for PCI Bus module.
 
 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2016 HP Development Company, L.P.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
@@ -390,8 +391,8 @@ LoadOpRomImage (
   EFI_STATUS                RetStatus;
   BOOLEAN                   FirstCheck;
   UINT8                     *Image;
-  PCI_EXPANSION_ROM_HEADER  *RomHeader;
-  PCI_DATA_STRUCTURE        *RomPcir;
+  PCI_EXPANSION_ROM_HEADER  RomHeader;
+  PCI_DATA_STRUCTURE        RomPcir;
   UINT64                    RomSize;
   UINT64                    RomImageSize;
   UINT32                    LegacyImageLength;
@@ -423,19 +424,6 @@ LoadOpRomImage (
     //
     RomBarIndex = PCI_BRIDGE_ROMBAR;
   }
-  //
-  // Allocate memory for Rom header and PCIR
-  //
-  RomHeader = AllocatePool (sizeof (PCI_EXPANSION_ROM_HEADER));
-  if (RomHeader == NULL) {
-    return EFI_OUT_OF_RESOURCES;
-  }
-
-  RomPcir = AllocatePool (sizeof (PCI_DATA_STRUCTURE));
-  if (RomPcir == NULL) {
-    FreePool (RomHeader);
-    return EFI_OUT_OF_RESOURCES;
-  }
 
   RomBar = (UINT32) RomBase;
 
@@ -455,10 +443,10 @@ LoadOpRomImage (
                                       EfiPciWidthUint8,
                                       RomBarOffset,
                                       sizeof (PCI_EXPANSION_ROM_HEADER),
-                                      (UINT8 *) RomHeader
+                                      (VOID *) &RomHeader
                                       );
 
-    if (RomHeader->Signature != PCI_EXPANSION_ROM_HEADER_SIGNATURE) {
+    if (RomHeader.Signature != PCI_EXPANSION_ROM_HEADER_SIGNATURE) {
       RomBarOffset = RomBarOffset + 512;
       if (FirstCheck) {
         break;
@@ -469,7 +457,7 @@ LoadOpRomImage (
     }
 
     FirstCheck  = FALSE;
-    OffsetPcir  = RomHeader->PcirOffset;
+    OffsetPcir  = RomHeader.PcirOffset;
     //
     // If the pointer to the PCI Data Structure is invalid, no further images can be located. 
     // The PCI Data Structure must be DWORD aligned. 
@@ -484,24 +472,24 @@ LoadOpRomImage (
                                       EfiPciWidthUint8,
                                       RomBarOffset + OffsetPcir,
                                       sizeof (PCI_DATA_STRUCTURE),
-                                      (UINT8 *) RomPcir
+                                      (VOID *) &RomPcir
                                       );
     //
     // If a valid signature is not present in the PCI Data Structure, no further images can be located.
     //
-    if (RomPcir->Signature != PCI_DATA_STRUCTURE_SIGNATURE) {
+    if (RomPcir.Signature != PCI_DATA_STRUCTURE_SIGNATURE) {
       break;
     }
-    if (RomImageSize + RomPcir->ImageLength * 512 > RomSize) {
+    if (RomImageSize + RomPcir.ImageLength * 512 > RomSize) {
       break;
     }
-    if (RomPcir->CodeType == PCI_CODE_TYPE_PCAT_IMAGE) {
+    if (RomPcir.CodeType == PCI_CODE_TYPE_PCAT_IMAGE) {
       CodeType = PCI_CODE_TYPE_PCAT_IMAGE;
-      LegacyImageLength = ((UINT32)((EFI_LEGACY_EXPANSION_ROM_HEADER *)RomHeader)->Size512) * 512;
+      LegacyImageLength = ((UINT32)((EFI_LEGACY_EXPANSION_ROM_HEADER *)&RomHeader)->Size512) * 512;
     }
-    Indicator     = RomPcir->Indicator;
-    RomImageSize  = RomImageSize + RomPcir->ImageLength * 512;
-    RomBarOffset  = RomBarOffset + RomPcir->ImageLength * 512;
+    Indicator     = RomPcir.Indicator;
+    RomImageSize  = RomImageSize + RomPcir.ImageLength * 512;
+    RomBarOffset  = RomBarOffset + RomPcir.ImageLength * 512;
   } while (((Indicator & 0x80) == 0x00) && ((RomBarOffset - RomBar) < RomSize));
 
   //
@@ -517,8 +505,6 @@ LoadOpRomImage (
     Image     = AllocatePool ((UINT32) RomImageSize);
     if (Image == NULL) {
       RomDecode (PciDevice, RomBarIndex, RomBar, FALSE);
-      FreePool (RomHeader);
-      FreePool (RomPcir);
       return EFI_OUT_OF_RESOURCES;
     }
 
@@ -555,12 +541,6 @@ LoadOpRomImage (
     PciDevice->PciIo.RomSize
     );
 
-  //
-  // Free allocated memory
-  //
-  FreePool (RomHeader);
-  FreePool (RomPcir);
-
   return RetStatus;
 }
 
-- 
2.7.4


                 reply	other threads:[~2016-10-26  1:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CS1PR84MB0230DA9E0F0CAC2CDE073CF3ACAB0@CS1PR84MB0230.NAMPRD84.PROD.OUTLOOK.COM \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox