From cb9bdf37532e8b75c38bd4874f9c797d7f66ed30 Mon Sep 17 00:00:00 2001 From: Ashraf Ali Date: Wed, 14 Aug 2024 23:16:29 +0530 Subject: [PATCH] SecurityPkg: Optimization by moving PeiServicesLocatePpi outside loop This update refactors the code by moving the LocatePpi function call outside of the for loop where it was previously called repeatedly. By relocating the LocatePpi invocation outside of the loop, we improve the efficiency of the code by avoiding redundant lookups. Signed-off-by: Ashraf Ali --- SecurityPkg/FvReportPei/FvReportPei.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/SecurityPkg/FvReportPei/FvReportPei.c b/SecurityPkg/FvReportPei/FvReportPei.c index 6288dde16b..50773db056 100644 --- a/SecurityPkg/FvReportPei/FvReportPei.c +++ b/SecurityPkg/FvReportPei/FvReportPei.c @@ -150,6 +150,16 @@ VerifyHashedFv ( HashValue = AllocateZeroPool (AlgInfo->HashSize * (FvNumber + 1)); ASSERT (HashValue != NULL); + Status = PeiServicesLocatePpi ( + &gEdkiiPeiFirmwareVolumeShadowPpiGuid, + 0, + NULL, + (VOID **)&FvShadowPpi + ); + if (EFI_ERROR (Status)) { + FvShadowPpi = NULL; + } + // // Calculate hash value for each FV first. // @@ -194,14 +204,8 @@ VerifyHashedFv ( FvBuffer = AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)FvInfo[FvIndex].Length)); ASSERT (FvBuffer != NULL); - Status = PeiServicesLocatePpi ( - &gEdkiiPeiFirmwareVolumeShadowPpiGuid, - 0, - NULL, - (VOID **)&FvShadowPpi - ); - if (!EFI_ERROR (Status)) { + if (FvShadowPpi != NULL) { Status = FvShadowPpi->FirmwareVolumeShadow ( (EFI_PHYSICAL_ADDRESS)FvInfo[FvIndex].Base, FvBuffer, @@ -209,7 +213,7 @@ VerifyHashedFv ( ); } - if (EFI_ERROR (Status)) { + if ((FvShadowPpi == NULL) || (EFI_ERROR (Status))) { CopyMem ( FvBuffer, (CONST VOID *)(UINTN)FvInfo[FvIndex].Base,