.../RegisterCpuFeaturesLib/CpuFeaturesInitialize.c | 55 +++++----------------- 1 file changed, 11 insertions(+), 44 deletions(-)
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 <ruiyu.ni@intel.com>
Cc: Shao Ming <ming.shao@intel.com>
Cc: Kinney Michael D <michael.d.kinney@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Eric Dong <eric.dong@intel.com>
---
.../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
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
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 <ruiyu.ni@intel.com>; Shao, Ming
> <ming.shao@intel.com>; Kinney, Michael D
> <michael.d.kinney@intel.com>
> Subject: [Patch] UefiCpuPkg RegisterCpuFeaturesLib: Fix buffer
> pointer error usage.
>
> 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 <ruiyu.ni@intel.com>
> Cc: Shao Ming <ming.shao@intel.com>
> Cc: Kinney Michael D <michael.d.kinney@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Eric Dong <eric.dong@intel.com>
> ---
> .../RegisterCpuFeaturesLib/CpuFeaturesInitialize.c | 55 +++++--
> ---------------
> 1 file changed, 11 insertions(+), 44 deletions(-)
>
> 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 (
> }
>
> /**
> - 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
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
© 2016 - 2025 Red Hat, Inc.