Though CopyMem() copies nothing when Length equals to 0, I agree this patch to totally skip the CopyMem() call.
Reviewed-by: Ray Ni <ray...@intel.com> > -----Original Message----- > From: Mark Wilson <mark.wil...@amd.com> > Sent: Friday, November 13, 2020 8:05 AM > To: devel@edk2.groups.io > Cc: Dong, Eric <eric.d...@intel.com>; Ni, Ray <ray...@intel.com> > Subject: [PATCH v3 1/1] UefiCpuPkg: Clean up save state boundary checks and > comments. > > 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. > > Cc: Eric Dong <eric.d...@intel.com> > Cc: Ray Ni <ray...@intel.com> > Signed-off-by: Mark Wilson <mark.wil...@amd.com> > --- > UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c | 12 ++++++------ > 1 file changed, 6 insertions(+), 6 deletions(-) > > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c > b/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c > index 661cc51f361a..0ab5e1ba0f14 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c > @@ -315,12 +315,12 @@ 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) { > > + 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); > > } > > @@ -539,12 +539,12 @@ 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) { > > + 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); > > } > > -- > 2.28.0.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#79859): https://edk2.groups.io/g/devel/message/79859 Mute This Topic: https://groups.io/mt/78219846/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-