[PATCH v1 13/21] vbox: remove unneeded cleanup labels

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

 



Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
---
 src/vbox/vbox_common.c        | 12 +++---
 src/vbox/vbox_snapshot_conf.c | 75 +++++++++++++++--------------------
 2 files changed, 36 insertions(+), 51 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 475b3a3147..5ea9ef627d 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2202,21 +2202,21 @@ static int vboxDomainCreateWithFlags(virDomainPtr dom, unsigned int flags)
     int ret = -1;
 
     if (!data->vboxObj)
-        return ret;
+        return -1;
 
     virCheckFlags(0, -1);
 
     if (!dom->name) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Error while reading the domain name"));
-        goto cleanup;
+        return -1;
     }
 
     rc = gVBoxAPI.UArray.vboxArrayGet(&machines, data->vboxObj, ARRAY_GET_MACHINES);
     if (NS_FAILED(rc)) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Could not get list of machines, rc=%08x"), (unsigned)rc);
-        goto cleanup;
+        return -1;
     }
 
     for (i = 0; i < machines.count; ++i) {
@@ -2260,7 +2260,6 @@ static int vboxDomainCreateWithFlags(virDomainPtr dom, unsigned int flags)
     /* Do the cleanup and take care you dont leak any memory */
     gVBoxAPI.UArray.vboxArrayRelease(&machines);
 
- cleanup:
     return ret;
 }
 
@@ -2755,13 +2754,13 @@ static int vboxDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info)
     int ret = -1;
 
     if (!data->vboxObj)
-        return ret;
+        return -2;
 
     rc = gVBoxAPI.UArray.vboxArrayGet(&machines, data->vboxObj, ARRAY_GET_MACHINES);
     if (NS_FAILED(rc)) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Could not get list of machines, rc=%08x"), (unsigned)rc);
-        goto cleanup;
+        return -1;
     }
 
     info->nrVirtCpu = 0;
@@ -2823,7 +2822,6 @@ static int vboxDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info)
 
     gVBoxAPI.UArray.vboxArrayRelease(&machines);
 
- cleanup:
     return ret;
 }
 
