efi_loader: Remove incorrect calls of EFI_CALL in TCG2
authorIlias Apalodimas <ilias.apalodimas@linaro.org>
Wed, 8 Sep 2021 21:30:49 +0000 (00:30 +0300)
committerHeinrich Schuchardt <xypron.glpk@gmx.de>
Sat, 11 Sep 2021 09:02:02 +0000 (11:02 +0200)
There is two unneeded EFI_CALL references in tcg2_measure_pe_image().
The first one in efi_search_protocol() and the second on in the device path
calculation.  The second isn't even a function we should be calling, but a
pointer assignment, which happens to work with the existing macro.

While at it switch the malloc call to a calloc, remove the unnecessary cast
and get rid of an unneeded if statement before copying the device path

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
lib/efi_loader/efi_tcg2.c

index 62ae102..cb48919 100644 (file)
@@ -865,20 +865,19 @@ efi_status_t tcg2_measure_pe_image(void *efi, u64 efi_size,
        if (ret != EFI_SUCCESS)
                return ret;
 
-       ret = EFI_CALL(efi_search_protocol(&handle->header,
-                                          &efi_guid_loaded_image_device_path,
-                                          &handler));
+       ret = efi_search_protocol(&handle->header,
+                                 &efi_guid_loaded_image_device_path, &handler);
        if (ret != EFI_SUCCESS)
                return ret;
 
-       device_path = EFI_CALL(handler->protocol_interface);
+       device_path = handler->protocol_interface;
        device_path_length = efi_dp_size(device_path);
        if (device_path_length > 0) {
                /* add end node size */
                device_path_length += sizeof(struct efi_device_path);
        }
        event_size = sizeof(struct uefi_image_load_event) + device_path_length;
-       image_load_event = (struct uefi_image_load_event *)malloc(event_size);
+       image_load_event = calloc(1, event_size);
        if (!image_load_event)
                return EFI_OUT_OF_RESOURCES;
 
@@ -901,10 +900,8 @@ efi_status_t tcg2_measure_pe_image(void *efi, u64 efi_size,
                goto out;
        }
 
-       if (device_path_length > 0) {
-               memcpy(image_load_event->device_path, device_path,
-                      device_path_length);
-       }
+       /* device_path_length might be zero */
+       memcpy(image_load_event->device_path, device_path, device_path_length);
 
        ret = tcg2_agile_log_append(pcr_index, event_type, &digest_list,
                                    event_size, (u8 *)image_load_event);