This way when the stop() method of the EFI driver gets called
whatever bind() did can be cleaned up.

Signed-off-by: Adriano Cordova <adriano.cord...@canonical.com>
---
 include/efi_driver.h        | 4 ++++
 lib/efi_driver/efi_uclass.c | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/include/efi_driver.h b/include/efi_driver.h
index 63a95e4cf8..8f785f7945 100644
--- a/include/efi_driver.h
+++ b/include/efi_driver.h
@@ -36,6 +36,8 @@ struct efi_driver_binding_extended_protocol {
  *                     driver binding protocol.
  * @bind:              Function called by the EFI uclass to attach the
  *                     driver to EFI driver to a handle.
+ * @unbind:            Function called by the EFI uclass to detach the
+ *                     driver to EFI driver to a handle.
  */
 struct efi_driver_ops {
        const efi_guid_t *protocol;
@@ -43,6 +45,8 @@ struct efi_driver_ops {
        efi_status_t (*init)(struct efi_driver_binding_extended_protocol *this);
        efi_status_t (*bind)(struct efi_driver_binding_extended_protocol *this,
                             efi_handle_t handle, void *interface);
+       efi_status_t (*unbind)(struct efi_driver_binding_extended_protocol 
*this,
+                              efi_handle_t handle);
 };
 
 #endif /* _EFI_DRIVER_H */
diff --git a/lib/efi_driver/efi_uclass.c b/lib/efi_driver/efi_uclass.c
index 6553141f4e..393d62d3ba 100644
--- a/lib/efi_driver/efi_uclass.c
+++ b/lib/efi_driver/efi_uclass.c
@@ -247,6 +247,10 @@ static efi_status_t EFIAPI efi_uc_stop(
        if (ret != EFI_SUCCESS)
                log_err("Cannot free EFI memory pool\n");
 
+       ret = bp->ops->unbind(bp, controller_handle);
+       if (ret != EFI_SUCCESS)
+               goto out;
+
        /* Detach driver from controller */
        ret = efi_close_protocol(controller_handle, bp->ops->protocol,
                                 this->driver_binding_handle,
-- 
2.43.0

Reply via email to