[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH-for-5.1 1/2] tpm: Display when no backend is available
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH-for-5.1 1/2] tpm: Display when no backend is available |
Date: |
Wed, 22 Jul 2020 13:23:32 +0200 |
Display "No TPM backend available in this binary." error when
no backend is available.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
tpm.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/tpm.c b/tpm.c
index fe03b24858..e36803a64d 100644
--- a/tpm.c
+++ b/tpm.c
@@ -41,6 +41,22 @@ tpm_be_find_by_type(enum TpmType type)
return TPM_BACKEND_CLASS(oc);
}
+/*
+ * Walk the list of available TPM backend drivers and count them.
+ */
+static int tpm_backend_drivers_count(void)
+{
+ int count = 0, i;
+
+ for (i = 0; i < TPM_TYPE__MAX; i++) {
+ const TPMBackendClass *bc = tpm_be_find_by_type(i);
+ if (bc) {
+ count++;
+ }
+ }
+ return count;
+}
+
/*
* Walk the list of available TPM backend drivers and display them on the
* screen.
@@ -87,6 +103,11 @@ static int tpm_init_tpmdev(void *dummy, QemuOpts *opts,
Error **errp)
TPMBackend *drv;
int i;
+ if (!tpm_backend_drivers_count()) {
+ error_setg(errp, "No TPM backend available in this binary.");
+ return 1;
+ }
+
if (!QLIST_EMPTY(&tpm_backends)) {
error_setg(errp, "Only one TPM is allowed.");
return 1;
--
2.21.3