[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] efi/tpm: Extract duplicate code into independent functions
From: |
Tianjia Zhang |
Subject: |
[PATCH] efi/tpm: Extract duplicate code into independent functions |
Date: |
Thu, 29 Oct 2020 21:49:49 +0800 |
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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] efi/tpm: Extract duplicate code into independent functions,
Tianjia Zhang <=