From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 211DF21E2DA54 for ; Tue, 15 Aug 2017 19:38:16 -0700 (PDT) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Aug 2017 19:40:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,380,1498546800"; d="scan'208";a="137981580" Received: from orsmsx107.amr.corp.intel.com ([10.22.240.5]) by orsmga005.jf.intel.com with ESMTP; 15 Aug 2017 19:40:41 -0700 Received: from orsmsx157.amr.corp.intel.com (10.22.240.23) by ORSMSX107.amr.corp.intel.com (10.22.240.5) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 15 Aug 2017 19:40:40 -0700 Received: from orsmsx113.amr.corp.intel.com ([169.254.9.211]) by ORSMSX157.amr.corp.intel.com ([169.254.9.80]) with mapi id 14.03.0319.002; Tue, 15 Aug 2017 19:40:40 -0700 From: "Kinney, Michael D" To: "Dong, Eric" , "edk2-devel@lists.01.org" , "Kinney, Michael D" CC: "Ni, Ruiyu" , "Shao, Ming" Thread-Topic: [Patch] UefiCpuPkg RegisterCpuFeaturesLib: Fix buffer pointer error usage. Thread-Index: AQHTFit/7htN4mwiiUuhvk4ZkOL2HKKGRU4A Date: Wed, 16 Aug 2017 02:40:39 +0000 Message-ID: References: <1502845412-10856-1-git-send-email-eric.dong@intel.com> In-Reply-To: <1502845412-10856-1-git-send-email-eric.dong@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 10.0.102.7 dlp-reaction: no-action x-originating-ip: [10.22.254.138] MIME-Version: 1.0 Subject: Re: [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 02:38:16 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Eric, I think we should keep the Getxxx() functions to make the code easier to read and we have matched Get/Set functions to access these PCDs. Mike > -----Original Message----- > From: Dong, Eric > Sent: Tuesday, August 15, 2017 6:04 PM > To: edk2-devel@lists.01.org > Cc: Ni, Ruiyu ; Shao, Ming > ; Kinney, Michael D > > Subject: [Patch] UefiCpuPkg RegisterCpuFeaturesLib: Fix buffer > pointer error usage. >=20 > Current code allocate buffer for the pointer which later get > value > from PCD database. but current code error use "=3D" for this case. > Use AllocateCopyPool instead to fix it. >=20 > V2 enhanced to directly use AllocateCopyPool to get the PCD > value. > V3 enhanced to avoid using local temp variable. >=20 > 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(-) >=20 > diff --git > a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitializ > e.c > b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitializ > e.c > index 474aea3..a7e1852 100644 > --- > a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitializ > e.c > +++ > b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitializ > e.c > @@ -51,48 +51,6 @@ SetSettingPcd ( > } >=20 > /** > - Worker function to get PcdCpuFeaturesSupport. > - > - @return The pointer to CPU feature bits mask buffer. > -**/ > -UINT8 * > -GetSupportPcds ( > - VOID > - ) > -{ > - UINTN BitMaskSize; > - UINT8 *SupportBitMask; > - > - BitMaskSize =3D PcdGetSize (PcdCpuFeaturesSupport); > - SupportBitMask =3D AllocateZeroPool (BitMaskSize); > - ASSERT (SupportBitMask !=3D NULL); > - SupportBitMask =3D (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 =3D PcdGetSize (PcdCpuFeaturesUserConfiguration); > - SupportBitMask =3D AllocateZeroPool (BitMaskSize); > - ASSERT (SupportBitMask !=3D NULL); > - SupportBitMask =3D (UINT8 *) PcdGetPtr > (PcdCpuFeaturesUserConfiguration); > - > - return SupportBitMask; > -} > - > -/** > Collects CPU type and feature information. >=20 > @param[in, out] CpuInfo The pointer to CPU feature > information > @@ -180,8 +138,17 @@ CpuInitDataInitialize ( > // > // Get support and configuration PCDs > // > - CpuFeaturesData->SupportPcds =3D GetSupportPcds (); > - CpuFeaturesData->ConfigurationPcds =3D GetConfigurationPcds (); > + CpuFeaturesData->SupportPcds =3D AllocateCopyPool ( > + PcdGetSize (PcdCpuFeaturesSupport), > + PcdGetPtr (PcdCpuFeaturesSupport) > + ); > + ASSERT (CpuFeaturesData->SupportPcds !=3D NULL); > + > + CpuFeaturesData->ConfigurationPcds =3D AllocateCopyPool ( > + PcdGetSize (PcdCpuFeaturesUserConfiguration), > + PcdGetPtr (PcdCpuFeaturesUserConfiguration) > + ); > + ASSERT (CpuFeaturesData->ConfigurationPcds !=3D NULL); > } >=20 > /** > -- > 2.7.0.windows.1