[PATCH 07/21] domain_conf.c: use g_autoptr() with virDomainVideoDefPtr

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

 



This will modernize virDomainVideoDefParseXML() and
virDomainDefAddImplicitVideo() by removing unneeded
cleanup labels.

Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
---
 src/conf/domain_conf.c | 48 ++++++++++++++++++------------------------
 1 file changed, 20 insertions(+), 28 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 521a7cee3a..8352c60473 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -16179,7 +16179,7 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
                           xmlXPathContextPtr ctxt,
                           unsigned int flags)
 {
-    virDomainVideoDefPtr def;
+    g_autoptr(virDomainVideoDef) def = NULL;
     xmlNodePtr cur;
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
     g_autofree char *type = NULL;
@@ -16220,12 +16220,12 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
                         if (def->accel == NULL &&
                             virXMLNodeNameEqual(child, "acceleration")) {
                             if ((def->accel = virDomainVideoAccelDefParseXML(child)) == NULL)
-                                goto error;
+                                return NULL;
                         }
                         if (def->res == NULL &&
                             virXMLNodeNameEqual(child, "resolution")) {
                             if ((def->res = virDomainVideoResolutionDefParseXML(child)) == NULL)
-                                goto error;
+                                return NULL;
                         }
                     }
                     child = child->next;
@@ -16233,7 +16233,7 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
             }
             if (virXMLNodeNameEqual(cur, "driver")) {
                 if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0)
-                    goto error;
+                    return NULL;
                 driver_name = virXMLPropString(cur, "name");
             }
         }
@@ -16244,7 +16244,7 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
         if ((def->type = virDomainVideoTypeFromString(type)) < 0) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("unknown video model '%s'"), type);
-            goto error;
+            return NULL;
         }
     } else {
         def->type = VIR_DOMAIN_VIDEO_TYPE_DEFAULT;
@@ -16255,7 +16255,7 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
         if ((backend = virDomainVideoBackendTypeFromString(driver_name)) <= 0) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("unknown video driver '%s'"), driver_name);
-            goto error;
+            return NULL;
         }
         def->backend = backend;
     } else {
@@ -16266,12 +16266,12 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
         if (def->type != VIR_DOMAIN_VIDEO_TYPE_QXL) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("ram attribute only supported for type of qxl"));
-            goto error;
+            return NULL;
         }
         if (virStrToLong_uip(ram, NULL, 10, &def->ram) < 0) {
             virReportError(VIR_ERR_XML_ERROR,
                            _("cannot parse video ram '%s'"), ram);
-            goto error;
+            return NULL;
         }
     }
 
@@ -16279,7 +16279,7 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
         if (virStrToLong_uip(vram, NULL, 10, &def->vram) < 0) {
             virReportError(VIR_ERR_XML_ERROR,
                            _("cannot parse video vram '%s'"), vram);
-            goto error;
+            return NULL;
         }
     }
 
@@ -16287,12 +16287,12 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
         if (def->type != VIR_DOMAIN_VIDEO_TYPE_QXL) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("vram64 attribute only supported for type of qxl"));
-            goto error;
+            return NULL;
         }
         if (virStrToLong_uip(vram64, NULL, 10, &def->vram64) < 0) {
             virReportError(VIR_ERR_XML_ERROR,
                            _("cannot parse video vram64 '%s'"), vram64);
-            goto error;
+            return NULL;
         }
     }
 
@@ -16300,12 +16300,12 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
         if (def->type != VIR_DOMAIN_VIDEO_TYPE_QXL) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("vgamem attribute only supported for type of qxl"));
-            goto error;
+            return NULL;
         }
         if (virStrToLong_uip(vgamem, NULL, 10, &def->vgamem) < 0) {
             virReportError(VIR_ERR_XML_ERROR,
                            _("cannot parse video vgamem '%s'"), vgamem);
-            goto error;
+            return NULL;
         }
     }
 
@@ -16313,20 +16313,16 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
         if (virStrToLong_uip(heads, NULL, 10, &def->heads) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("cannot parse video heads '%s'"), heads);
-            goto error;
+            return NULL;
         }
     }
 
     if (virDomainDeviceInfoParseXML(xmlopt, node, &def->info, flags) < 0)
-        goto error;
+        return NULL;
 
     def->driver = virDomainVideoDriverDefParseXML(node);
 
-    return def;
-
- error:
-    virDomainVideoDefFree(def);
-    return NULL;
+    return g_steal_pointer(&def);
 }
 
 static virDomainHostdevDefPtr
@@ -25038,8 +25034,7 @@ virDomainDefAddImplicitControllers(virDomainDefPtr def)
 static int
 virDomainDefAddImplicitVideo(virDomainDefPtr def, virDomainXMLOptionPtr xmlopt)
 {
-    int ret = -1;
-    virDomainVideoDefPtr video = NULL;
+    g_autoptr(virDomainVideoDef) video = NULL;
 
     /* For backwards compatibility, if no <video> tag is set but there
      * is a <graphics> tag, then we add a single video tag */
@@ -25047,15 +25042,12 @@ virDomainDefAddImplicitVideo(virDomainDefPtr def, virDomainXMLOptionPtr xmlopt)
         return 0;
 
     if (!(video = virDomainVideoDefNew(xmlopt)))
-        goto cleanup;
+        return -1;
     video->type = VIR_DOMAIN_VIDEO_TYPE_DEFAULT;
     if (VIR_APPEND_ELEMENT(def->videos, def->nvideos, video) < 0)
-        goto cleanup;
+        return -1;
 
-    ret = 0;
- cleanup:
-    virDomainVideoDefFree(video);
-    return ret;
+    return 0;
 }
 
 int
-- 
2.26.2




[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