From: "Jeff Brasen" <jbrasen@nvidia.com>
To: <devel@edk2.groups.io>
Cc: <daniel.schaefer@hpe.com>, <abner.chang@hpe.com>,
<ardb+tianocore@kernel.org>, <leif@nuviainc.com>,
Jeff Brasen <jbrasen@nvidia.com>
Subject: [PATCH v3 2/4] EmbeddedPkg: AndroidBootImgBoot error handling updates
Date: Mon, 13 Sep 2021 23:18:49 +0000 [thread overview]
Message-ID: <212f203320b448f4832b31ea4513119693114012.1631574815.git.jbrasen@nvidia.com> (raw)
In-Reply-To: <cover.1631574815.git.jbrasen@nvidia.com>
Update AndroidBootImgBoot to use a single return point
Make sure Kernel args are freed and Image is unloaded.
Signed-off-by: Jeff Brasen <jbrasen@nvidia.com>
---
.../AndroidBootImgLib/AndroidBootImgLib.c | 50 +++++++++++--------
1 file changed, 29 insertions(+), 21 deletions(-)
diff --git a/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c b/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c
index 33425060b15d..324933013d91 100644
--- a/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c
+++ b/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c
@@ -382,10 +382,13 @@ AndroidBootImgBoot (
UINTN RamdiskSize;
IN VOID *FdtBase;
+ NewKernelArg = NULL;
+ ImageHandle = NULL;
+
Status = gBS->LocateProtocol (&gAndroidBootImgProtocolGuid, NULL,
(VOID **) &mAndroidBootImg);
if (EFI_ERROR (Status)) {
- return Status;
+ goto Exit;
}
Status = AndroidBootImgGetKernelInfo (
@@ -394,19 +397,19 @@ AndroidBootImgBoot (
&KernelSize
);
if (EFI_ERROR (Status)) {
- return Status;
+ goto Exit;
}
NewKernelArg = AllocateZeroPool (ANDROID_BOOTIMG_KERNEL_ARGS_SIZE);
if (NewKernelArg == NULL) {
DEBUG ((DEBUG_ERROR, "Fail to allocate memory\n"));
- return EFI_OUT_OF_RESOURCES;
+ Status = EFI_OUT_OF_RESOURCES;
+ goto Exit;
}
Status = AndroidBootImgUpdateArgs (Buffer, NewKernelArg);
if (EFI_ERROR (Status)) {
- FreePool (NewKernelArg);
- return Status;
+ goto Exit;
}
Status = AndroidBootImgGetRamdiskInfo (
@@ -415,19 +418,17 @@ AndroidBootImgBoot (
&RamdiskSize
);
if (EFI_ERROR (Status)) {
- return Status;
+ goto Exit;
}
Status = AndroidBootImgLocateFdt (Buffer, &FdtBase);
if (EFI_ERROR (Status)) {
- FreePool (NewKernelArg);
- return Status;
+ goto Exit;
}
Status = AndroidBootImgUpdateFdt (Buffer, FdtBase, RamdiskData, RamdiskSize);
if (EFI_ERROR (Status)) {
- FreePool (NewKernelArg);
- return Status;
+ goto Exit;
}
KernelDevicePath = mMemoryDevicePathTemplate;
@@ -440,21 +441,15 @@ AndroidBootImgBoot (
(EFI_DEVICE_PATH *)&KernelDevicePath,
(VOID*)(UINTN)Kernel, KernelSize, &ImageHandle);
if (EFI_ERROR (Status)) {
- //
- // With EFI_SECURITY_VIOLATION retval, the Image was loaded and an ImageHandle was created
- // with a valid EFI_LOADED_IMAGE_PROTOCOL, but the image can not be started right now.
- // If the caller doesn't have the option to defer the execution of an image, we should
- // unload image for the EFI_SECURITY_VIOLATION to avoid resource leak.
- //
- if (Status == EFI_SECURITY_VIOLATION) {
- gBS->UnloadImage (ImageHandle);
- }
- return Status;
+ goto Exit;
}
// Set kernel arguments
Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid,
(VOID **) &ImageInfo);
+ if (EFI_ERROR (Status)) {
+ goto Exit;
+ }
ImageInfo->LoadOptions = NewKernelArg;
ImageInfo->LoadOptionsSize = StrLen (NewKernelArg) * sizeof (CHAR16);
@@ -464,5 +459,18 @@ AndroidBootImgBoot (
Status = gBS->StartImage (ImageHandle, NULL, NULL);
// Clear the Watchdog Timer if the image returns
gBS->SetWatchdogTimer (0, 0x10000, 0, NULL);
- return EFI_SUCCESS;
+
+Exit:
+ //Unload image as it will not be used anymore
+ if (ImageHandle != NULL) {
+ gBS->UnloadImage (ImageHandle);
+ ImageHandle = NULL;
+ }
+ if (EFI_ERROR (Status)) {
+ if (NewKernelArg != NULL) {
+ FreePool (NewKernelArg);
+ NewKernelArg = NULL;
+ }
+ }
+ return Status;
}
--
2.17.1
next prev parent reply other threads:[~2021-09-13 23:19 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-13 23:18 [PATCH v3 0/4] AndroidBootImgLib improvements Jeff Brasen
2021-09-13 23:18 ` [PATCH v3 1/4] EmbeddedPkg: Remove duplicate libfdt.h include Jeff Brasen
2021-09-13 23:18 ` Jeff Brasen [this message]
2021-09-13 23:18 ` [PATCH v3 3/4] EmbeddedPkg: Install FDT if UpdateDtb is not present Jeff Brasen
2021-09-13 23:18 ` [PATCH v3 4/4] EmbeddedPkg: Add LoadFile2 for linux initrd Jeff Brasen
2021-09-14 15:00 ` [PATCH v3 0/4] AndroidBootImgLib improvements Leif Lindholm
2021-09-14 16:57 ` Jeff Brasen
2021-09-21 16:32 ` Jeff Brasen
2021-09-22 2:15 ` Jun Nie
2021-09-23 11:06 ` Leif Lindholm
2021-09-23 15:20 ` Jeff Brasen
2021-09-23 18:38 ` Leif Lindholm
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=212f203320b448f4832b31ea4513119693114012.1631574815.git.jbrasen@nvidia.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox