From: "Lee, Chun-Yi" <joeyli.kernel@gmail.com>
To: Ard Biesheuvel <ard.biesheuvel@linaro.org>,
James Morris <jmorris@namei.org>,
"Serge E . Hallyn" <serge@hallyn.com>,
David Howells <dhowells@redhat.com>,
Josh Boyer <jwboyer@fedoraproject.org>,
Nayna Jain <nayna@linux.ibm.com>,
Mimi Zohar <zohar@linux.ibm.com>
Cc: linux-efi@vger.kernel.org, linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org, "Lee, Chun-Yi" <jlee@suse.com>
Subject: [PATCH 1/2 v2] efi: add a function to convert the status code to a string
Date: Fri, 13 Dec 2019 17:06:45 +0800 [thread overview]
Message-ID: <20191213090646.12329-2-jlee@suse.com> (raw)
In-Reply-To: <20191213090646.12329-1-jlee@suse.com>
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
Signed-off-by: "Lee, Chun-Yi" <jlee@suse.com>
---
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
next prev parent reply other threads:[~2019-12-13 9:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-13 9:06 [PATCH 0/2 v2] efi: cosmetic patches for the error messages when Lee, Chun-Yi
2019-12-13 9:06 ` Lee, Chun-Yi [this message]
2019-12-13 10:03 ` [PATCH 1/2 v2] efi: add a function to convert the status code to a string Ard Biesheuvel
2019-12-13 10:33 ` Joey Lee
2019-12-13 9:06 ` [PATCH 2/2] efi: show error messages only when loading certificates is failed Lee, Chun-Yi
2019-12-13 9:10 ` Ard Biesheuvel
2019-12-13 9:20 ` Joey Lee
2019-12-13 10:04 ` Ard Biesheuvel
2019-12-13 10:35 ` Joey Lee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191213090646.12329-2-jlee@suse.com \
--to=joeyli.kernel@gmail.com \
--cc=ard.biesheuvel@linaro.org \
--cc=dhowells@redhat.com \
--cc=jlee@suse.com \
--cc=jmorris@namei.org \
--cc=jwboyer@fedoraproject.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=nayna@linux.ibm.com \
--cc=serge@hallyn.com \
--cc=zohar@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).