UINTN RamdiskSize;\r
IN VOID *FdtBase;\r
\r
+ NewKernelArg = NULL;\r
+ ImageHandle = NULL;\r
+\r
Status = gBS->LocateProtocol (&gAndroidBootImgProtocolGuid, NULL,\r
(VOID **) &mAndroidBootImg);\r
if (EFI_ERROR (Status)) {\r
- return Status;\r
+ goto Exit;\r
}\r
\r
Status = AndroidBootImgGetKernelInfo (\r
&KernelSize\r
);\r
if (EFI_ERROR (Status)) {\r
- return Status;\r
+ goto Exit;\r
}\r
\r
NewKernelArg = AllocateZeroPool (ANDROID_BOOTIMG_KERNEL_ARGS_SIZE);\r
if (NewKernelArg == NULL) {\r
DEBUG ((DEBUG_ERROR, "Fail to allocate memory\n"));\r
- return EFI_OUT_OF_RESOURCES;\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto Exit;\r
}\r
\r
Status = AndroidBootImgUpdateArgs (Buffer, NewKernelArg);\r
if (EFI_ERROR (Status)) {\r
- FreePool (NewKernelArg);\r
- return Status;\r
+ goto Exit;\r
}\r
\r
Status = AndroidBootImgGetRamdiskInfo (\r
&RamdiskSize\r
);\r
if (EFI_ERROR (Status)) {\r
- return Status;\r
+ goto Exit;\r
}\r
\r
Status = AndroidBootImgLocateFdt (Buffer, &FdtBase);\r
if (EFI_ERROR (Status)) {\r
- FreePool (NewKernelArg);\r
- return Status;\r
+ goto Exit;\r
}\r
\r
Status = AndroidBootImgUpdateFdt (Buffer, FdtBase, RamdiskData, RamdiskSize);\r
if (EFI_ERROR (Status)) {\r
- FreePool (NewKernelArg);\r
- return Status;\r
+ goto Exit;\r
}\r
\r
KernelDevicePath = mMemoryDevicePathTemplate;\r
(EFI_DEVICE_PATH *)&KernelDevicePath,\r
(VOID*)(UINTN)Kernel, KernelSize, &ImageHandle);\r
if (EFI_ERROR (Status)) {\r
- //\r
- // With EFI_SECURITY_VIOLATION retval, the Image was loaded and an ImageHandle was created\r
- // with a valid EFI_LOADED_IMAGE_PROTOCOL, but the image can not be started right now.\r
- // If the caller doesn't have the option to defer the execution of an image, we should\r
- // unload image for the EFI_SECURITY_VIOLATION to avoid resource leak.\r
- //\r
- if (Status == EFI_SECURITY_VIOLATION) {\r
- gBS->UnloadImage (ImageHandle);\r
- }\r
- return Status;\r
+ goto Exit;\r
}\r
\r
// Set kernel arguments\r
Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid,\r
(VOID **) &ImageInfo);\r
+ if (EFI_ERROR (Status)) {\r
+ goto Exit;\r
+ }\r
ImageInfo->LoadOptions = NewKernelArg;\r
ImageInfo->LoadOptionsSize = StrLen (NewKernelArg) * sizeof (CHAR16);\r
\r
Status = gBS->StartImage (ImageHandle, NULL, NULL);\r
// Clear the Watchdog Timer if the image returns\r
gBS->SetWatchdogTimer (0, 0x10000, 0, NULL);\r
- return EFI_SUCCESS;\r
+\r
+Exit:\r
+ //Unload image as it will not be used anymore\r
+ if (ImageHandle != NULL) {\r
+ gBS->UnloadImage (ImageHandle);\r
+ ImageHandle = NULL;\r
+ }\r
+ if (EFI_ERROR (Status)) {\r
+ if (NewKernelArg != NULL) {\r
+ FreePool (NewKernelArg);\r
+ NewKernelArg = NULL;\r
+ }\r
+ }\r
+ return Status;\r
}\r