diff mbox

[edk2,v2,1/7] OvmfPg: flash driver: fix type of EFI_SIZE_TO_PAGES argument (VS2010)

Message ID 1415877385-18341-2-git-send-email-lersek@redhat.com
State New
Headers show

Commit Message

Laszlo Ersek Nov. 13, 2014, 11:16 a.m. UTC
The MarkMemoryRangeForRuntimeAccess() function passes the Length parameter
(of type UINT64) to the macro EFI_SIZE_TO_PAGES(). When building for the
Ia32 platform, this violates the interface contract of the macro:

    [...] Passing in a parameter that is larger than UINTN may produce
    unexpected results.

In addition, it trips up compilation by VS2010 for the Ia32 platform and
the NOOPT target -- it generates calls to intrinsics, which are not
allowed in edk2.

Fix both issues with the following steps:

(1) Demote the Length parameter of MarkMemoryRangeForRuntimeAccess() to
UINTN. Even a UINT32 value is plenty for representing the size of the
flash chip holding the variable store. Length parameter is used in the
following contexts:
- passed to gDS->RemoveMemorySpace() -- takes an UINT64
- passed to gDS->AddMemorySpace() -- ditto
- passed to EFI_SIZE_TO_PAGES() -- requires an UINTN. This also guarantees
  that the return type of EFI_SIZE_TO_PAGES() will be UINTN, hence we can
  drop the outer cast.

(2) The only caller of MarkMemoryRangeForRuntimeAccess() is
FvbInitialize(). The latter function populates the local Length variable
(passed to MarkMemoryRangeForRuntimeAccess()) from
PcdGet32(PcdOvmfFirmwareFdSize). Therefore we can simply demote the local
variable to UINTN in this function as well.
- There's only one other use of Length in FvbInitialize(): it is passed to
  GetFvbInfo(). GetFvbInfo() takes an UINT64, so passing an UINTN is fine.

Suggested-by: Scott Duplichan <scott@notabs.org>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c
index b56ece3..42060c8 100644
--- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c
+++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c
@@ -895,7 +895,7 @@  STATIC
 EFI_STATUS
 MarkMemoryRangeForRuntimeAccess (
   EFI_PHYSICAL_ADDRESS                BaseAddress,
-  UINT64                              Length
+  UINTN                               Length
   )
 {
   EFI_STATUS                          Status;
@@ -919,7 +919,7 @@  MarkMemoryRangeForRuntimeAccess (
   Status = gBS->AllocatePages (
                   AllocateAddress,
                   EfiRuntimeServicesData,
-                  (UINTN) EFI_SIZE_TO_PAGES (Length),
+                  EFI_SIZE_TO_PAGES (Length),
                   &BaseAddress
                   );
   ASSERT_EFI_ERROR (Status);
@@ -1026,7 +1026,7 @@  Returns:
   EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL  *OldFwbInterface;
   UINT32                              MaxLbaSize;
   EFI_PHYSICAL_ADDRESS                BaseAddress;
-  UINT64                              Length;
+  UINTN                               Length;
   UINTN                               NumOfBlocks;
   EFI_EVENT                           VirtualAddressChangeEvent;