From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.116]) by mx.groups.io with SMTP id smtpd.web09.7951.1609940401483701494 for ; Wed, 06 Jan 2021 05:40:01 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=XGCYTsZo; spf=pass (domain: os.amperecomputing.com, ip: 40.107.94.116, mailfrom: nhi@os.amperecomputing.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kwyVnsWeUZ9H22rNfSJ0b6LwbEbpoUUy9bLKwG3fspMmYkz90GRvDsQXkjkyKp9eBBsZaiDf184Mv8tPlEUhl7ejQEyXWc/WYl9nfNgRVDxhCayjsmo/Pdhac47Nr6Gw+FsG/kAxzrUQ9JRSzRkxqUt6d+X323HRo+ow4e1D/oJpWDu0GcObOZjH+bVm/cDpPRVwIHnqgm4zA2JJJoQOwwk5fcBgu77IMZnJuwbg9uyPUsXVsE9lzttfSMIwOu6yHMv2tzUEtDPIqDoToV72SVNmZkrBebqyR9Ek2JoKu9Y5S2sEG33s7D9xZhAnaH8hTImZIQcWD7feVBTgpgUDMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6sjy44q3YQFgGZwR9Y9ks4BaqTR3fqOg6qIUWq2x51c=; b=TyGNzMZnW/McHS6UyU8ap4wgffcKW+kuZHff24YANO46S0EirLAlSjr54JykJvS7bxhM6JVcpN1TqmsiKdKEwTrRzDZ4/2a/3DkVUXLbKLWOXjxXJ2UxfMc15x/Ep754nhtwbZzXNuIcNocU6/YLuJ/7x69H688Y52DkpzFz9uTri1mVo6H6/2Mzl6yyB8NS/PV6aEiprrLqMWpx2SARD6ytIUpm9aTfH8me0/Yyl1sJfOrLci+BUPh7hZKuizDR6h3X+06rF5tji4IOoHm7u+lz0qQy62ymFGDd5KaXg0ButvFQM4a/XZWoEjX+EVXGXX0xqadIwQQ1beNqd5Jf2A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6sjy44q3YQFgGZwR9Y9ks4BaqTR3fqOg6qIUWq2x51c=; b=XGCYTsZo4Hpp7BJMPdsyiIZJRCuXkcLiol3WpYwDVFyX7c00amNZlT2LQI5qGDq+HqVrwNEvsMfa7u2ot9u+NRhfeocp/gTRVl1A4DTcMHiNFQalgJsj82PPQIr4YJhbFd+4JozQNI3BqP4d2pyB3SvlfOCMXA72+31w4Woii1c= Authentication-Results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=os.amperecomputing.com; Received: from DM6PR01MB5849.prod.exchangelabs.com (2603:10b6:5:205::20) by DM6PR01MB5401.prod.exchangelabs.com (2603:10b6:5:153::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6; Wed, 6 Jan 2021 13:39:59 +0000 Received: from DM6PR01MB5849.prod.exchangelabs.com ([fe80::c814:9a08:5c2e:4076]) by DM6PR01MB5849.prod.exchangelabs.com ([fe80::c814:9a08:5c2e:4076%5]) with mapi id 15.20.3721.024; Wed, 6 Jan 2021 13:39:58 +0000 Subject: Re: [PATCH 2/2] EmbeddedPkg/RealTimeClockRuntimeDxe: Use helper functions from TimeBaseLib To: Leif Lindholm Cc: devel@edk2.groups.io, Ard Biesheuvel References: <20210106105558.9582-1-nhi@os.amperecomputing.com> <20210106105558.9582-3-nhi@os.amperecomputing.com> <20210106130519.GC1664@vanye> From: "Nhi Pham" Message-ID: Date: Wed, 6 Jan 2021 20:39:48 +0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.5.1 In-Reply-To: <20210106130519.GC1664@vanye> X-Originating-IP: [42.113.218.204] X-ClientProxiedBy: HK2PR06CA0013.apcprd06.prod.outlook.com (2603:1096:202:2e::25) To DM6PR01MB5849.prod.exchangelabs.com (2603:10b6:5:205::20) Return-Path: nhi@os.amperecomputing.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.1.73] (42.113.218.204) by HK2PR06CA0013.apcprd06.prod.outlook.com (2603:1096:202:2e::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Wed, 6 Jan 2021 13:39:57 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bc9fe24b-26fc-4ea3-e1be-08d8b2488f8f X-MS-TrafficTypeDiagnostic: DM6PR01MB5401: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0DNA8Yi5FbqtzHGKJibyg/fHrrKIhuxprm+ivD3zK6KxT0pneaD3BY8j8uTOSbMlMpR0ICfVsW3YtV5Aade7z//9Xl9r3MPVV4/OhilEFD0VF/vb3i2gs3WJ/uAZe4zBRAbASkitjP2cSOYlI729FudDvjBgza9bFg2umUU0/YeV1G0xtcxH0xLotIEuhe7ii+zEXQDhxedoBoPX5pZQE/VxzSblV6NjhOQMafK/ou0mlGfu9AEAnZ4xoP/MIPaMPf4gMu8h+DcekvmCfGbR3emqqOYtABBPkd5XZb3wbc+P9veSWHFOx+Qybar75CQ6SVx4KMGR8qWXCyRKh0Ozh1qFzM7+U80ImYNHLSa/tHGuQtcFgVljmO5J6+97qx790+YqkACdnhPpjSd+YWdzMkVzwO+Zn+t/UvPUNitvyPE0n2KzlxbChjD96SIG1O3QAAmMxMq535WhECMhkln3KU/KBEg7DKc9ajkQ+DhK1uJ3K+qdG6GcevgSAWg6cog1 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR01MB5849.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(346002)(366004)(136003)(376002)(39850400004)(66946007)(86362001)(2616005)(6916009)(6486002)(66556008)(66476007)(5660300002)(956004)(53546011)(31696002)(186003)(26005)(4326008)(16526019)(52116002)(8676002)(2906002)(316002)(6666004)(16576012)(83380400001)(8936002)(478600001)(31686004)(213903007)(45980500001)(43740500002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: C1aBTqvwRfp5mMItAu5bEFhbIvfah1+V2R4G7GmYxQoMMBRJTCK72Fcgzqo5s9hy0Akk00hL0DWPjEtdtkJ0N+wzJNnK5aOUR3UceeVLS0qQjZmpN5s+PHrUHsKgevLIiwdnU22fD/WL1Jlui83/8ReyL15Zs08cqAT+qh1lYC2RDTbnpKqxGer4vNTkQDm+4xoBLC1BV17Kn9RftnGrAEMjFirLFlwGRgMiR71NCVCDV2AF0lI7SpkeLQ/bU29QD/jUzEMuvNkXgdf+30qD95htFbW3OdFdsTjefsbq0plyQfsq2y25K+3jXyaoXEltP4gEqtcCAyvqYeeZxTx79W/4/zEG1tzUbS0Aeb/PytXKk77OzqrHEg1lpuOJwkZ5rjPjvHBt7EBqjErkeqAkrfCdh1udh5A9ZbB9Vmi9NftAB2ehHdx7j+QnC+KGkwYSMYuE3S/TT5v9YDabUhXogjUUrgp1/btTMvmFJ12vZhqzSIzDZ8+xzPo30yis6gpqO89v8/eSqDK4Lpfd5nDKvWE4Tqp/GyUWBTW8BKfr7+BOw1puy9whttRZX3jdKG56k2nAhgqywoVyHdSuwYRaukHB1Sx2aEuiiqU64Lc7cndJ0Hj7ESNdMWjOu9wo14w2rJiszt1L4G9FDyVyJsyPvhat1hdCL+iF5+nHRZ53rhkRzu0knzXrnzZhbLg6tKkrdhJBRjVv0Tps7maPfoQ7uUJ6hCgAqZI0nC8kC30XzbJE1FKt+5Aba9zqZ0hmLR33 X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-AuthSource: DM6PR01MB5849.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2021 13:39:58.7366 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-Network-Message-Id: bc9fe24b-26fc-4ea3-e1be-08d8b2488f8f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: U0Ft86cScqod+xOY4okdN/lO1JqOJs3RoTmwRghMRusgArB53NpGyK7HT/rIG8EGZcz9itS9VauGeaiN3DyUUWv/f2wBCPTUYDChpfIBhN0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB5401 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Thanks. I will fix all comments in the v2. -Nhi On 1/6/21 20:05, Leif Lindholm wrote: > On Wed, Jan 06, 2021 at 17:55:58 +0700, Nhi Pham wrote: >> This patch replaces all time checking functions and leverage the helper >> functions in TimeBaseLib library. >> >> Cc: Leif Lindholm >> Cc: Ard Biesheuvel >> Signed-off-by: Nhi Pham >> --- >> EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf | 2 + >> EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClock.c | 88 +------------------- >> 2 files changed, 4 insertions(+), 86 deletions(-) >> >> diff --git a/EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf b/EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf >> index c9cd052adef4..c0e44033af3a 100644 >> --- a/EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf >> +++ b/EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf >> @@ -3,6 +3,7 @@ >> # >> # Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.
>> # Copyright (c) 2017, Linaro, Ltd. All rights reserved.
>> +# Copyright (c) 2020, Ampere Computing LLC. All rights reserved.
> 2021? > >> # >> # SPDX-License-Identifier: BSD-2-Clause-Patent >> # >> @@ -31,6 +32,7 @@ [LibraryClasses] >> UefiBootServicesTableLib >> UefiDriverEntryPoint >> UefiRuntimeLib >> + TimeBaseLib > Please insert alphabetically sorted. > >> >> [Protocols] >> gEfiRealTimeClockArchProtocolGuid >> diff --git a/EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClock.c b/EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClock.c >> index 20f1fa640ecc..8ae4e9315be5 100644 >> --- a/EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClock.c >> +++ b/EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClock.c >> @@ -3,6 +3,7 @@ >> >> Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
>> Copyright (c) 2017, Linaro, Ltd. All rights reserved.
>> + Copyright (c) 2020, Ampere Computing LLC. All rights reserved.
> 2021? > >> >> SPDX-License-Identifier: BSD-2-Clause-Patent >> >> @@ -14,6 +15,7 @@ >> #include >> #include >> #include >> +#include > Please insert alphabetically sorted. > > This set looks a nice bit of cleanup, though - thanks! > > / > Leif > >> #include >> >> EFI_HANDLE mHandle = NULL; >> @@ -31,92 +33,6 @@ typedef struct { >> STATIC CONST CHAR16 mTimeSettingsVariableName[] = L"RtcTimeSettings"; >> STATIC NON_VOLATILE_TIME_SETTINGS mTimeSettings; >> >> -STATIC >> -BOOLEAN >> -IsValidTimeZone ( >> - IN INT16 TimeZone >> - ) >> -{ >> - return TimeZone == EFI_UNSPECIFIED_TIMEZONE || >> - (TimeZone >= -1440 && TimeZone <= 1440); >> -} >> - >> -STATIC >> -BOOLEAN >> -IsValidDaylight ( >> - IN INT8 Daylight >> - ) >> -{ >> - return Daylight == 0 || >> - Daylight == EFI_TIME_ADJUST_DAYLIGHT || >> - Daylight == (EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT); >> -} >> - >> -STATIC >> -BOOLEAN >> -EFIAPI >> -IsLeapYear ( >> - IN EFI_TIME *Time >> - ) >> -{ >> - if (Time->Year % 4 == 0) { >> - if (Time->Year % 100 == 0) { >> - if (Time->Year % 400 == 0) { >> - return TRUE; >> - } else { >> - return FALSE; >> - } >> - } else { >> - return TRUE; >> - } >> - } else { >> - return FALSE; >> - } >> -} >> - >> -STATIC CONST INTN mDayOfMonth[12] = { >> - 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 >> -}; >> - >> -STATIC >> -BOOLEAN >> -EFIAPI >> -IsDayValid ( >> - IN EFI_TIME *Time >> - ) >> -{ >> - if (Time->Day < 1 || >> - Time->Day > mDayOfMonth[Time->Month - 1] || >> - (Time->Month == 2 && !IsLeapYear (Time) && Time->Day > 28)) { >> - return FALSE; >> - } >> - return TRUE; >> -} >> - >> -STATIC >> -BOOLEAN >> -EFIAPI >> -IsTimeValid( >> - IN EFI_TIME *Time >> - ) >> -{ >> - // Check the input parameters are within the range specified by UEFI >> - if (Time->Year < 1900 || >> - Time->Year > 9999 || >> - 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)) { >> - return FALSE; >> - } >> - return TRUE; >> -} >> - >> /** >> Returns the current time and date information, and the time-keeping capabilities >> of the hardware platform. >> -- >> 2.17.1 >>