Message ID | 20200722112333.29966-2-philmd@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | tpm: Improve error reporting | expand |
On 7/22/20 7:23 AM, Philippe Mathieu-Daudé wrote: > 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; Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
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.
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;
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(+)