Display "No TPM backend available in this binary." error when no backend is available.
Reviewed-by: Stefan Berger <stef...@linux.ibm.com> Signed-off-by: Philippe Mathieu-Daudé <phi...@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