From 4ef6c3850e66617df1ed35a4a390567d2bbf6b76 Mon Sep 17 00:00:00 2001 From: Ruiyu Ni Date: Fri, 31 Mar 2017 22:04:17 +0800 Subject: [PATCH] UefiCpuPkg/MtrrLib: Fix GCC build failure Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni --- UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c index 524f21e842..8e8427291f 100644 --- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c +++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c @@ -836,7 +836,7 @@ MtrrLibGetMtrrNumber ( IN UINT64 Alignment0, OUT UINT32 *SubLeft, // subtractive from BaseAddress to get more aligned address, to save MTRR OUT UINT32 *SubRight // subtractive from BaseAddress + Length, to save MTRR -) + ) { UINT64 Alignment; UINT32 LeastLeftMtrrNumber; @@ -859,6 +859,8 @@ MtrrLibGetMtrrNumber ( // Get the optimal left subtraction solution. // if (BaseAddress != 0) { + SubtractiveBaseAddress = 0; + SubtractiveLength = 0; // // Get the MTRR number needed without left subtraction. // @@ -1371,6 +1373,8 @@ MtrrLibSetMemoryType ( UINT32 EndIndex; UINT32 DeltaCount; + LengthRight = 0; + LengthLeft = 0; Limit = BaseAddress + Length; StartIndex = *Count; EndIndex = *Count; @@ -1847,6 +1851,8 @@ MtrrSetMemoryAttributeWorker ( if (((BaseAddress & ~MtrrValidAddressMask) != 0) || (Length & ~MtrrValidAddressMask) != 0) { return RETURN_UNSUPPORTED; } + OriginalVariableMtrrCount = 0; + VariableSettings = NULL; ZeroMem (&WorkingFixedSettings, sizeof (WorkingFixedSettings)); for (Index = 0; Index < MTRR_NUMBER_OF_FIXED_MTRR; Index++) { @@ -2048,7 +2054,7 @@ MtrrSetMemoryAttributeWorker ( if (VariableSettingModified[Index]) { if (OriginalVariableMtrr[Index].Valid) { VariableSettings->Mtrr[Index].Base = (OriginalVariableMtrr[Index].BaseAddress & MtrrValidAddressMask) | (UINT8) OriginalVariableMtrr[Index].Type; - VariableSettings->Mtrr[Index].Mask = (~(OriginalVariableMtrr[Index].Length - 1)) & MtrrValidAddressMask | BIT11; + VariableSettings->Mtrr[Index].Mask = ((~(OriginalVariableMtrr[Index].Length - 1)) & MtrrValidAddressMask) | BIT11; } else { VariableSettings->Mtrr[Index].Base = 0; VariableSettings->Mtrr[Index].Mask = 0; @@ -2081,6 +2087,8 @@ Done: // // Write variable MTRRs + // When only fixed MTRRs were changed, below loop doesn't run + // because OriginalVariableMtrrCount equals to 0. // for (Index = 0; Index < OriginalVariableMtrrCount; Index++) { if (VariableSettingModified[Index]) { @@ -2102,7 +2110,7 @@ Done: MtrrLibPostMtrrChange (&MtrrContext); } - return Status; + return RETURN_SUCCESS; } /** -- 2.39.2