diff mbox series

[RFC,09/14] efi_loader: do not install dtb if bootmgr fails

Message ID 20240426141321.232236-10-heinrich.schuchardt@canonical.com
State Accepted, archived
Delegated to: Heinrich Schuchardt
Headers show
Series efi_loader: improve device-tree loading | expand

Commit Message

Heinrich Schuchardt April 26, 2024, 2:13 p.m. UTC
If the UEFI boot manager fails there is no point in installing the
device-tree as a configuration table.

Unload image if device-tree cannot be installed.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 lib/efi_loader/efi_bootmgr.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

Comments

Ilias Apalodimas May 22, 2024, 6:17 a.m. UTC | #1
On Fri, Apr 26, 2024 at 04:13:16PM +0200, Heinrich Schuchardt wrote:
> If the UEFI boot manager fails there is no point in installing the
> device-tree as a configuration table.
>
> Unload image if device-tree cannot be installed.
>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
>  lib/efi_loader/efi_bootmgr.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
> index c64cbe82402..d924810a94b 100644
> --- a/lib/efi_loader/efi_bootmgr.c
> +++ b/lib/efi_loader/efi_bootmgr.c
> @@ -1209,15 +1209,21 @@ efi_status_t efi_bootmgr_run(void *fdt)
>  		return CMD_RET_FAILURE;
>  	}
>
> -	ret = efi_install_fdt(fdt);
> -	if (ret != EFI_SUCCESS)
> -		return ret;
> -
>  	ret = efi_bootmgr_load(&handle, &load_options);
>  	if (ret != EFI_SUCCESS) {
>  		log_notice("EFI boot manager: Cannot load any image\n");
>  		return ret;
>  	}
>
> +	ret = efi_install_fdt(fdt);
> +	if (ret != EFI_SUCCESS) {
> +		if (EFI_CALL(efi_unload_image(*handle)) == EFI_SUCCESS)
> +			free(load_options);
> +		else
> +			log_err("Unloading image failed\n");
> +
> +		return ret;
> +	}
> +
>  	return do_bootefi_exec(handle, load_options);
>  }
> --
> 2.43.0
>

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Ilias Apalodimas May 22, 2024, 6:27 a.m. UTC | #2
On Wed, May 22, 2024 at 09:17:11AM +0300, Ilias Apalodimas wrote:
> On Fri, Apr 26, 2024 at 04:13:16PM +0200, Heinrich Schuchardt wrote:
> > If the UEFI boot manager fails there is no point in installing the
> > device-tree as a configuration table.
> >
> > Unload image if device-tree cannot be installed.
> >
> > Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> > ---
> >  lib/efi_loader/efi_bootmgr.c | 14 ++++++++++----
> >  1 file changed, 10 insertions(+), 4 deletions(-)
> >
> > diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
> > index c64cbe82402..d924810a94b 100644
> > --- a/lib/efi_loader/efi_bootmgr.c
> > +++ b/lib/efi_loader/efi_bootmgr.c
> > @@ -1209,15 +1209,21 @@ efi_status_t efi_bootmgr_run(void *fdt)
> >  		return CMD_RET_FAILURE;
> >  	}
> >
> > -	ret = efi_install_fdt(fdt);
> > -	if (ret != EFI_SUCCESS)
> > -		return ret;
> > -
> >  	ret = efi_bootmgr_load(&handle, &load_options);
> >  	if (ret != EFI_SUCCESS) {
> >  		log_notice("EFI boot manager: Cannot load any image\n");
> >  		return ret;
> >  	}
> >
> > +	ret = efi_install_fdt(fdt);
> > +	if (ret != EFI_SUCCESS) {
> > +		if (EFI_CALL(efi_unload_image(*handle)) == EFI_SUCCESS)

I missed this during the review. This should be efi_unload_image(handle)

With this fixed
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

> > +			free(load_options);
> > +		else
> > +			log_err("Unloading image failed\n");
> > +
> > +		return ret;
> > +	}
> > +
> >  	return do_bootefi_exec(handle, load_options);
> >  }
> > --
> > 2.43.0
> >
>
>
diff mbox series

Patch

diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
index c64cbe82402..d924810a94b 100644
--- a/lib/efi_loader/efi_bootmgr.c
+++ b/lib/efi_loader/efi_bootmgr.c
@@ -1209,15 +1209,21 @@  efi_status_t efi_bootmgr_run(void *fdt)
 		return CMD_RET_FAILURE;
 	}
 
-	ret = efi_install_fdt(fdt);
-	if (ret != EFI_SUCCESS)
-		return ret;
-
 	ret = efi_bootmgr_load(&handle, &load_options);
 	if (ret != EFI_SUCCESS) {
 		log_notice("EFI boot manager: Cannot load any image\n");
 		return ret;
 	}
 
+	ret = efi_install_fdt(fdt);
+	if (ret != EFI_SUCCESS) {
+		if (EFI_CALL(efi_unload_image(*handle)) == EFI_SUCCESS)
+			free(load_options);
+		else
+			log_err("Unloading image failed\n");
+
+		return ret;
+	}
+
 	return do_bootefi_exec(handle, load_options);
 }