Merge tag 'efi-2019-07-rc3-3' of git://git.denx.de/u-boot-efi
[oweals/u-boot.git] / lib / efi_loader / efi_boottime.c
index b8589b9531c0c87f47df7b45f1fd90853c41a8d4..54fff85e64efff2e0dc49160331aa8e689b352bc 100644 (file)
@@ -181,10 +181,12 @@ static void efi_queue_event(struct efi_event *event, bool check_tpl)
                /* Check TPL */
                if (check_tpl && efi_tpl >= event->notify_tpl)
                        return;
+               event->is_queued = false;
                EFI_CALL_VOID(event->notify_function(event,
                                                     event->notify_context));
+       } else {
+               event->is_queued = false;
        }
-       event->is_queued = false;
 }
 
 /**
@@ -514,7 +516,7 @@ efi_status_t efi_remove_protocol(const efi_handle_t handle,
        if (ret != EFI_SUCCESS)
                return ret;
        if (handler->protocol_interface != protocol_interface)
-               return EFI_INVALID_PARAMETER;
+               return EFI_NOT_FOUND;
        list_del(&handler->link);
        free(handler);
        return EFI_SUCCESS;
@@ -1914,10 +1916,17 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle,
 static efi_status_t EFIAPI efi_get_next_monotonic_count(uint64_t *count)
 {
        static uint64_t mono;
+       efi_status_t ret;
 
        EFI_ENTRY("%p", count);
+       if (!count) {
+               ret = EFI_INVALID_PARAMETER;
+               goto out;
+       }
        *count = mono++;
-       return EFI_EXIT(EFI_SUCCESS);
+       ret = EFI_SUCCESS;
+out:
+       return EFI_EXIT(ret);
 }
 
 /**
@@ -2332,6 +2341,7 @@ efi_status_t EFIAPI efi_install_multiple_protocol_interfaces
        efi_va_list argptr;
        const efi_guid_t *protocol;
        void *protocol_interface;
+       efi_handle_t old_handle;
        efi_status_t r = EFI_SUCCESS;
        int i = 0;
 
@@ -2344,6 +2354,20 @@ efi_status_t EFIAPI efi_install_multiple_protocol_interfaces
                if (!protocol)
                        break;
                protocol_interface = efi_va_arg(argptr, void*);
+               /* Check that a device path has not been installed before */
+               if (!guidcmp(protocol, &efi_guid_device_path)) {
+                       struct efi_device_path *dp = protocol_interface;
+
+                       r = EFI_CALL(efi_locate_device_path(protocol, &dp,
+                                                           &old_handle));
+                       if (r == EFI_SUCCESS &&
+                           dp->type == DEVICE_PATH_TYPE_END) {
+                               EFI_PRINT("Path %pD already installed\n",
+                                         protocol_interface);
+                               r = EFI_ALREADY_STARTED;
+                               break;
+                       }
+               }
                r = EFI_CALL(efi_install_protocol_interface(
                                                handle, protocol,
                                                EFI_NATIVE_INTERFACE,
@@ -2451,9 +2475,16 @@ static efi_status_t EFIAPI efi_calculate_crc32(const void *data,
                                               efi_uintn_t data_size,
                                               u32 *crc32_p)
 {
+       efi_status_t ret = EFI_SUCCESS;
+
        EFI_ENTRY("%p, %zu", data, data_size);
+       if (!data || !data_size || !crc32_p) {
+               ret = EFI_INVALID_PARAMETER;
+               goto out;
+       }
        *crc32_p = crc32(0, data, data_size);
-       return EFI_EXIT(EFI_SUCCESS);
+out:
+       return EFI_EXIT(ret);
 }
 
 /**