public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Mark Wilson <Mark.Wilson@amd.com>
To: devel@edk2.groups.io
Cc: Mark Wilson <Mark.Wilson@amd.com>,
	Eric Dong <eric.dong@intel.com>, Ray Ni <ray.ni@intel.com>
Subject: [PATCH v1 1/1] UefiCpuPkg: Clean up save state boundary checks and comments.
Date: Thu, 15 Oct 2020 11:32:43 -0500	[thread overview]
Message-ID: <20201015163243.364-2-Mark.Wilson@amd.com> (raw)
In-Reply-To: <20201015163243.364-1-Mark.Wilson@amd.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2956

In functions ReadSaveStateRegisterByIndex and WriteSaveStateRegister:
* check width > 4 instead of >= 4 when writing upper 32 bytes.
  - This improves the code but will not affect functionality.
* Update related comments to better describe code.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Mark Wilson <Mark.Wilson@amd.com>
---
 UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c | 26 ++++++++++----------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c b/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c
index 661cc51f361a..4a872e400b7a 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c
@@ -297,8 +297,8 @@ ReadSaveStateRegisterByIndex (
     //
     // Write return buffer
     //
-    ASSERT(CpuSaveState != NULL);
-    CopyMem(Buffer, (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset32, Width);
+    ASSERT (CpuSaveState != NULL);
+    CopyMem (Buffer, (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset32, Width);
   } else {
     //
     // If 64-bit mode width is zero, then the specified register can not be accessed
@@ -315,14 +315,14 @@ ReadSaveStateRegisterByIndex (
     }
 
     //
-    // Write lower 32-bits of return buffer
+    // Write at most 4 of the lower bytes of the return buffer
     //
-    CopyMem(Buffer, (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset64Lo, MIN(4, Width));
-    if (Width >= 4) {
+    CopyMem (Buffer, (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset64Lo, MIN(4, Width));
+    if (Width > 4) {
       //
-      // Write upper 32-bits of return buffer
+      // Write at most 4 of the upper bytes of the return buffer
       //
-      CopyMem((UINT8 *)Buffer + 4, (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset64Hi, Width - 4);
+      CopyMem ((UINT8 *)Buffer + 4, (UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset64Hi, Width - 4);
     }
   }
   return EFI_SUCCESS;
@@ -522,7 +522,7 @@ WriteSaveStateRegister (
     // Write SMM State register
     //
     ASSERT (CpuSaveState != NULL);
-    CopyMem((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset32, Buffer, Width);
+    CopyMem ((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset32, Buffer, Width);
   } else {
     //
     // If 64-bit mode width is zero, then the specified register can not be accessed
@@ -539,14 +539,14 @@ WriteSaveStateRegister (
     }
 
     //
-    // Write lower 32-bits of SMM State register
+    // Write at most 4 of the lower bytes of SMM State register
     //
-    CopyMem((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset64Lo, Buffer, MIN (4, Width));
-    if (Width >= 4) {
+    CopyMem ((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset64Lo, Buffer, MIN (4, Width));
+    if (Width > 4) {
       //
-      // Write upper 32-bits of SMM State register
+      // Write at most 4 of the upper bytes of SMM State register
       //
-      CopyMem((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset64Hi, (UINT8 *)Buffer + 4, Width - 4);
+      CopyMem ((UINT8 *)CpuSaveState + mSmmCpuWidthOffset[RegisterIndex].Offset64Hi, (UINT8 *)Buffer + 4, Width - 4);
     }
   }
   return EFI_SUCCESS;
-- 
2.27.0.windows.1


  reply	other threads:[~2020-10-15 16:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-15 16:32 [PATCH v1 0/1] Clean up save state boundary checks and comments in functions ReadSaveStateRegisterByIndex and WriteSaveStateRegister Mark Wilson
2020-10-15 16:32 ` Mark Wilson [this message]
2020-10-19 18:03   ` [edk2-devel] [PATCH v1 1/1] UefiCpuPkg: Clean up save state boundary checks and comments Laszlo Ersek
2020-10-19 18:06     ` Laszlo Ersek
2020-11-11 16:20       ` Mark Wilson
2020-11-11 22:37         ` Laszlo Ersek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201015163243.364-2-Mark.Wilson@amd.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox