From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 98A4621E2DA5A for ; Tue, 15 Aug 2017 18:01:11 -0700 (PDT) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga104.jf.intel.com with ESMTP; 15 Aug 2017 18:03:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,380,1498546800"; d="scan'208";a="137961478" Received: from ydong10-win10.ccr.corp.intel.com ([10.239.158.51]) by orsmga005.jf.intel.com with ESMTP; 15 Aug 2017 18:03:35 -0700 From: Eric Dong To: edk2-devel@lists.01.org Cc: Ruiyu Ni , Shao Ming , Kinney Michael D Date: Wed, 16 Aug 2017 09:03:32 +0800 Message-Id: <1502845412-10856-1-git-send-email-eric.dong@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 Subject: [Patch] UefiCpuPkg RegisterCpuFeaturesLib: Fix buffer pointer error usage. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Aug 2017 01:01:11 -0000 Current code allocate buffer for the pointer which later get value from PCD database. but current code error use "=" for this case. Use AllocateCopyPool instead to fix it. V2 enhanced to directly use AllocateCopyPool to get the PCD value. V3 enhanced to avoid using local temp variable. Cc: Ruiyu Ni Cc: Shao Ming Cc: Kinney Michael D Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Eric Dong --- .../RegisterCpuFeaturesLib/CpuFeaturesInitialize.c | 55 +++++----------------- 1 file changed, 11 insertions(+), 44 deletions(-) diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c index 474aea3..a7e1852 100644 --- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c @@ -51,48 +51,6 @@ SetSettingPcd ( } /** - Worker function to get PcdCpuFeaturesSupport. - - @return The pointer to CPU feature bits mask buffer. -**/ -UINT8 * -GetSupportPcds ( - VOID - ) -{ - UINTN BitMaskSize; - UINT8 *SupportBitMask; - - BitMaskSize = PcdGetSize (PcdCpuFeaturesSupport); - SupportBitMask = AllocateZeroPool (BitMaskSize); - ASSERT (SupportBitMask != NULL); - SupportBitMask = (UINT8 *) PcdGetPtr (PcdCpuFeaturesSupport); - - return SupportBitMask; -} - -/** - Worker function to get PcdCpuFeaturesUserConfiguration. - - @return The pointer to CPU feature bits mask buffer. -**/ -UINT8 * -GetConfigurationPcds ( - VOID - ) -{ - UINTN BitMaskSize; - UINT8 *SupportBitMask; - - BitMaskSize = PcdGetSize (PcdCpuFeaturesUserConfiguration); - SupportBitMask = AllocateZeroPool (BitMaskSize); - ASSERT (SupportBitMask != NULL); - SupportBitMask = (UINT8 *) PcdGetPtr (PcdCpuFeaturesUserConfiguration); - - return SupportBitMask; -} - -/** Collects CPU type and feature information. @param[in, out] CpuInfo The pointer to CPU feature information @@ -180,8 +138,17 @@ CpuInitDataInitialize ( // // Get support and configuration PCDs // - CpuFeaturesData->SupportPcds = GetSupportPcds (); - CpuFeaturesData->ConfigurationPcds = GetConfigurationPcds (); + CpuFeaturesData->SupportPcds = AllocateCopyPool ( + PcdGetSize (PcdCpuFeaturesSupport), + PcdGetPtr (PcdCpuFeaturesSupport) + ); + ASSERT (CpuFeaturesData->SupportPcds != NULL); + + CpuFeaturesData->ConfigurationPcds = AllocateCopyPool ( + PcdGetSize (PcdCpuFeaturesUserConfiguration), + PcdGetPtr (PcdCpuFeaturesUserConfiguration) + ); + ASSERT (CpuFeaturesData->ConfigurationPcds != NULL); } /** -- 2.7.0.windows.1