diff mbox series

efi_loader: remove efi_delete_handle on loadfile2

Message ID 20221015213534.216607-1-ilias.apalodimas@linaro.org
State Superseded
Headers show
Series efi_loader: remove efi_delete_handle on loadfile2 | expand

Commit Message

Ilias Apalodimas Oct. 15, 2022, 9:35 p.m. UTC
Loadfile2 code is installing two protocols on it's own handle
and uses efi_delete_handle() to clean it up on failure(s).  However
commit 05c4c9e21ae6 ("efi_loader: define internal implementations of install/uninstallmultiple")
prepares the ground for us to clean up efi_elete_handle() used in favor of
Install/UninstallMultipleProtocol

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---
 cmd/bootefi.c                    |  6 ++++--
 include/efi_loader.h             |  2 +-
 lib/efi_loader/efi_load_initrd.c | 17 ++++++++++++++---
 3 files changed, 19 insertions(+), 6 deletions(-)

Comments

Heinrich Schuchardt Oct. 16, 2022, 7:50 a.m. UTC | #1
On 10/15/22 23:35, Ilias Apalodimas wrote:
> Loadfile2 code is installing two protocols on it's own handle
> and uses efi_delete_handle() to clean it up on failure(s).  However
> commit 05c4c9e21ae6 ("efi_loader: define internal implementations of install/uninstallmultiple")
> prepares the ground for us to clean up efi_elete_handle() used in favor of
> Install/UninstallMultipleProtocol
>
> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> ---
>   cmd/bootefi.c                    |  6 ++++--
>   include/efi_loader.h             |  2 +-
>   lib/efi_loader/efi_load_initrd.c | 17 ++++++++++++++---
>   3 files changed, 19 insertions(+), 6 deletions(-)
>
> diff --git a/cmd/bootefi.c b/cmd/bootefi.c
> index b93c0d3d4c02..2a7d42925d65 100644
> --- a/cmd/bootefi.c
> +++ b/cmd/bootefi.c
> @@ -394,8 +394,10 @@ static efi_status_t do_bootefi_exec(efi_handle_t handle, void *load_options)
>   out:
>   	free(load_options);
>
> -	if (IS_ENABLED(CONFIG_EFI_LOAD_FILE2_INITRD))
> -		efi_initrd_deregister();
> +	if (IS_ENABLED(CONFIG_EFI_LOAD_FILE2_INITRD)) {
> +		if (efi_initrd_deregister() != EFI_SUCCESS)
> +			log_err("Failed to remove loadfile2 for initrd\n");
> +	}
>
>   	/* Control is returned to U-Boot, disable EFI watchdog */
>   	efi_set_watchdog(0);
> diff --git a/include/efi_loader.h b/include/efi_loader.h
> index 1bac3f49a3e5..0c6c95ba4641 100644
> --- a/include/efi_loader.h
> +++ b/include/efi_loader.h
> @@ -570,7 +570,7 @@ efi_status_t efi_net_register(void);
>   /* Called by bootefi to make the watchdog available */
>   efi_status_t efi_watchdog_register(void);
>   efi_status_t efi_initrd_register(void);
> -void efi_initrd_deregister(void);
> +efi_status_t efi_initrd_deregister(void);
>   /* Called by bootefi to make SMBIOS tables available */
>   /**
>    * efi_acpi_register() - write out ACPI tables
> diff --git a/lib/efi_loader/efi_load_initrd.c b/lib/efi_loader/efi_load_initrd.c
> index 87fde3f88c2b..7a345d3fe41e 100644
> --- a/lib/efi_loader/efi_load_initrd.c
> +++ b/lib/efi_loader/efi_load_initrd.c
> @@ -227,11 +227,22 @@ efi_status_t efi_initrd_register(void)
>    *
>    * Return:	status code
>    */
> -void efi_initrd_deregister(void)
> +efi_status_t efi_initrd_deregister(void)
>   {
> +	efi_status_t ret;
> +
>   	if (!efi_initrd_handle)
> -		return;
> +		return EFI_SUCCESS;
>
> -	efi_delete_handle(efi_initrd_handle);
> +	ret = efi_uninstall_multiple_protocol_interfaces(efi_initrd_handle,
> +							 /* initramfs */
> +							 &efi_guid_device_path,
> +							 &dp_lf2_handle,
> +							 /* LOAD_FILE2 */
> +							 &efi_guid_load_file2_protocol,
> +							 (void *)&efi_lf2_protocol,

The (void *) conversion is not needed.

> +							 NULL);

This will delete the handle if the called application has not installed
additional protocols on the handle.

Except for the (void *) conversion

Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

>   	efi_initrd_handle = NULL;
> +
> +	return ret;
>   }
Ilias Apalodimas Oct. 16, 2022, 8:38 a.m. UTC | #2
Hi Heinrich, 

