[PATCH 1/7] qemu_capabilities.c: use g_autofree in virQEMUCapsLoadCache()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use autofree with 'str' and 'nodes' to get rid of the 'cleanup'
label.

Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
---
 src/qemu/qemu_capabilities.c | 66 ++++++++++++++++--------------------
 1 file changed, 30 insertions(+), 36 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 67fae46a34..aef76ecc56 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -4125,20 +4125,19 @@ virQEMUCapsLoadCache(virArch hostArch,
                      bool skipInvalidation)
 {
     g_autoptr(xmlDoc) doc = NULL;
-    int ret = -1;
     size_t i;
     int n;
-    xmlNodePtr *nodes = NULL;
+    g_autofree xmlNodePtr *nodes = NULL;
     g_autoptr(xmlXPathContext) ctxt = NULL;
-    char *str = NULL;
+    g_autofree char *str = NULL;
     long long int l;
     unsigned long lu;
 
     if (!(doc = virXMLParseFile(filename)))
-        goto cleanup;
+        return -1;
 
     if (!(ctxt = virXMLXPathContextNew(doc)))
-        goto cleanup;
+        return -1;
 
     ctxt->node = xmlDocGetRootElement(doc);
 
@@ -4147,13 +4146,13 @@ virQEMUCapsLoadCache(virArch hostArch,
                        _("unexpected root element <%s>, "
                          "expecting <qemuCaps>"),
                        ctxt->node->name);
-        goto cleanup;
+        return -1;
     }
 
     if (virXPathLongLong("string(./selfctime)", ctxt, &l) < 0) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("missing selfctime in QEMU capabilities XML"));
-        goto cleanup;
+        return -1;
     }
     qemuCaps->libvirtCtime = (time_t)l;
 
@@ -4171,26 +4170,25 @@ virQEMUCapsLoadCache(virArch hostArch,
                   (long long)virGetSelfLastChanged(),
                   (unsigned long)qemuCaps->libvirtVersion,
                   (unsigned long)LIBVIR_VERSION_NUMBER);
-        ret = 1;
-        goto cleanup;
+        return 1;
     }
 
     if (!(str = virXPathString("string(./emulator)", ctxt))) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("missing emulator in QEMU capabilities cache"));
-        goto cleanup;
+        return -1;
     }
     if (STRNEQ(str, qemuCaps->binary)) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Expected caps for '%s' but saw '%s'"),
                        qemuCaps->binary, str);
-        goto cleanup;
+        return -1;
     }
     VIR_FREE(str);
     if (virXPathLongLong("string(./qemuctime)", ctxt, &l) < 0) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("missing qemuctime in QEMU capabilities XML"));
-        goto cleanup;
+        return -1;
     }
     qemuCaps->ctime = (time_t)l;
 
@@ -4200,7 +4198,7 @@ virQEMUCapsLoadCache(virArch hostArch,
     if ((n = virXPathNodeSet("./flag", ctxt, &nodes)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("failed to parse qemu capabilities flags"));
-        goto cleanup;
+        return -1;
     }
     VIR_DEBUG("Got flags %d", n);
     for (i = 0; i < n; i++) {
@@ -4208,13 +4206,13 @@ virQEMUCapsLoadCache(virArch hostArch,
         if (!(str = virXMLPropString(nodes[i], "name"))) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("missing flag name in QEMU capabilities cache"));
-            goto cleanup;
+            return -1;
         }
         flag = virQEMUCapsTypeFromString(str);
         if (flag < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Unknown qemu capabilities flag %s"), str);
-            goto cleanup;
+            return -1;
         }
         VIR_FREE(str);
         virQEMUCapsSet(qemuCaps, flag);
@@ -4224,20 +4222,20 @@ virQEMUCapsLoadCache(virArch hostArch,
     if (virXPathUInt("string(./version)", ctxt, &qemuCaps->version) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("missing version in QEMU capabilities cache"));
-        goto cleanup;
+        return -1;
     }
 
     if (virXPathUInt("string(./kvmVersion)", ctxt, &qemuCaps->kvmVersion) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("missing version in QEMU capabilities cache"));
-        goto cleanup;
+        return -1;
     }
 
     if (virXPathUInt("string(./microcodeVersion)", ctxt,
                      &qemuCaps->microcodeVersion) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("missing microcode version in QEMU capabilities cache"));
