[PATCH 3/8] conf: Drop needless setting of VIR_DOMAIN_TPM_VERSION_DEFAULT

Michal Privoznik posted 8 patches 3 years, 6 months ago
[PATCH 3/8] conf: Drop needless setting of VIR_DOMAIN_TPM_VERSION_DEFAULT
Posted by Michal Privoznik 3 years, 6 months ago
In previous commit the VIR_DOMAIN_TPM_VERSION_DEFAULT value was
made just an alias to value of 0. And since all newly allocated
memory is zeroed out (due to use of g_new0()), the def->version
inside of virDomainTPMDefParseXML() is also 0 and thus there is
no need to set it explicitly.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/conf/domain_conf.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 6c178783af..2d8989e4ff 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -10397,15 +10397,12 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt,
     }
 
     version = virXMLPropString(backends[0], "version");
-    if (!version) {
-        def->version = VIR_DOMAIN_TPM_VERSION_DEFAULT;
-    } else {
-        if ((def->version = virDomainTPMVersionTypeFromString(version)) <= 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("Unsupported TPM version '%s'"),
-                           version);
-            goto error;
-        }
+    if (version &&
+        (def->version = virDomainTPMVersionTypeFromString(version)) <= 0) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("Unsupported TPM version '%s'"),
+                       version);
+        goto error;
     }
 
     switch (def->type) {
-- 
2.35.1
Re: [PATCH 3/8] conf: Drop needless setting of VIR_DOMAIN_TPM_VERSION_DEFAULT
Posted by Peter Krempa 3 years, 6 months ago
On Mon, Jul 18, 2022 at 11:30:45 +0200, Michal Privoznik wrote:
> In previous commit the VIR_DOMAIN_TPM_VERSION_DEFAULT value was
> made just an alias to value of 0.

This is true even now.

> And since all newly allocated
> memory is zeroed out (due to use of g_new0()), the def->version
> inside of virDomainTPMDefParseXML() is also 0 and thus there is
> no need to set it explicitly.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/conf/domain_conf.c | 15 ++++++---------
>  1 file changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index 6c178783af..2d8989e4ff 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -10397,15 +10397,12 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt,
>      }
>  
>      version = virXMLPropString(backends[0], "version");
> -    if (!version) {
> -        def->version = VIR_DOMAIN_TPM_VERSION_DEFAULT;
> -    } else {
> -        if ((def->version = virDomainTPMVersionTypeFromString(version)) <= 0) {
> -            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> -                           _("Unsupported TPM version '%s'"),
> -                           version);
> -            goto error;
> -        }
> +    if (version &&
> +        (def->version = virDomainTPMVersionTypeFromString(version)) <= 0) {
> +        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> +                       _("Unsupported TPM version '%s'"),
> +                       version);

You can use:

Reviewed-by: Peter Krempa <pkrempa@redhat.com>

With appropriate adaptation if previous patch ends up to be modified.