When calling SetTimer with Type is not TimerCancel and TriggerTime is 0, gTimer is used to get the timer period. However, gTimer is NULL before EFI_TIMER_ARCH_PROTOCOL is installed. Adding the check of gTimer and return EFI_NOT_READY to avoid the hang.
Cc: Jian J Wang <jian.j.w...@intel.com> Cc: Dandan Bi <dandan...@intel.com> Cc: Liming Gao <gaolim...@byosoft.com.cn> Signed-off-by: Ying-Tsun Huang <ying-tsun.hu...@amd.com> --- MdeModulePkg/Core/Dxe/DxeMain.h | 3 +++ MdeModulePkg/Core/Dxe/Event/Timer.c | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/DxeMain.h b/MdeModulePkg/Core/Dxe/DxeMain.h index 815a6b4bd844..182d9c3537ad 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.h +++ b/MdeModulePkg/Core/Dxe/DxeMain.h @@ -3,6 +3,7 @@ internal structure and functions used by DxeCore module. Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2022, AMD Incorporated. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -1538,6 +1539,8 @@ CoreCreateEventInternal ( @retval EFI_SUCCESS The event has been set to be signaled at the requested time @retval EFI_INVALID_PARAMETER Event or Type is not valid + @retval EFI_NOT_READY Type is not TimerCancel, TriggerTime is 0, but + EFI_TIMER_ARCH_PROTOCOL is not installed yet **/ EFI_STATUS diff --git a/MdeModulePkg/Core/Dxe/Event/Timer.c b/MdeModulePkg/Core/Dxe/Event/Timer.c index 29e507c67c50..f630cf5dad61 100644 --- a/MdeModulePkg/Core/Dxe/Event/Timer.c +++ b/MdeModulePkg/Core/Dxe/Event/Timer.c @@ -2,6 +2,7 @@ Core Timer Services Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2022, AMD Incorporated. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -229,6 +230,8 @@ CoreTimerTick ( @retval EFI_SUCCESS The event has been set to be signaled at the requested time @retval EFI_INVALID_PARAMETER Event or Type is not valid + @retval EFI_NOT_READY Type is not TimerCancel, TriggerTime is 0, but + EFI_TIMER_ARCH_PROTOCOL is not installed yet **/ EFI_STATUS @@ -255,6 +258,16 @@ CoreSetTimer ( return EFI_INVALID_PARAMETER; } + if ((Type != TimerCancel) && (TriggerTime == 0)) { + if (gTimer) { + gTimer->GetTimerPeriod (gTimer, &TriggerTime); + } else { + DEBUG ((DEBUG_ERROR, "EFI_TIMER_ARCH_PROTOCOL is not installed. Unable to get timer period.\n")); + ASSERT (FALSE); + return EFI_NOT_READY; + } + } + CoreAcquireLock (&mEfiTimerLock); // @@ -270,10 +283,6 @@ CoreSetTimer ( if (Type != TimerCancel) { if (Type == TimerPeriodic) { - if (TriggerTime == 0) { - gTimer->GetTimerPeriod (gTimer, &TriggerTime); - } - Event->Timer.Period = TriggerTime; } -- 2.25.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#94107): https://edk2.groups.io/g/devel/message/94107 Mute This Topic: https://groups.io/mt/93843297/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-