public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] UefiCpuPkg/MtrrLib: Avoid running unnecessary code
@ 2017-04-17  4:56 Ruiyu Ni
  2017-04-17  4:58 ` Wu, Hao A
  0 siblings, 1 reply; 2+ messages in thread
From: Ruiyu Ni @ 2017-04-17  4:56 UTC (permalink / raw)
  To: edk2-devel; +Cc: Hao A Wu

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
---
 UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 35 +++++++++++++++++++----------------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
index c38191a..9d19272 100644
--- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
+++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
@@ -1536,6 +1536,7 @@ MtrrLibAddVariableMtrr (
 
   MTRR_LIB_ASSERT_ALIGNED (BaseAddress, Length);
   if (Type == CacheInvalid) {
+    ASSERT (Ranges != NULL);
     for (Index = 0; Index < RangeCount; Index++) {
       if (Ranges[Index].BaseAddress <= BaseAddress && BaseAddress < Ranges[Index].BaseAddress + Ranges[Index].Length) {
 
@@ -2027,25 +2028,27 @@ MtrrSetMemoryAttributeWorker (
   ASSERT (OriginalVariableMtrrCount - FreeVariableMtrrCount <= FirmwareVariableMtrrCount);
 
   //
-  // Move MTRRs after the FirmwraeVariableMtrrCount position to beginning
+  // Move MTRRs after the FirmwareVariableMtrrCount position to beginning
   //
-  WorkingIndex = FirmwareVariableMtrrCount;
-  for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {
-    if (!OriginalVariableMtrr[Index].Valid) {
-      //
-      // Found an empty MTRR in WorkingIndex position
-      //
-      for (; WorkingIndex < OriginalVariableMtrrCount; WorkingIndex++) {
-        if (OriginalVariableMtrr[WorkingIndex].Valid) {
-          break;
+  if (FirmwareVariableMtrrCount < OriginalVariableMtrrCount) {
+    WorkingIndex = FirmwareVariableMtrrCount;
+    for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {
+      if (!OriginalVariableMtrr[Index].Valid) {
+        //
+        // Found an empty MTRR in WorkingIndex position
+        //
+        for (; WorkingIndex < OriginalVariableMtrrCount; WorkingIndex++) {
+          if (OriginalVariableMtrr[WorkingIndex].Valid) {
+            break;
+          }
         }
-      }
 
-      if (WorkingIndex != OriginalVariableMtrrCount) {
-        CopyMem (&OriginalVariableMtrr[Index], &OriginalVariableMtrr[WorkingIndex], sizeof (VARIABLE_MTRR));
-        VariableSettingModified[Index] = TRUE;
-        VariableSettingModified[WorkingIndex] = TRUE;
-        OriginalVariableMtrr[WorkingIndex].Valid = FALSE;
+        if (WorkingIndex != OriginalVariableMtrrCount) {
+          CopyMem (&OriginalVariableMtrr[Index], &OriginalVariableMtrr[WorkingIndex], sizeof (VARIABLE_MTRR));
+          VariableSettingModified[Index] = TRUE;
+          VariableSettingModified[WorkingIndex] = TRUE;
+          OriginalVariableMtrr[WorkingIndex].Valid = FALSE;
+        }
       }
     }
   }
-- 
2.9.0.windows.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-04-17  4:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-17  4:56 [PATCH] UefiCpuPkg/MtrrLib: Avoid running unnecessary code Ruiyu Ni
2017-04-17  4:58 ` Wu, Hao A

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox