[edk2] [PATCH 1/6] OvmfPkg/AcpiPlatformDxe: drop double right shift in ADD/WRITE POINTER cmds

Laszlo Ersek posted 6 patches 7 years, 8 months ago
[edk2] [PATCH 1/6] OvmfPkg/AcpiPlatformDxe: drop double right shift in ADD/WRITE POINTER cmds
Posted by Laszlo Ersek 7 years, 8 months ago
The Count parameter of RShiftU64() must be strictly smaller than 64.
ProcessCmdAddPointer() and ProcessCmdWritePointer() currently ensure this
by "cleverly" breaking the last bit of a potentially 8-byte right shift
out to a separate operation.

Instead, exclude the Count==64 case explicitly (in which case the
preexistent outer RShiftU64() would return 0), and keep only the inner
RShiftU64(), with the direct Count however.

This is not a functional change, just style improvement.

Cc: Jordan Justen <jordan.l.justen@intel.com>
Suggested-by: Jordan Justen <jordan.l.justen@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c b/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c
index eadd690bef4e..6a0ecd1ad962 100644
--- a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c
+++ b/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c
@@ -277,8 +277,8 @@ ProcessCmdAddPointer (
   ASSERT ((UINTN)Blob2->Base <= MAX_ADDRESS - Blob2->Size);
 
   PointerValue += (UINT64)(UINTN)Blob2->Base;
-  if (RShiftU64 (
-        RShiftU64 (PointerValue, AddPointer->PointerSize * 8 - 1), 1) != 0) {
+  if (AddPointer->PointerSize < 8 &&
+      RShiftU64 (PointerValue, AddPointer->PointerSize * 8) != 0) {
     DEBUG ((EFI_D_ERROR, "%a: relocated pointer value unrepresentable in "
       "\"%a\"\n", __FUNCTION__, AddPointer->PointerFile));
     return EFI_PROTOCOL_ERROR;
@@ -438,8 +438,8 @@ ProcessCmdWritePointer (
   ASSERT ((UINTN)PointeeBlob->Base <= MAX_ADDRESS - PointeeBlob->Size);
 
   PointerValue += (UINT64)(UINTN)PointeeBlob->Base;
-  if (RShiftU64 (
-        RShiftU64 (PointerValue, WritePointer->PointerSize * 8 - 1), 1) != 0) {
+  if (WritePointer->PointerSize < 8 &&
+      RShiftU64 (PointerValue, WritePointer->PointerSize * 8) != 0) {
     DEBUG ((DEBUG_ERROR, "%a: pointer value unrepresentable in \"%a\"\n",
       __FUNCTION__, WritePointer->PointerFile));
     return EFI_PROTOCOL_ERROR;
-- 
2.9.3


_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel