diff mbox series

[3/3] efi_loader: return the correct error in efi_bootmgr_release_uridp()

Message ID 20240812205638.1732159-3-ilias.apalodimas@linaro.org
State Accepted
Commit 063b4ed07de41ea688e9f6e2d4168b192243ba58
Headers show
Series [1/3] efi_loader: shorten efi_bootmgr_release_uridp_resource() | expand

Commit Message

Ilias Apalodimas Aug. 12, 2024, 8:56 p.m. UTC
There's currently a chance for this function to overwrite an error if
one occurred and the subsequent call to
efi_uninstall_multiple_protocol_interfaces() succedded. Although this
is an EFI event and we can't do much let's at least set and return
the correct error

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---
 lib/efi_loader/efi_bootmgr.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

Simon Glass Sept. 1, 2024, 8:10 p.m. UTC | #1
On Mon, 12 Aug 2024 at 14:57, Ilias Apalodimas
<ilias.apalodimas@linaro.org> wrote:
>
> There's currently a chance for this function to overwrite an error if
> one occurred and the subsequent call to
> efi_uninstall_multiple_protocol_interfaces() succedded. Although this
> is an EFI event and we can't do much let's at least set and return
> the correct error
>
> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> ---
>  lib/efi_loader/efi_bootmgr.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
> index 03cdee15017d..a3aa2b8d1b92 100644
> --- a/lib/efi_loader/efi_bootmgr.c
> +++ b/lib/efi_loader/efi_bootmgr.c
> @@ -388,6 +388,7 @@ err:
>  efi_status_t efi_bootmgr_release_uridp(struct uridp_context *ctx)
>  {
>         efi_status_t ret = EFI_SUCCESS;
> +       efi_status_t ret2 = EFI_SUCCESS;
>
>         if (!ctx)
>                 return ret;
> @@ -407,17 +408,18 @@ efi_status_t efi_bootmgr_release_uridp(struct uridp_context *ctx)
>
>         /* cleanup for PE-COFF image */
>         if (ctx->mem_handle) {
> -               ret = efi_uninstall_multiple_protocol_interfaces(
> -                       ctx->mem_handle, &efi_guid_device_path, ctx->loaded_dp,
> -                       NULL);
> -               if (ret != EFI_SUCCESS)
> +               ret2 = efi_uninstall_multiple_protocol_interfaces(ctx->mem_handle,
> +                                                                 &efi_guid_device_path,
> +                                                                 ctx->loaded_dp,
> +                                                                 NULL);
> +               if (ret2 != EFI_SUCCESS)
>                         log_err("Uninstall device_path protocol failed\n");
>         }
>
>         efi_free_pool(ctx->loaded_dp);
>         free(ctx);
>
> -       return ret;
> +       return ret == EFI_SUCCESS ? ret2 : ret;

Reviewed-by: Simon Glass <sjg@chromium.org>

I would love the EFI code to use the same if (true/false) that the
rest of U-Boot uses for errors, e.g.

return ret ? ret : ret2;

Regards,
Simon
diff mbox series

Patch

diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
index 03cdee15017d..a3aa2b8d1b92 100644
--- a/lib/efi_loader/efi_bootmgr.c
+++ b/lib/efi_loader/efi_bootmgr.c
@@ -388,6 +388,7 @@  err:
 efi_status_t efi_bootmgr_release_uridp(struct uridp_context *ctx)
 {
 	efi_status_t ret = EFI_SUCCESS;
+	efi_status_t ret2 = EFI_SUCCESS;
 
 	if (!ctx)
 		return ret;
@@ -407,17 +408,18 @@  efi_status_t efi_bootmgr_release_uridp(struct uridp_context *ctx)
 
 	/* cleanup for PE-COFF image */
 	if (ctx->mem_handle) {
-		ret = efi_uninstall_multiple_protocol_interfaces(
-			ctx->mem_handle, &efi_guid_device_path, ctx->loaded_dp,
-			NULL);
-		if (ret != EFI_SUCCESS)
+		ret2 = efi_uninstall_multiple_protocol_interfaces(ctx->mem_handle,
+								  &efi_guid_device_path,
+								  ctx->loaded_dp,
+								  NULL);
+		if (ret2 != EFI_SUCCESS)
 			log_err("Uninstall device_path protocol failed\n");
 	}
 
 	efi_free_pool(ctx->loaded_dp);
 	free(ctx);
 
-	return ret;
+	return ret == EFI_SUCCESS ? ret2 : ret;
 }
 
 /**