* [PATCH] efi/tpm: Extract duplicate code into independent functions
@ 2020-10-29 13:49 Tianjia Zhang
2020-12-02 16:38 ` Daniel Kiper
0 siblings, 1 reply; 2+ messages in thread
From: Tianjia Zhang @ 2020-10-29 13:49 UTC (permalink / raw)
To: Daniel Kiper, grub-devel; +Cc: Tianjia Zhang
Part of the code logic for processing the return value of efi
log_extend_event is repetitive and complicated. Extract the
repetitive code into an independent function.
Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
---
grub-core/commands/efi/tpm.c | 55 +++++++++++++++---------------------
1 file changed, 23 insertions(+), 32 deletions(-)
diff --git a/grub-core/commands/efi/tpm.c b/grub-core/commands/efi/tpm.c
index 49964feb9..5cc9ca2d1 100644
--- a/grub-core/commands/efi/tpm.c
+++ b/grub-core/commands/efi/tpm.c
@@ -127,6 +127,27 @@ grub_tpm_handle_find (grub_efi_handle_t *tpm_handle,
return 0;
}
+static grub_err_t
+grub_efi_log_event_status(grub_efi_status_t status)
+{
+ switch (status)
+ {
+ case GRUB_EFI_SUCCESS:
+ return 0;
+ case GRUB_EFI_DEVICE_ERROR:
+ return grub_error (GRUB_ERR_IO, N_("Command failed"));
+ case GRUB_EFI_INVALID_PARAMETER:
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Invalid parameter"));
+ case GRUB_EFI_BUFFER_TOO_SMALL:
+ return grub_error (GRUB_ERR_BAD_ARGUMENT,
+ N_("Output buffer too small"));
+ case GRUB_EFI_NOT_FOUND:
+ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("TPM unavailable"));
+ default:
+ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("Unknown TPM error"));
+ }
+}
+
static grub_err_t
grub_tpm1_log_event (grub_efi_handle_t tpm_handle, unsigned char *buf,
grub_size_t size, grub_uint8_t pcr,
@@ -160,22 +181,7 @@ grub_tpm1_log_event (grub_efi_handle_t tpm_handle, unsigned char *buf,
algorithm, event, &eventnum, &lastevent);
grub_free (event);
- switch (status)
- {
- case GRUB_EFI_SUCCESS:
- return 0;
- case GRUB_EFI_DEVICE_ERROR:
- return grub_error (GRUB_ERR_IO, N_("Command failed"));
- case GRUB_EFI_INVALID_PARAMETER:
- return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Invalid parameter"));
- case GRUB_EFI_BUFFER_TOO_SMALL:
- return grub_error (GRUB_ERR_BAD_ARGUMENT,
- N_("Output buffer too small"));
- case GRUB_EFI_NOT_FOUND:
- return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("TPM unavailable"));
- default:
- return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("Unknown TPM error"));
- }
+ return grub_efi_log_event_status(status);
}
static grub_err_t
@@ -211,22 +217,7 @@ grub_tpm2_log_event (grub_efi_handle_t tpm_handle, unsigned char *buf,
(grub_uint64_t) size, event);
grub_free (event);
- switch (status)
- {
- case GRUB_EFI_SUCCESS:
- return 0;
- case GRUB_EFI_DEVICE_ERROR:
- return grub_error (GRUB_ERR_IO, N_("Command failed"));
- case GRUB_EFI_INVALID_PARAMETER:
- return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Invalid parameter"));
- case GRUB_EFI_BUFFER_TOO_SMALL:
- return grub_error (GRUB_ERR_BAD_ARGUMENT,
- N_("Output buffer too small"));
- case GRUB_EFI_NOT_FOUND:
- return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("TPM unavailable"));
- default:
- return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("Unknown TPM error"));
- }
+ return grub_efi_log_event_status(status);
}
grub_err_t
--
2.19.1.3.ge56e4f7
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] efi/tpm: Extract duplicate code into independent functions
2020-10-29 13:49 [PATCH] efi/tpm: Extract duplicate code into independent functions Tianjia Zhang
@ 2020-12-02 16:38 ` Daniel Kiper
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Kiper @ 2020-12-02 16:38 UTC (permalink / raw)
To: Tianjia Zhang; +Cc: Daniel Kiper, grub-devel
On Thu, Oct 29, 2020 at 09:49:49PM +0800, Tianjia Zhang wrote:
> Part of the code logic for processing the return value of efi
> log_extend_event is repetitive and complicated. Extract the
> repetitive code into an independent function.
>
> Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Daniel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-12-02 16:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-29 13:49 [PATCH] efi/tpm: Extract duplicate code into independent functions Tianjia Zhang
2020-12-02 16:38 ` Daniel Kiper
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.