From afdae789cd0d33c6f7debce2fc41f1af4946d869 Mon Sep 17 00:00:00 2001 From: Ard Biesheuvel Date: Wed, 29 Jan 2025 11:29:54 +0100 Subject: ArmPkg/CpuDxe: Fix error handling in driver initialization Failure to install the CPU arch protocol is a fatal error, so treat it as such, rather than ignore it, even though we won't get very far if this driver fails to dispatch - at least, we will get an error in a DEBUG build rather than a mysterious failure due to unsatisfied DEPEXes. Failure to install the idle loop event handler is not a fatal error, and it should not cause the driver to exit with an error, as this will unload the driver and keep the installed CPU arch protocol pointer dangling. So keep the ASSERT() on the return value, but return EFI_SUCCESS once we're past the point where the CPU arch protocol has been installed. Since the protocol is never uninstalled, make the CPU handle function local, as there is no point in keeping its value around. Signed-off-by: Ard Biesheuvel --- ArmPkg/Drivers/CpuDxe/CpuDxe.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ArmPkg/Drivers/CpuDxe/CpuDxe.c b/ArmPkg/Drivers/CpuDxe/CpuDxe.c index fc63e52784..9bb2b4a600 100644 --- a/ArmPkg/Drivers/CpuDxe/CpuDxe.c +++ b/ArmPkg/Drivers/CpuDxe/CpuDxe.c @@ -206,8 +206,7 @@ IdleLoopEventCallback ( // // Globals used to initialize the protocol // -EFI_HANDLE mCpuHandle = NULL; -EFI_CPU_ARCH_PROTOCOL mCpu = { +EFI_CPU_ARCH_PROTOCOL mCpu = { CpuFlushCpuDataCache, CpuEnableInterrupt, CpuDisableInterrupt, @@ -308,6 +307,7 @@ CpuDxeInitialize ( { EFI_STATUS Status; EFI_EVENT IdleLoopEvent; + EFI_HANDLE CpuHandle; InitializeExceptions (&mCpu); @@ -327,14 +327,20 @@ CpuDxeInitialize ( RemapUnusedMemoryNx (); } + CpuHandle = NULL; + Status = gBS->InstallMultipleProtocolInterfaces ( - &mCpuHandle, + &CpuHandle, &gEfiCpuArchProtocolGuid, &mCpu, &gEfiMemoryAttributeProtocolGuid, &mMemoryAttribute, NULL ); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } // // Make sure GCD and MMU settings match. This API calls gDS->SetMemorySpaceAttributes () @@ -358,5 +364,5 @@ CpuDxeInitialize ( ); ASSERT_EFI_ERROR (Status); - return Status; + return EFI_SUCCESS; } -- cgit