-        goto cleanup;
+        return -1;
     }
 
     qemuCaps->hostCPUSignature = virXPathString("string(./hostCPUSignature)", ctxt);
@@ -4251,35 +4249,35 @@ virQEMUCapsLoadCache(virArch hostArch,
     if (virXPathBoolean("boolean(./kernelVersion)", ctxt) > 0) {
         qemuCaps->kernelVersion = virXPathString("string(./kernelVersion)", ctxt);
         if (!qemuCaps->kernelVersion)
-            goto cleanup;
+            return -1;
     }
 
     if (!(str = virXPathString("string(./arch)", ctxt))) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("missing arch in QEMU capabilities cache"));
-        goto cleanup;
+        return -1;
     }
     if (!(qemuCaps->arch = virArchFromString(str))) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unknown arch %s in QEMU capabilities cache"), str);
-        goto cleanup;
+        return -1;
     }
     VIR_FREE(str);
 
     if (virXPathBoolean("boolean(./cpudata)", ctxt) > 0) {
         qemuCaps->cpuData = virCPUDataParseNode(virXPathNode("./cpudata", ctxt));
         if (!qemuCaps->cpuData)
-            goto cleanup;
+            return -1;
     }
 
     if (virQEMUCapsLoadAccel(qemuCaps, ctxt, VIR_DOMAIN_VIRT_KVM) < 0 ||
         virQEMUCapsLoadAccel(qemuCaps, ctxt, VIR_DOMAIN_VIRT_QEMU) < 0)
-        goto cleanup;
+        return -1;
 
     if ((n = virXPathNodeSet("./gic", ctxt, &nodes)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("failed to parse qemu capabilities gic"));
-        goto cleanup;
+        return -1;
     }
     if (n > 0) {
         unsigned int uintValue;
@@ -4295,13 +4293,13 @@ virQEMUCapsLoadCache(virArch hostArch,
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("missing GIC version "
                                  "in QEMU capabilities cache"));
-                goto cleanup;
+                return -1;
             }
             if (virStrToLong_ui(str, NULL, 10, &uintValue) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("malformed GIC version "
                                  "in QEMU capabilities cache"));
-                goto cleanup;
+                return -1;
             }
             cap->version = uintValue;
             VIR_FREE(str);
@@ -4310,13 +4308,13 @@ virQEMUCapsLoadCache(virArch hostArch,
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("missing in-kernel GIC information "
                                  "in QEMU capabilities cache"));
-                goto cleanup;
+                return -1;
             }
             if (!(boolValue = STREQ(str, "yes")) && STRNEQ(str, "no")) {
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("malformed in-kernel GIC information "
                                  "in QEMU capabilities cache"));
-                goto cleanup;
+                return -1;
             }
             if (boolValue)
                 cap->implementation |= VIR_GIC_IMPLEMENTATION_KERNEL;
@@ -4326,13 +4324,13 @@ virQEMUCapsLoadCache(virArch hostArch,
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("missing emulated GIC information "
                                  "in QEMU capabilities cache"));
-                goto cleanup;
+                return -1;
             }
             if (!(boolValue = STREQ(str, "yes")) && STRNEQ(str, "no")) {
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("malformed emulated GIC information "
                                  "in QEMU capabilities cache"));
-                goto cleanup;
+                return -1;
             }
             if (boolValue)
                 cap->implementation |= VIR_GIC_IMPLEMENTATION_EMULATED;
@@ -4342,7 +4340,7 @@ virQEMUCapsLoadCache(virArch hostArch,
     VIR_FREE(nodes);
 
     if (virQEMUCapsParseSEVInfo(qemuCaps, ctxt) < 0)
-        goto cleanup;
+        return -1;
 
     virQEMUCapsInitHostCPUModel(qemuCaps, hostArch, VIR_DOMAIN_VIRT_KVM);
     virQEMUCapsInitHostCPUModel(qemuCaps, hostArch, VIR_DOMAIN_VIRT_QEMU);
@@ -4356,11 +4354,7 @@ virQEMUCapsLoadCache(virArch hostArch,
     if (skipInvalidation)
         qemuCaps->invalidation = false;
 
-    ret = 0;
- cleanup:
-    VIR_FREE(str);
-    VIR_FREE(nodes);
-    return ret;
+    return 0;
 }
 
 
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux