From: "Leif Lindholm" <leif@nuviainc.com>
To: Nhi Pham <nhi@os.amperecomputing.com>
Cc: devel@edk2.groups.io, Ard Biesheuvel <ard.biesheuvel@arm.com>
Subject: Re: [PATCH 1/2] EmbeddedPkg/TimeBaseLib: Add function to check Timezone and Daylight
Date: Wed, 6 Jan 2021 13:03:35 +0000 [thread overview]
Message-ID: <20210106130335.GB1664@vanye> (raw)
In-Reply-To: <20210106105558.9582-2-nhi@os.amperecomputing.com>
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@nuviainc.com>
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
> Signed-off-by: Nhi Pham <nhi@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
>
next prev parent reply other threads:[~2021-01-06 13:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-06 10:55 [PATCH 0/2] Reduce duplicate code in RTC modules Nhi Pham
2021-01-06 10:55 ` [PATCH 1/2] EmbeddedPkg/TimeBaseLib: Add function to check Timezone and Daylight Nhi Pham
2021-01-06 13:03 ` Leif Lindholm [this message]
2021-01-06 10:55 ` [PATCH 2/2] EmbeddedPkg/RealTimeClockRuntimeDxe: Use helper functions from TimeBaseLib Nhi Pham
2021-01-06 13:05 ` Leif Lindholm
2021-01-06 13:39 ` Nhi Pham
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210106130335.GB1664@vanye \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox