From 7e5f031ff982c545a883476fc3f943488f4d87f2 Mon Sep 17 00:00:00 2001 From: Daniel Henrique Barboza Date: Fri, 20 Nov 2020 16:09:13 -0300 Subject: [PATCH] domain_conf.c: modernize virDomainSmartcardDefParseXML Register a AUTOPTR_CLEANUP_FUNC for virDomainSmartcardDef and use g_autoptr() to eliminate the 'error' label. Reviewed-by: Michal Privoznik Signed-off-by: Daniel Henrique Barboza --- src/conf/domain_conf.c | 37 +++++++++++++++++-------------------- src/conf/domain_conf.h | 1 + 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6799efe3d4..0fb7becf6e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13523,7 +13523,7 @@ virDomainSmartcardDefParseXML(virDomainXMLOptionPtr xmlopt, unsigned int flags) { xmlNodePtr cur; - virDomainSmartcardDefPtr def; + g_autoptr(virDomainSmartcardDef) def = NULL; size_t i; g_autofree char *mode = NULL; g_autofree char *type = NULL; @@ -13534,13 +13534,13 @@ virDomainSmartcardDefParseXML(virDomainXMLOptionPtr xmlopt, if (mode == NULL) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing smartcard device mode")); - goto error; + return NULL; } if ((def->type = virDomainSmartcardTypeFromString(mode)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown smartcard device mode: %s"), mode); - goto error; + return NULL; } switch (def->type) { @@ -13557,23 +13557,23 @@ virDomainSmartcardDefParseXML(virDomainXMLOptionPtr xmlopt, virReportError(VIR_ERR_XML_ERROR, "%s", _("host-certificates mode needs " "exactly three certificates")); - goto error; + return NULL; } if (!(def->data.cert.file[i] = virXMLNodeContentString(cur))) - goto error; + return NULL; i++; } else if (cur->type == XML_ELEMENT_NODE && virXMLNodeNameEqual(cur, "database") && !def->data.cert.database) { if (!(def->data.cert.database = virXMLNodeContentString(cur))) - goto error; + return NULL; if (*def->data.cert.database != '/') { virReportError(VIR_ERR_XML_ERROR, _("expecting absolute path: %s"), def->data.cert.database); - goto error; + return NULL; } } cur = cur->next; @@ -13582,7 +13582,7 @@ virDomainSmartcardDefParseXML(virDomainXMLOptionPtr xmlopt, virReportError(VIR_ERR_XML_ERROR, "%s", _("host-certificates mode needs " "exactly three certificates")); - goto error; + return NULL; } break; @@ -13592,23 +13592,23 @@ virDomainSmartcardDefParseXML(virDomainXMLOptionPtr xmlopt, virReportError(VIR_ERR_XML_ERROR, "%s", _("passthrough mode requires a character " "device type attribute")); - goto error; + return NULL; } if (!(def->data.passthru = virDomainChrSourceDefNew(xmlopt))) - goto error; + return NULL; if ((def->data.passthru->type = virDomainChrTypeFromString(type)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown type presented to host for " "character device: %s"), type); - goto error; + return NULL; } cur = node->children; if (virDomainChrSourceDefParseXML(def->data.passthru, cur, flags, NULL, ctxt) < 0) - goto error; + return NULL; if (def->data.passthru->type == VIR_DOMAIN_CHR_TYPE_SPICEVMC) { def->data.passthru->data.spicevmc @@ -13620,23 +13620,20 @@ virDomainSmartcardDefParseXML(virDomainXMLOptionPtr xmlopt, default: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("unknown smartcard mode")); - goto error; + return NULL; } if (virDomainDeviceInfoParseXML(xmlopt, node, &def->info, flags) < 0) - goto error; + return NULL; + if (def->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE && def->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCID) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Controllers must use the 'ccid' address type")); - goto error; + return NULL; } - return def; - - error: - virDomainSmartcardDefFree(def); - return NULL; + return g_steal_pointer(&def); } /* Parse the XML definition for a TPM device diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index cef17efe73..694f015011 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3070,6 +3070,7 @@ void virDomainVsockDefFree(virDomainVsockDefPtr vsock); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainVsockDef, virDomainVsockDefFree); void virDomainNetDefFree(virDomainNetDefPtr def); void virDomainSmartcardDefFree(virDomainSmartcardDefPtr def); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainSmartcardDef, virDomainSmartcardDefFree); void virDomainChrDefFree(virDomainChrDefPtr def); int virDomainChrSourceDefCopy(virDomainChrSourceDefPtr dest, virDomainChrSourceDefPtr src);