Thread (9 messages) 9 messages, 3 authors, 2019-12-13

Re: [PATCH 1/2 v2] efi: add a function to convert the status code to a string

From: Ard Biesheuvel <hidden>
Date: 2019-12-13 10:03:33
Also in: linux-efi, lkml

On Fri, 13 Dec 2019 at 10:07, Lee, Chun-Yi [off-list ref] wrote:
This function can be used to convert EFI status code to a string
to improve the readability of log.

v2:
Moved the convert function to efi.c
Please put the patch series revision log below the ---
Signed-off-by: "Lee, Chun-Yi" <jlee@suse.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
quoted hunk ↗ jump to hunk
---
 drivers/firmware/efi/efi.c | 32 ++++++++++++++++++++++++++++++++
 include/linux/efi.h        |  1 +
 2 files changed, 33 insertions(+)
diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index e98bbf8e56d9..8bdc1c17eb5d 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -954,6 +954,38 @@ int efi_status_to_err(efi_status_t status)
        return err;
 }

+#define EFI_STATUS_STR(_status) \
+       EFI_##_status : return "EFI_" __stringify(_status)
+
+const char *efi_status_to_str(efi_status_t status)
+{
+       switch (status) {
+       case EFI_STATUS_STR(SUCCESS);
+       case EFI_STATUS_STR(LOAD_ERROR);
+       case EFI_STATUS_STR(INVALID_PARAMETER);
+       case EFI_STATUS_STR(UNSUPPORTED);
+       case EFI_STATUS_STR(BAD_BUFFER_SIZE);
+       case EFI_STATUS_STR(BUFFER_TOO_SMALL);
+       case EFI_STATUS_STR(NOT_READY);
+       case EFI_STATUS_STR(DEVICE_ERROR);
+       case EFI_STATUS_STR(WRITE_PROTECTED);
+       case EFI_STATUS_STR(OUT_OF_RESOURCES);
+       case EFI_STATUS_STR(NOT_FOUND);
+       case EFI_STATUS_STR(ABORTED);
+       case EFI_STATUS_STR(SECURITY_VIOLATION);
+       }
+       /*
+        * There are two possibilities for this message to be exposed:
+        * - Caller feeds a unknown status code from firmware.
+        * - A new status code be defined in efi.h but we forgot to update
+        *   this function.
+        */
+       pr_warn("Unknown efi status: 0x%lx\n", status);
+
+       return "Unknown efi status";
+}
+EXPORT_SYMBOL(efi_status_to_str);
+
 static DEFINE_SPINLOCK(efi_mem_reserve_persistent_lock);
 static struct linux_efi_memreserve *efi_memreserve_root __ro_after_init;
diff --git a/include/linux/efi.h b/include/linux/efi.h
index d87acf62958e..2c6848d2b112 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -1228,6 +1228,7 @@ efi_capsule_pending(int *reset_type)
 #endif

 extern int efi_status_to_err(efi_status_t status);
+extern const char *efi_status_to_str(efi_status_t status);

 /*
  * Variable Attributes
--
2.16.4
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help