[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH-for-5.1 1/2] tpm: Display when no backend is available
From: |
Markus Armbruster |
Subject: |
Re: [PATCH-for-5.1 1/2] tpm: Display when no backend is available |
Date: |
Thu, 23 Jul 2020 12:40:45 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) |
Philippe Mathieu-Daudé <philmd@redhat.com> writes:
> 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.");
Scratch the '.', please. From error_setg()'s contract:
* The resulting message should be a single phrase, with no newline or
* trailing punctuation.
> + return 1;
> + }
> +
> if (!QLIST_EMPTY(&tpm_backends)) {
> error_setg(errp, "Only one TPM is allowed.");
> return 1;
This works, but it's more code than I'd like to see for the purpose.
Moreover, it's tied to the error handling issue discussed in
Subject: Re: What is TYPE_TPM_TIS_ISA? (Not an ISA Device)
Message-ID: <87tuxyoauy.fsf@dusky.pond.sub.org>
If we revert flawed commit d10e05f15d5, then your patch needs a v2.
Your PATCH 2 might become unnecessary. I'll give it a quick try to see
how it comes out.