[...]

> > -void efi_initrd_deregister(void)
> > +efi_status_t efi_initrd_deregister(void)
> >   {
> > +	efi_status_t ret;
> > +
> >   	if (!efi_initrd_handle)
> > -		return;
> > +		return EFI_SUCCESS;
> > 
> > -	efi_delete_handle(efi_initrd_handle);
> > +	ret = efi_uninstall_multiple_protocol_interfaces(efi_initrd_handle,
> > +							 /* initramfs */
> > +							 &efi_guid_device_path,
> > +							 &dp_lf2_handle,
> > +							 /* LOAD_FILE2 */
> > +							 &efi_guid_load_file2_protocol,
> > +							 (void *)&efi_lf2_protocol,
> 
> The (void *) conversion is not needed.
> 
> > +							 NULL);
> 
> This will delete the handle if the called application has not installed
> additional protocols on the handle.
> 
> Except for the (void *) conversion

Fair enough.  This was a c/p from
efi_install_multiple_protocol_interfaces() so on v2 I've cleaned that up as
well

> 
> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

Thanks!
/Ilias
> 
> >   	efi_initrd_handle = NULL;
> > +
> > +	return ret;
> >   }
diff mbox series

Patch

diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index b93c0d3d4c02..2a7d42925d65 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -394,8 +394,10 @@  static efi_status_t do_bootefi_exec(efi_handle_t handle, void *load_options)
 out:
 	free(load_options);
 
-	if (IS_ENABLED(CONFIG_EFI_LOAD_FILE2_INITRD))
-		efi_initrd_deregister();
+	if (IS_ENABLED(CONFIG_EFI_LOAD_FILE2_INITRD)) {
+		if (efi_initrd_deregister() != EFI_SUCCESS)
+			log_err("Failed to remove loadfile2 for initrd\n");
+	}
 
 	/* Control is returned to U-Boot, disable EFI watchdog */
 	efi_set_watchdog(0);
diff --git a/include/efi_loader.h b/include/efi_loader.h
index 1bac3f49a3e5..0c6c95ba4641 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -570,7 +570,7 @@  efi_status_t efi_net_register(void);
 /* Called by bootefi to make the watchdog available */
 efi_status_t efi_watchdog_register(void);
 efi_status_t efi_initrd_register(void);
-void efi_initrd_deregister(void);
+efi_status_t efi_initrd_deregister(void);
 /* Called by bootefi to make SMBIOS tables available */
 /**
  * efi_acpi_register() - write out ACPI tables
diff --git a/lib/efi_loader/efi_load_initrd.c b/lib/efi_loader/efi_load_initrd.c
index 87fde3f88c2b..7a345d3fe41e 100644
--- a/lib/efi_loader/efi_load_initrd.c
+++ b/lib/efi_loader/efi_load_initrd.c
@@ -227,11 +227,22 @@  efi_status_t efi_initrd_register(void)
  *
  * Return:	status code
  */
-void efi_initrd_deregister(void)
+efi_status_t efi_initrd_deregister(void)
 {
+	efi_status_t ret;
+
 	if (!efi_initrd_handle)
-		return;
+		return EFI_SUCCESS;
 
-	efi_delete_handle(efi_initrd_handle);
+	ret = efi_uninstall_multiple_protocol_interfaces(efi_initrd_handle,
+							 /* initramfs */
+							 &efi_guid_device_path,
+							 &dp_lf2_handle,
+							 /* LOAD_FILE2 */
+							 &efi_guid_load_file2_protocol,
+							 (void *)&efi_lf2_protocol,
+							 NULL);
 	efi_initrd_handle = NULL;
+
+	return ret;
 }