[edk2-devel] [PATCH 2/2] EmbeddedPkg/TimeBaseLib: remove useless truncation to 32-bit

Laszlo Ersek lersek at redhat.com
Mon Dec 21 11:36:57 UTC 2020


EfiTimeToEpoch() calls EfiGetEpochDays() internally, which (reasonably)
returns a UINTN. But then EfiTimeToEpoch() truncates the EfiGetEpochDays()
retval to UINT32 for no good reason, effectively restricting Time->Year
under 2106.

This truncation was pointed out with a valid warning (= build error) by
VS2019.

Allow EfiTimeToEpoch() to return / propagate a UINTN value.

Cc: Ard Biesheuvel <ard.biesheuvel at arm.com>
Cc: Leif Lindholm <leif at nuviainc.com>
Cc: Philippe Mathieu-Daudé <philmd at redhat.com>
Signed-off-by: Laszlo Ersek <lersek at redhat.com>
---

Notes:
    This patch may only be committed after the edk2-platforms patch
    "Silicon/Marvell/RealTimeClockLib: make EpochSeconds, WakeupSeconds
    UINTN".

 EmbeddedPkg/Include/Library/TimeBaseLib.h     | 2 +-
 EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/EmbeddedPkg/Include/Library/TimeBaseLib.h b/EmbeddedPkg/Include/Library/TimeBaseLib.h
index 3c2d3660c66c..90853c3f4b93 100644
--- a/EmbeddedPkg/Include/Library/TimeBaseLib.h
+++ b/EmbeddedPkg/Include/Library/TimeBaseLib.h
@@ -83,7 +83,7 @@ EpochToEfiTime (
 /**
   Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC)
  **/
-UINT32
+UINTN
 EFIAPI
 EfiTimeToEpoch (
   IN  EFI_TIME  *Time
diff --git a/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c b/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
index 136ce8a51e86..78fc7b6cd2e5 100644
--- a/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
+++ b/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
@@ -97,24 +97,24 @@ EfiGetEpochDays (
   return EpochDays;
 }
 /**
   Converts EFI_TIME to Epoch seconds (elapsed since 1970 JANUARY 01, 00:00:00 UTC)
  **/
-UINT32
+UINTN
 EFIAPI
 EfiTimeToEpoch (
   IN  EFI_TIME  *Time
   )
 {
-  UINT32 EpochDays;   // Number of days elapsed since EPOCH_JULIAN_DAY
-  UINT32 EpochSeconds;
+  UINTN EpochDays;   // Number of days elapsed since EPOCH_JULIAN_DAY
+  UINTN EpochSeconds;
 
   EpochDays = EfiGetEpochDays (Time);
 
   EpochSeconds = (EpochDays * SEC_PER_DAY) + ((UINTN)Time->Hour * SEC_PER_HOUR) + (Time->Minute * SEC_PER_MIN) + Time->Second;
 
   return EpochSeconds;
 }
 
 /**
   returns Day of the week [0-6] 0=Sunday
  **/
-- 
2.19.1.3.g30247aa5d201



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#69315): https://edk2.groups.io/g/devel/message/69315
Mute This Topic: https://groups.io/mt/79123604/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-






More information about the edk2-devel-archive mailing list