[edk2] [PATCH 3/7] OvmfPkg: flash driver: drop needlessly wide multiplication (VS2010)

Subject: [edk2] [PATCH 3/7] OvmfPkg: flash driver: drop needlessly wide multiplication (VS2010)

From: Laszlo Ersek <lersek@redhat.com>

To: edk2-devel@lists.sourceforge.net, jordan.l.justen@intel.com, scott@notabs.org, qin.long@intel.com

Date: 2014-11-12 23:03:57

  • 2014-11-12 23:03:57  Laszlo Ersek   [edk2] [PATCH 3/7] OvmfPkg: flash driver: drop needlessly wide multiplication (VS2010)
From: Scott Duplichan 

The current types of subexpressions used in QemuFlashPtr() are as follows.
(We also show the types of "larger" subexpressions, according to operator
binding.)

  mFlashBase + (Lba * mFdBlockSize) + Offset
      ^          ^         ^            ^
      |          |         |            |
   (UINT8*)   EFI_LBA    UINTN        UINTN
              (UINT64)

  ---------------------------------   ------
              (UINT8*)                UINTN

  ------------------------------------------
                    (UINT8*)

When building with VS2010 for Ia32 / NOOPT, the 64-by-32 bit
multiplication is translated to an intrinsic, which is not allowed in
edk2.

Recognize that "Lba" is always bounded by "mFdBlockCount" (an UINTN) here
-- all callers of QemuFlashPtr() ensure that. In addition, the flash chip
in question is always under 4GB, which is why we can address it at all on
Ia32. Narrow "Lba" to UINTN, without any loss of range.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Scott Duplichan 
[commit message by lersek@redhat.com]
Signed-off-by: Laszlo Ersek 

Signed-off-by: Laszlo Ersek 
---
 OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c
index f9c6f5c..a96e0e5 100644
--- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c
+++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c
@@ -54,7 +54,7 @@ QemuFlashPtr (
   IN        UINTN                               Offset
   )
 {
-  return mFlashBase + (Lba * mFdBlockSize) + Offset;
+  return mFlashBase + ((UINTN)Lba * mFdBlockSize) + Offset;
 }
 
 
-- 
1.8.3.1



------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel