From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0712.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe46::712]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id F3A071A1E43 for ; Tue, 25 Oct 2016 18:03:44 -0700 (PDT) Received: from CS1PR84MB0230.NAMPRD84.PROD.OUTLOOK.COM (10.162.190.152) by CS1PR84MB0229.NAMPRD84.PROD.OUTLOOK.COM (10.162.190.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.679.12; Wed, 26 Oct 2016 01:03:42 +0000 Received: from CS1PR84MB0230.NAMPRD84.PROD.OUTLOOK.COM ([10.162.190.152]) by CS1PR84MB0230.NAMPRD84.PROD.OUTLOOK.COM ([10.162.190.152]) with mapi id 15.01.0679.015; Wed, 26 Oct 2016 01:03:42 +0000 From: "Alcantara, Paulo" To: "edk2-devel@lists.01.org" CC: Feng Tian , Star Zeng Thread-Topic: [PATCH] MdeModulePkg/PciBusDxe: Remove unnecessary memory allocations Thread-Index: AQHSLyRkQDcLlorF9EicuuGJ+zYZ9g== Date: Wed, 26 Oct 2016 01:03:42 +0000 Message-ID: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=paulo.alc.cavalcanti@hp.com; x-originating-ip: [2804:7f4:c380:ab64::1] x-ms-office365-filtering-correlation-id: 4e2e4a52-7998-45df-24fa-08d3fd3beddb x-microsoft-exchange-diagnostics: 1; CS1PR84MB0229; 6:uN9Dakle5SqWYVU0n8T+XpH//MTeX53D2N7LrWKyB2oPpsjs/9ib+LxOo5rSlhntoI2bAobHlmygdTfarR5gRxM1HdzQfLP8dX2x4FHFzLNOX30yxF1RRkDJn9EcEIlIxMqjQlAiaqv1VXNYWi+9/sGuOHK7qUEsEixoQzYVTNCSk0kqgPm2p1UiXrve6++gStZp1bmZyOVf+YDrwN5kpif2hFyyWMVwHnKit85NJJP249ujhBneCIiQvAXcLLXEKouz/+PsVkrxDt8s8qpJKlZfb0+n/uq1yzb/kTsGRYXK6NX6Kms7bzBNZmkHt0Km; 5:cF0Ekd0OKLVNCnTmYGvhXO+EbM50d7ZVb+H6IfBAoxHPiuLnFg8m61AYZBg+q4R4h3Szu/eUqI4m+gLTlWtLaTUmYEj1IEFhcEwjdn2YWood4WnnBEj0bQ3Bddm7wuzm3jT8+EJJWCYU62RHAAkm9oKR9bkZJrUu6LCThGcCR9Y=; 24:F3b8ho8bqY1kcUzYkWoPV+K0Ch+R6ykrmOFTKkdsN/t7gPGnFVSaNP1W1c/rBm6wrWx8+KurCjeE1EeFzESWP6olIYzAmWchNL+BJwINn2M=; 7:hSj9R+IBTBVjm+d2w+ttRotPhTF5ZIN5LNt9DqE9q3HRdKHkdudJ+Lp/Thd0dfxknNjoieR8L9qa7ngX47POU9WXw7LoOSsl7vKM+UQ1tkFQmflgOyd1s9Lv9vNbwj/ZOLY/p8KRoIAC6Rayk9neHo1ccGaPAOV7wg9nXqUWOO9U9xos2B01oTmlnhdPX+pdUr3cA/wVCx6zl5nAAP0t3CkyyHUUBiowiRJn19g40cxcrvln/w0XrjozwIiyim9T97a3PkZbHcPL2pPucCZ63twk0vvJDy10CrIUU3nxBBliK3y9G57CP3FansxR0uVv6dbMk1n4pM3T8QZipicB8eslwyK3UIbnJb/IgnCIWgI= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CS1PR84MB0229; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(788757137089)(228905959029699)(73583498263828); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001); SRVR:CS1PR84MB0229; BCL:0; PCL:0; RULEID:; SRVR:CS1PR84MB0229; x-forefront-prvs: 0107098B6C x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(7916002)(199003)(189002)(6602003)(87936001)(6116002)(2351001)(7846002)(3280700002)(110136003)(586003)(2501003)(305945005)(7736002)(5002640100001)(74316002)(97736004)(106116001)(105586002)(102836003)(99286002)(68736007)(4326007)(3660700001)(2906002)(11100500001)(19580395003)(19580405001)(50986999)(122556002)(33656002)(229853001)(6916009)(92566002)(54356999)(8936002)(106356001)(8676002)(9686002)(7696004)(101416001)(10400500002)(189998001)(81166006)(81156014)(2900100001)(5660300001)(86362001)(77096005); DIR:OUT; SFP:1102; SCL:1; SRVR:CS1PR84MB0229; H:CS1PR84MB0230.NAMPRD84.PROD.OUTLOOK.COM; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; received-spf: None (protection.outlook.com: hp.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: hp.com X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Oct 2016 01:03:42.2459 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: ca7981a2-785a-463d-b82a-3db87dfc3ce6 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CS1PR84MB0229 Subject: [PATCH] MdeModulePkg/PciBusDxe: Remove unnecessary memory allocations X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Oct 2016 01:03:45 -0000 Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Replace unnecessary heap-based allocations with stack-based ones during mapping of PCI option ROMs. Cc: Feng Tian Cc: Star Zeng Signed-off-by: Paulo Alcantara --- .../Bus/Pci/PciBusDxe/PciOptionRomSupport.c | 48 +++++++-----------= ---- 1 file changed, 14 insertions(+), 34 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c b/MdeModu= lePkg/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. =20 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2016 HP Development Company, L.P.
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 =3D PCI_BRIDGE_ROMBAR; } - // - // Allocate memory for Rom header and PCIR - // - RomHeader =3D AllocatePool (sizeof (PCI_EXPANSION_ROM_HEADER)); - if (RomHeader =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - RomPcir =3D AllocatePool (sizeof (PCI_DATA_STRUCTURE)); - if (RomPcir =3D=3D NULL) { - FreePool (RomHeader); - return EFI_OUT_OF_RESOURCES; - } =20 RomBar =3D (UINT32) RomBase; =20 @@ -455,10 +443,10 @@ LoadOpRomImage ( EfiPciWidthUint8, RomBarOffset, sizeof (PCI_EXPANSION_ROM_HEADER), - (UINT8 *) RomHeader + (VOID *) &RomHeader ); =20 - if (RomHeader->Signature !=3D PCI_EXPANSION_ROM_HEADER_SIGNATURE) { + if (RomHeader.Signature !=3D PCI_EXPANSION_ROM_HEADER_SIGNATURE) { RomBarOffset =3D RomBarOffset + 512; if (FirstCheck) { break; @@ -469,7 +457,7 @@ LoadOpRomImage ( } =20 FirstCheck =3D FALSE; - OffsetPcir =3D RomHeader->PcirOffset; + OffsetPcir =3D RomHeader.PcirOffset; // // If the pointer to the PCI Data Structure is invalid, no further ima= ges can be located.=20 // The PCI Data Structure must be DWORD aligned.=20 @@ -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 f= urther images can be located. // - if (RomPcir->Signature !=3D PCI_DATA_STRUCTURE_SIGNATURE) { + if (RomPcir.Signature !=3D PCI_DATA_STRUCTURE_SIGNATURE) { break; } - if (RomImageSize + RomPcir->ImageLength * 512 > RomSize) { + if (RomImageSize + RomPcir.ImageLength * 512 > RomSize) { break; } - if (RomPcir->CodeType =3D=3D PCI_CODE_TYPE_PCAT_IMAGE) { + if (RomPcir.CodeType =3D=3D PCI_CODE_TYPE_PCAT_IMAGE) { CodeType =3D PCI_CODE_TYPE_PCAT_IMAGE; - LegacyImageLength =3D ((UINT32)((EFI_LEGACY_EXPANSION_ROM_HEADER *)R= omHeader)->Size512) * 512; + LegacyImageLength =3D ((UINT32)((EFI_LEGACY_EXPANSION_ROM_HEADER *)&= RomHeader)->Size512) * 512; } - Indicator =3D RomPcir->Indicator; - RomImageSize =3D RomImageSize + RomPcir->ImageLength * 512; - RomBarOffset =3D RomBarOffset + RomPcir->ImageLength * 512; + Indicator =3D RomPcir.Indicator; + RomImageSize =3D RomImageSize + RomPcir.ImageLength * 512; + RomBarOffset =3D RomBarOffset + RomPcir.ImageLength * 512; } while (((Indicator & 0x80) =3D=3D 0x00) && ((RomBarOffset - RomBar) < = RomSize)); =20 // @@ -517,8 +505,6 @@ LoadOpRomImage ( Image =3D AllocatePool ((UINT32) RomImageSize); if (Image =3D=3D NULL) { RomDecode (PciDevice, RomBarIndex, RomBar, FALSE); - FreePool (RomHeader); - FreePool (RomPcir); return EFI_OUT_OF_RESOURCES; } =20 @@ -555,12 +541,6 @@ LoadOpRomImage ( PciDevice->PciIo.RomSize ); =20 - // - // Free allocated memory - // - FreePool (RomHeader); - FreePool (RomPcir); - return RetStatus; } =20 --=20 2.7.4