diff --git a/src/vbox/vbox_snapshot_conf.c b/src/vbox/vbox_snapshot_conf.c
index 8cdfb35357..eafdc577e3 100644
--- a/src/vbox/vbox_snapshot_conf.c
+++ b/src/vbox/vbox_snapshot_conf.c
@@ -753,18 +753,17 @@ virVBoxSnapshotConfAddSnapshotToXmlMachine(virVBoxSnapshotConfSnapshotPtr snapsh
                                            virVBoxSnapshotConfMachinePtr machine,
                                            const char *snapshotParentName)
 {
-    int ret = -1;
     virVBoxSnapshotConfSnapshotPtr parentSnapshot = NULL;
 
     if (snapshot == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Snapshot is Null"));
-        goto cleanup;
+        return -1;
     }
     if (machine == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Machine is Null"));
-        goto cleanup;
+        return -1;
     }
 
     /*If parent is NULL and the machine has no snapshot yet,
@@ -774,32 +773,29 @@ virVBoxSnapshotConfAddSnapshotToXmlMachine(virVBoxSnapshotConfSnapshotPtr snapsh
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("Unable to add this snapshot, there is already a snapshot "
                              "linked to the machine"));
-            goto cleanup;
+            return -1;
         }
         machine->snapshot = snapshot;
-        ret = 0;
-        goto cleanup;
+        return 0;
     } else {
         if (machine->snapshot == NULL) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("The machine has no snapshot and it should have it"));
-            goto cleanup;
+            return -1;
         }
         parentSnapshot = virVBoxSnapshotConfSnapshotByName(machine->snapshot, snapshotParentName);
         if (parentSnapshot == NULL) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Unable to find the snapshot %s"), snapshotParentName);
-            goto cleanup;
+            return -1;
         }
         if (VIR_EXPAND_N(parentSnapshot->children, parentSnapshot->nchildren, 1) < 0)
-            goto cleanup;
+            return -1;
 
         parentSnapshot->children[parentSnapshot->nchildren - 1] = snapshot;
-        ret = 0;
     }
 
- cleanup:
-    return ret;
+    return 0;
 }
 
 /*
@@ -813,18 +809,17 @@ virVBoxSnapshotConfAddHardDiskToMediaRegistry(virVBoxSnapshotConfHardDiskPtr har
                                               virVBoxSnapshotConfMediaRegistryPtr mediaRegistry,
                                               const char *parentHardDiskId)
 {
-    int ret = -1;
     size_t i = 0;
     virVBoxSnapshotConfHardDiskPtr parentDisk = NULL;
     if (hardDisk == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Hard disk is null"));
-        goto cleanup;
+        return -1;
     }
     if (mediaRegistry == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Media Registry is null"));
-        goto cleanup;
+        return -1;
     }
 
     for (i = 0; i < mediaRegistry->ndisks; i++) {
@@ -835,19 +830,17 @@ virVBoxSnapshotConfAddHardDiskToMediaRegistry(virVBoxSnapshotConfHardDiskPtr har
     if (parentDisk == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Unable to get the parent disk"));
-        goto cleanup;
+        return -1;
     }
     /*Hard disk found*/
     if (VIR_EXPAND_N(parentDisk->children, parentDisk->nchildren, 1) < 0)
-        goto cleanup;
+        return -1;
 
     parentDisk->children[parentDisk->nchildren - 1] = hardDisk;
     if (hardDisk->parent == NULL)
         hardDisk->parent = parentDisk;
-    ret = 0;
 
- cleanup:
-    return ret;
+    return 0;
 }
 
 /*
@@ -860,48 +853,47 @@ int
 virVBoxSnapshotConfRemoveSnapshot(virVBoxSnapshotConfMachinePtr machine,
                                   const char *snapshotName)
 {
-    int ret = -1;
     size_t i = 0;
     virVBoxSnapshotConfSnapshotPtr snapshot = NULL;
     virVBoxSnapshotConfSnapshotPtr parentSnapshot = NULL;
     if (machine == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("machine is null"));
-        goto cleanup;
+        return -1;
     }
     if (snapshotName == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("snapshotName is null"));
-        goto cleanup;
+        return -1;
     }
     if (machine->snapshot == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("the machine has no snapshot"));
-        goto cleanup;
+        return -1;
     }
     snapshot = virVBoxSnapshotConfSnapshotByName(machine->snapshot, snapshotName);
     if (snapshot == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Unable to find the snapshot with name %s"), snapshotName);
-        goto cleanup;
+        return -1;
     }
     if (snapshot->nchildren > 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("This snapshot has children, "
                          "please delete theses snapshots before"));
-        goto cleanup;
+        return -1;
     }
 
     if (snapshot->parent == NULL) {
         if (machine->snapshot != snapshot) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("You are trying to remove a snapshot which does not exists"));
-            goto cleanup;
+            return -1;
         }
         machine->snapshot = NULL;
         virVBoxSnapshotConfSnapshotFree(snapshot);
-        ret = 0;
-        goto cleanup;
+
+        return 0;
     }
     parentSnapshot = snapshot->parent;
 
@@ -909,11 +901,9 @@ virVBoxSnapshotConfRemoveSnapshot(virVBoxSnapshotConfMachinePtr machine,
     while (i < parentSnapshot->nchildren && parentSnapshot->children[i] != snapshot)
         ++i;
     if (VIR_DELETE_ELEMENT(parentSnapshot->children, i, parentSnapshot->nchildren) < 0)
-        goto cleanup;
+        return -1;
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 /*
@@ -926,19 +916,18 @@ int
 virVBoxSnapshotConfRemoveHardDisk(virVBoxSnapshotConfMediaRegistryPtr mediaRegistry,
                                   const char *uuid)
 {
-    int ret = -1;
     size_t i = 0;
     virVBoxSnapshotConfHardDiskPtr hardDisk = NULL;
     virVBoxSnapshotConfHardDiskPtr parentHardDisk = NULL;
     if (mediaRegistry == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Media registry is null"));
-        goto cleanup;
+        return -1;
     }
     if (uuid == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Uuid is null"));
-        goto cleanup;
+        return -1;
     }
 
     for (i = 0; i < mediaRegistry->ndisks; i++) {
@@ -949,7 +938,7 @@ virVBoxSnapshotConfRemoveHardDisk(virVBoxSnapshotConfMediaRegistryPtr mediaRegis
     if (hardDisk == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Unable to find the hard disk with uuid %s"), uuid);
-        goto cleanup;
+        return -1;
     }
     if (hardDisk->parent == NULL) {
         /* it means that the hard disk is in 'root' */
@@ -958,9 +947,9 @@ virVBoxSnapshotConfRemoveHardDisk(virVBoxSnapshotConfMediaRegistryPtr mediaRegis
                 break;
         }
         if (VIR_DELETE_ELEMENT(mediaRegistry->disks, i, mediaRegistry->ndisks) < 0)
-            goto cleanup;
-        ret = 0;
-        goto cleanup;
+            return -1;
+
+        return 0;
     }
 
     parentHardDisk = hardDisk->parent;
@@ -969,11 +958,9 @@ virVBoxSnapshotConfRemoveHardDisk(virVBoxSnapshotConfMediaRegistryPtr mediaRegis
         ++i;
     hardDisk->parent = NULL;
     if (VIR_DELETE_ELEMENT(parentHardDisk->children, i, parentHardDisk->nchildren) < 0)
-        goto cleanup;
-    ret = 0;
+        return -1;
 
- cleanup:
-    return ret;
+    return 0;
 }
 
 /*vboxSnapshotSaveVboxFile: Create a VirtualBox XML file from a vboxSnapshotXmlMachinePtr.
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[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