[edk2-devel] [PATCH 1/2] EmbeddedPkg/TimeBaseLib: Add function to check Timezone and Daylight

Leif Lindholm leif at nuviainc.com
Wed Jan 6 13:03:35 UTC 2021


Hi Nhi,

On Wed, Jan 06, 2021 at 17:55:57 +0700, Nhi Pham wrote:
> This adds two functions IsValidTimeZone() and IsValidDaylight() to check
> the time zone and daylight value from EFI time. These functions are
> retrieved from the RealTimeClockRuntimeDxe module as they reduce
> duplicated code in RTC modules.
> 
> Cc: Leif Lindholm <leif at nuviainc.com>
> Cc: Ard Biesheuvel <ard.biesheuvel at arm.com>
> Signed-off-by: Nhi Pham <nhi at os.amperecomputing.com>
> ---
>  EmbeddedPkg/Include/Library/TimeBaseLib.h     | 13 ++++++
>  EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c | 47 ++++++++++++++------
>  2 files changed, 47 insertions(+), 13 deletions(-)
> 
> diff --git a/EmbeddedPkg/Include/Library/TimeBaseLib.h b/EmbeddedPkg/Include/Library/TimeBaseLib.h
> index 90853c3f4b93..8bebf5886db8 100644
> --- a/EmbeddedPkg/Include/Library/TimeBaseLib.h
> +++ b/EmbeddedPkg/Include/Library/TimeBaseLib.h
> @@ -2,6 +2,7 @@
>  *
>  *  Copyright (c) 2016, Hisilicon Limited. All rights reserved.
>  *  Copyright (c) 2016-2019, Linaro Limited. All rights reserved.
> +*  Copyright (c) 2020, Ampere Computing LLC. All rights reserved.

2021? :)

>  *
>  *  SPDX-License-Identifier: BSD-2-Clause-Patent
>  *
> @@ -64,6 +65,18 @@ IsDayValid (
>    IN  EFI_TIME  *Time
>    );
>  
> +BOOLEAN
> +EFIAPI
> +IsValidTimeZone (
> +  IN  INT16  TimeZone
> +  );
> +
> +BOOLEAN
> +EFIAPI
> +IsValidDaylight (
> +  IN  INT8  Daylight
> +  );
> +

Could you please add doxygen comment blocks to these new functions
(and repeat them in the .c)?
I know we've been lax about this in the past, but I would like for us
to start improving (especially in common libraries).

>  BOOLEAN
>  EFIAPI
>  IsTimeValid (
> diff --git a/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c b/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
> index 78fc7b6cd2e5..02d9901338b9 100644
> --- a/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
> +++ b/EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.c
> @@ -2,6 +2,7 @@
>  *
>  *  Copyright (c) 2016, Hisilicon Limited. All rights reserved.
>  *  Copyright (c) 2016-2019, Linaro Limited. All rights reserved.
> +*  Copyright (c) 2020, Ampere Computing LLC. All rights reserved.
>  *
>  *  SPDX-License-Identifier: BSD-2-Clause-Patent
>  *
> @@ -173,23 +174,43 @@ IsDayValid (
>  
>  BOOLEAN
>  EFIAPI
> -IsTimeValid(
> +IsValidTimeZone (
> +  IN  INT16  TimeZone
> +  )
> +{
> +  return TimeZone == EFI_UNSPECIFIED_TIMEZONE ||
> +         (TimeZone >= -1440 && TimeZone <= 1440);
> +}
> +
> +BOOLEAN
> +EFIAPI
> +IsValidDaylight (
> +  IN  INT8  Daylight
> +  )
> +{
> +  return Daylight == 0 ||
> +         Daylight == EFI_TIME_ADJUST_DAYLIGHT ||
> +         Daylight == (EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT);
> +}
> +
> +BOOLEAN
> +EFIAPI
> +IsTimeValid (
>    IN EFI_TIME *Time
>    )
>  {
>    // Check the input parameters are within the range specified by UEFI
> -  if ((Time->Year   < 2000) ||
> -     (Time->Year   > 2099) ||
> -     (Time->Month  < 1   ) ||
> -     (Time->Month  > 12  ) ||
> -     (!IsDayValid (Time)    ) ||
> -     (Time->Hour   > 23  ) ||
> -     (Time->Minute > 59  ) ||
> -     (Time->Second > 59  ) ||
> -     (Time->Nanosecond > 999999999) ||
> -     (!((Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE) || ((Time->TimeZone >= -1440) && (Time->TimeZone <= 1440)))) ||
> -     (Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT)))
> -  ) {
> +  if ((Time->Year  < 2000)              ||
> +     (Time->Year   > 2099)              ||
> +     (Time->Month  < 1   )              ||
> +     (Time->Month  > 12  )              ||
> +     (!IsDayValid (Time) )              ||
> +     (Time->Hour   > 23  )              ||
> +     (Time->Minute > 59  )              ||
> +     (Time->Second > 59  )              ||
> +     (Time->Nanosecond > 999999999)     ||
> +     (!IsValidTimeZone(Time->TimeZone)) ||
> +     (!IsValidDaylight(Time->Daylight))) {

Can you split the tidying of unchanged lines up into a separate
preceding patch please?

Best Regards,

Leif

p.s.
I have now cleared my backlog after getting back from Christmas and am
just about to get back to reviewing the massive mt-jade platform port.
Apologies for the delay on this.

>      return FALSE;
>    }
>  
> -- 
> 2.17.1
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#69817): https://edk2.groups.io/g/devel/message/69817
Mute This Topic: https://groups.io/mt/79472334/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