]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
domain_conf.c: modernize virDomainSmartcardDefParseXML
authorDaniel Henrique Barboza <danielhb413@gmail.com>
Fri, 20 Nov 2020 19:09:13 +0000 (16:09 -0300)
committerDaniel Henrique Barboza <danielhb413@gmail.com>
Tue, 1 Dec 2020 22:27:17 +0000 (19:27 -0300)
Register a AUTOPTR_CLEANUP_FUNC for virDomainSmartcardDef and use
g_autoptr() to eliminate the 'error' label.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
src/conf/domain_conf.c
src/conf/domain_conf.h

index 6799efe3d487733ff37dc887645f99cfe6fe99cc..0fb7becf6e6c2096995d6cd678c3bc9e7bb31651 100644 (file)
@@ -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
index cef17efe73eeeada89f5fa39c64e0bff5594e73f..694f015011fa79d8fec975c22911f8a7f4f0df89 100644 (file)
@@ -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);