diff --git a/Silicon/NVIDIA/Drivers/FvbNorFlashDxe/VarIntCheck.c b/Silicon/NVIDIA/Drivers/FvbNorFlashDxe/VarIntCheck.c index 53d5fc2aa9..11cd4d4f94 100644 --- a/Silicon/NVIDIA/Drivers/FvbNorFlashDxe/VarIntCheck.c +++ b/Silicon/NVIDIA/Drivers/FvbNorFlashDxe/VarIntCheck.c @@ -483,6 +483,8 @@ GetLastValidMeasurements ( UINT64 StartOffset; UINT64 EndOffset; UINT64 CurOffset; + UINT64 BlockOffset; + UINT64 BlockEnd; UINT64 NumValidRecords; UINT8 *ReadBuf; @@ -499,50 +501,58 @@ GetLastValidMeasurements ( EndOffset = StartOffset + VarInt->PartitionSize; CurOffset = StartOffset; + BlockOffset = CurOffset; + BlockEnd = BlockOffset + VarInt->BlockSize; NumValidRecords = 0; *NumRecords = 0; while (CurOffset < EndOffset) { - Status = NorFlash->Read ( - NorFlash, - CurOffset, - VarInt->MeasurementSize, - ReadBuf - ); - if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "%a: NorFlash Read Failed at %lu offset %r\n", - __FUNCTION__, - CurOffset, - Status - )); - goto ExitGetLastValidMeasuremets; - } - - if ((ReadBuf[0] == VAR_INT_VALID) || - (ReadBuf[0] == VAR_INT_PENDING)) - { - NumValidRecords++; - if (NumValidRecords > MAX_VALID_RECORDS) { + while (BlockOffset < BlockEnd) { + Status = NorFlash->Read ( + NorFlash, + BlockOffset, + VarInt->MeasurementSize, + ReadBuf + ); + if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, - "%a: More than %d Valid measurements found %x\n", + "%a: NorFlash Read Failed at %lu offset %r\n", __FUNCTION__, - MAX_VALID_RECORDS, - ReadBuf[0] + BlockOffset, + Status )); - Status = EFI_DEVICE_ERROR; goto ExitGetLastValidMeasuremets; - } else { - DEBUG ((DEBUG_INFO, "Found Record at %lu Header %x\n", CurOffset, ReadBuf[0])); - CopyMem (Records[(NumValidRecords - 1)]->Measurement, ReadBuf, VarInt->MeasurementSize); - *NumRecords += 1; - Records[(NumValidRecords - 1)]->ByteOffset = CurOffset; } + + if ((ReadBuf[0] == VAR_INT_VALID) || + (ReadBuf[0] == VAR_INT_PENDING)) + { + NumValidRecords++; + if (NumValidRecords > MAX_VALID_RECORDS) { + DEBUG (( + DEBUG_ERROR, + "%a: More than %d Valid measurements found %x\n", + __FUNCTION__, + MAX_VALID_RECORDS, + ReadBuf[0] + )); + Status = EFI_DEVICE_ERROR; + goto ExitGetLastValidMeasuremets; + } else { + DEBUG ((DEBUG_INFO, "Found Record at %lu Header %x\n", BlockOffset, ReadBuf[0])); + CopyMem (Records[(NumValidRecords - 1)]->Measurement, ReadBuf, VarInt->MeasurementSize); + *NumRecords += 1; + Records[(NumValidRecords - 1)]->ByteOffset = BlockOffset; + } + } + + BlockOffset += VarInt->MeasurementSize; } - CurOffset += VarInt->MeasurementSize; + CurOffset += VarInt->BlockSize; + BlockEnd += VarInt->BlockSize; + BlockOffset = CurOffset; } ExitGetLastValidMeasuremets: diff --git a/Silicon/NVIDIA/Library/NvVarIntLibrary/NvVarIntLibrary.c b/Silicon/NVIDIA/Library/NvVarIntLibrary/NvVarIntLibrary.c index 236e68532d..16c239fb55 100644 --- a/Silicon/NVIDIA/Library/NvVarIntLibrary/NvVarIntLibrary.c +++ b/Silicon/NVIDIA/Library/NvVarIntLibrary/NvVarIntLibrary.c @@ -177,9 +177,16 @@ MeasureBootVars ( DEBUG ((DEBUG_INFO, "Adding %s Size %u %p\n", BootOptionName, BootOptionSize, BootOptions[Index])); HashApiUpdate (HashContext, BootOptions[Index], BootOptionSize); + FreePool (BootOptions[Index]); } ExitMeasureBootVars: + + if (BootOptions != NULL) { + FreePool (BootOptions); + BootOptions = NULL; + } + if ((UpdatingBootOrder == TRUE)) { BootOrder = NULL; BootCount = 0; @@ -598,7 +605,6 @@ ComputeVarMeasurement ( ) { EFI_STATUS Status; - UINTN Index; if (HashContext == NULL) { HashContext = AllocateRuntimeZeroPool (HashApiGetContextSize ()); @@ -625,22 +631,12 @@ ComputeVarMeasurement ( Status = EFI_DEVICE_ERROR; } - if ((BootCount != 0) && (BootOptions != NULL)) { - for (Index = 0; Index < BootCount; Index++) { - if (BootOptions[Index] != NULL) { - FreePool (BootOptions[Index]); - } - } - - FreePool (BootOptions); - BootCount = 0; - BootOptions = NULL; - } - if (BootOrder != NULL) { FreePool (BootOrder); } + BootCount = 0; + Status = EFI_SUCCESS; ExitComputeVarMeasurement: