From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web08.38893.1608556926284455936 for ; Mon, 21 Dec 2020 05:22:07 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YLsqYWBQ; spf=pass (domain: redhat.com, ip: 216.205.24.124, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608556925; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RuTI/G5HoQ3OUK3KqIOxofZF3IuPZUopLVtfae20o20=; b=YLsqYWBQazS7qgct8dT93J6kWAibWToAxnTf49isNmlwX5aFvey49m+eHyWLIXUcQCRVqK FVYXl8csRV33omd6zMGuSO6tLrSBqGRSBXdmYjHF7se6jIdk0mUQ1IYdfF4V7LfffetRKX +chZRRjdb3K6SCg3836fUjJiMolKBrE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-407-561TkUM3PlqjJKtRrcCyrg-1; Mon, 21 Dec 2020 08:22:01 -0500 X-MC-Unique: 561TkUM3PlqjJKtRrcCyrg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 636408144E0; Mon, 21 Dec 2020 13:22:00 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-71.ams2.redhat.com [10.36.114.71]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1AF11964B; Mon, 21 Dec 2020 13:21:58 +0000 (UTC) Subject: Re: [edk2-devel] [edk2-platforms PATCH] Silicon/Marvell/RealTimeClockLib: make EpochSeconds, WakeupSeconds UINTN To: devel@edk2.groups.io, ard.biesheuvel@arm.com Cc: Leif Lindholm , Marcin Wojtas , =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= References: <20201221112433.5525-1-lersek@redhat.com> <39b45fed-d3d9-5563-81be-bcf339f01085@arm.com> From: "Laszlo Ersek" Message-ID: <1ec2e9c1-c27d-9233-96bf-022a16a0d004@redhat.com> Date: Mon, 21 Dec 2020 14:21:57 +0100 MIME-Version: 1.0 In-Reply-To: <39b45fed-d3d9-5563-81be-bcf339f01085@arm.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lersek@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit On 12/21/20 13:16, Ard Biesheuvel wrote: > On 12/21/20 12:24 PM, Laszlo Ersek wrote: >> We're going to change EfiTimeToEpoch() in edk2's TimeBaseLib to propagate >> its internal UINTN calculation to the caller without an internal UINT32 >> truncation. >> >> Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib drives 32-bit-only >> hardware, so catch any number of seconds since the epoch, from >> EfiTimeToEpoch(), that doesn't fit in 32 bits. >> >> Cc: Ard Biesheuvel >> Cc: Leif Lindholm >> Cc: Marcin Wojtas >> Cc: Philippe Mathieu-Daudé >> Signed-off-by: Laszlo Ersek > > Acked-by: Ard Biesheuvel > > Feel free to push this directly (no CI+label dance required) Commit fbdfe8c4100d. Thank you, Ard! Laszlo >> --- >> >> Notes: >> Build-tested only, with >> >> build \ >> -a AARCH64 \ >> -b NOOPT \ >> -p Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc \ >> -t GCC5 \ >> -m EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf >> >> Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.c | 14 ++++++++++---- >> 1 file changed, 10 insertions(+), 4 deletions(-) >> >> diff --git a/Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.c b/Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.c >> index 1974e0144cd8..a811fd368eca 100644 >> --- a/Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.c >> +++ b/Silicon/Marvell/Armada7k8k/Library/RealTimeClockLib/RealTimeClockLib.c >> @@ -100,33 +100,36 @@ EFIAPI >> LibSetTime ( >> IN EFI_TIME *Time >> ) >> { >> EFI_STATUS Status = EFI_SUCCESS; >> - UINT32 EpochSeconds; >> + UINTN EpochSeconds; >> >> // Check the input parameters are within the range specified by UEFI >> if (!IsTimeValid (Time)) { >> return EFI_INVALID_PARAMETER; >> } >> >> // Convert time to raw seconds >> EpochSeconds = EfiTimeToEpoch (Time); >> + if (EpochSeconds > MAX_UINT32) { >> + return EFI_INVALID_PARAMETER; >> + } >> >> // Issue delayed write to time register >> - RtcDelayedWrite (RTC_TIME_REG, EpochSeconds); >> + RtcDelayedWrite (RTC_TIME_REG, (UINT32)EpochSeconds); >> >> return Status; >> } >> >> /** >> Returns the current wakeup alarm clock setting. >> >> @param Enabled Indicates if the alarm is currently enabled or disabled. >> @param Pending Indicates if the alarm signal is pending and requires acknowledgement. >> @param Time The current alarm setting. >> >> @retval EFI_SUCCESS The alarm settings were returned. >> @retval EFI_INVALID_PARAMETER Any parameter is NULL. >> @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error. >> >> **/ >> @@ -172,32 +175,35 @@ EFIAPI >> LibSetWakeupTime ( >> IN BOOLEAN Enabled, >> OUT EFI_TIME *Time >> ) >> { >> - UINT32 WakeupSeconds; >> + UINTN WakeupSeconds; >> >> // Convert time to raw seconds >> WakeupSeconds = EfiTimeToEpoch (Time); >> + if (WakeupSeconds > MAX_UINT32) { >> + return EFI_INVALID_PARAMETER; >> + } >> >> // Issue delayed write to alarm register >> - RtcDelayedWrite (RTC_ALARM_2_REG, WakeupSeconds); >> + RtcDelayedWrite (RTC_ALARM_2_REG, (UINT32)WakeupSeconds); >> >> if (Enabled) { >> MmioWrite32 (mArmadaRtcBase + RTC_IRQ_2_CONFIG_REG, RTC_IRQ_ALARM_EN); >> } else { >> MmioWrite32 (mArmadaRtcBase + RTC_IRQ_2_CONFIG_REG, 0); >> } >> >> return EFI_SUCCESS; >> } >> >> /** >> This is the declaration of an EFI image entry point. This can be the entry point to an application >> written to this specification, an EFI boot service driver, or an EFI runtime driver. >> >> @param ImageHandle Handle that identifies the loaded image. >> @param SystemTable System Table for this image. >> >> @retval EFI_SUCCESS The operation completed successfully. >> >> **/ >> > > > > > >