]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPg: flash driver: fix type of EFI_SIZE_TO_PAGES argument (VS2010)
authorLaszlo Ersek <lersek@redhat.com>
Fri, 14 Nov 2014 10:23:21 +0000 (10:23 +0000)
committerlersek <lersek@Edk2>
Fri, 14 Nov 2014 10:23:21 +0000 (10:23 +0000)
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>
Build-tested-by: Scott Duplichan <scott@notabs.org>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16382 6f19259b-4bc3-4df7-8a09-765794883524

OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c

index b56ece3931ed6693b73c9bc17b95e72c94bee7fd..42060c84cf0d126c169b25675f5862a28b45e587 100644 (file)
@@ -895,7 +895,7 @@ STATIC
 EFI_STATUS\r
 MarkMemoryRangeForRuntimeAccess (\r
   EFI_PHYSICAL_ADDRESS                BaseAddress,\r
 EFI_STATUS\r
 MarkMemoryRangeForRuntimeAccess (\r
   EFI_PHYSICAL_ADDRESS                BaseAddress,\r
-  UINT64                              Length\r
+  UINT                              Length\r
   )\r
 {\r
   EFI_STATUS                          Status;\r
   )\r
 {\r
   EFI_STATUS                          Status;\r
@@ -919,7 +919,7 @@ MarkMemoryRangeForRuntimeAccess (
   Status = gBS->AllocatePages (\r
                   AllocateAddress,\r
                   EfiRuntimeServicesData,\r
   Status = gBS->AllocatePages (\r
                   AllocateAddress,\r
                   EfiRuntimeServicesData,\r
-                  (UINTN) EFI_SIZE_TO_PAGES (Length),\r
+                  EFI_SIZE_TO_PAGES (Length),\r
                   &BaseAddress\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
                   &BaseAddress\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
@@ -1026,7 +1026,7 @@ Returns:
   EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL  *OldFwbInterface;\r
   UINT32                              MaxLbaSize;\r
   EFI_PHYSICAL_ADDRESS                BaseAddress;\r
   EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL  *OldFwbInterface;\r
   UINT32                              MaxLbaSize;\r
   EFI_PHYSICAL_ADDRESS                BaseAddress;\r
-  UINT64                              Length;\r
+  UINT                              Length;\r
   UINTN                               NumOfBlocks;\r
   EFI_EVENT                           VirtualAddressChangeEvent;\r
 \r
   UINTN                               NumOfBlocks;\r
   EFI_EVENT                           VirtualAddressChangeEvent;\r
 \r