[libvirt] [PATCH v1 20/21] tests: remove unneeded cleanup labels

Daniel Henrique Barboza danielhb413 at gmail.com
Mon Oct 21 18:19:10 UTC 2019


Signed-off-by: Daniel Henrique Barboza <danielhb413 at gmail.com>
---
 tests/commandtest.c                | 17 ++++----
 tests/domainconftest.c             |  5 +--
 tests/networkxml2firewalltest.c    | 13 ++----
 tests/nsstest.c                    | 27 ++++++-------
 tests/nwfilterebiptablestest.c     |  4 +-
 tests/nwfilterxml2firewalltest.c   | 16 +++-----
 tests/qemuhotplugtest.c            | 19 ++++-----
 tests/qemuxml2argvtest.c           | 11 ++---
 tests/storagebackendsheepdogtest.c |  5 +--
 tests/virauthconfigtest.c          | 11 ++---
 tests/vircgroupmock.c              | 11 ++---
 tests/virendiantest.c              | 58 ++++++++++++--------------
 tests/virkeycodetest.c             | 14 ++-----
 tests/virmacmaptest.c              |  5 +--
 tests/virnetdevtest.c              | 11 ++---
 tests/virpcimock.c                 | 31 +++++---------
 tests/virpcitest.c                 |  3 +-
 tests/virpolkittest.c              | 65 +++++++++---------------------
 tests/virstringtest.c              | 18 +++------
 19 files changed, 126 insertions(+), 218 deletions(-)

diff --git a/tests/commandtest.c b/tests/commandtest.c
index 6ff2039ab1..4fbbde9559 100644
--- a/tests/commandtest.c
+++ b/tests/commandtest.c
@@ -949,12 +949,11 @@ test23(const void *unused G_GNUC_UNUSED)
     /* Not strictly a virCommand test, but this is the easiest place
      * to test this lower-level interface.  It takes a double fork to
      * test virProcessExitWithStatus.  */
-    int ret = -1;
     int status = -1;
     pid_t pid;
 
     if ((pid = virFork()) < 0)
-        goto cleanup;
+        return -1;
     if (pid == 0) {
         if ((pid = virFork()) < 0)
             _exit(EXIT_FAILURE);
@@ -967,14 +966,14 @@ test23(const void *unused G_GNUC_UNUSED)
     }
 
     if (virProcessWait(pid, &status, true) < 0)
-        goto cleanup;
+        return -1;
     if (!WIFEXITED(status) || WEXITSTATUS(status) != 42) {
         printf("Unexpected status %d\n", status);
-        goto cleanup;
+        return -1;
     }
 
     if ((pid = virFork()) < 0)
-        goto cleanup;
+        return -1;
     if (pid == 0) {
         if ((pid = virFork()) < 0)
             _exit(EXIT_FAILURE);
@@ -989,15 +988,13 @@ test23(const void *unused G_GNUC_UNUSED)
     }
 
     if (virProcessWait(pid, &status, true) < 0)
-        goto cleanup;
+        return -1;
     if (!WIFSIGNALED(status) || WTERMSIG(status) != SIGKILL) {
         printf("Unexpected status %d\n", status);
-        goto cleanup;
+        return -1;
     }
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 static int test25(const void *unused G_GNUC_UNUSED)
diff --git a/tests/domainconftest.c b/tests/domainconftest.c
index e7bdc99438..5b7bf4bbec 100644
--- a/tests/domainconftest.c
+++ b/tests/domainconftest.c
@@ -83,10 +83,10 @@ mymain(void)
     int ret = 0;
 
     if ((caps = virTestGenericCapsInit()) == NULL)
-        goto cleanup;
+        return EXIT_SUCCESS;
 
     if (!(xmlopt = virTestGenericDomainXMLConfInit()))
-        goto cleanup;
+        return EXIT_SUCCESS;
 
 #define DO_TEST_GET_FS(fspath, expect) \
     do { \
@@ -107,7 +107,6 @@ mymain(void)
     virObjectUnref(caps);
     virObjectUnref(xmlopt);
 
- cleanup:
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
diff --git a/tests/networkxml2firewalltest.c b/tests/networkxml2firewalltest.c
index b8e974971a..6ee311f384 100644
--- a/tests/networkxml2firewalltest.c
+++ b/tests/networkxml2firewalltest.c
@@ -165,20 +165,16 @@ mymain(void)
             return EXIT_AM_SKIP;
         }
 
-        ret = -1;
-        goto cleanup;
+        return EXIT_FAILURE;
     }
 
     if (virAsprintf(&basefile, "%s/networkxml2firewalldata/base.args",
                     abs_srcdir) < 0) {
-        ret = -1;
-        goto cleanup;
+        return EXIT_FAILURE;
     }
 
-    if (virTestLoadFile(basefile, &baseargs) < 0) {
-        ret = -1;
-        goto cleanup;
-    }
+    if (virTestLoadFile(basefile, &baseargs) < 0)
+        return EXIT_FAILURE;
 
     DO_TEST("nat-default");
     DO_TEST("nat-tftp");
@@ -187,7 +183,6 @@ mymain(void)
     DO_TEST("nat-ipv6");
     DO_TEST("route-default");
 
- cleanup:
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
diff --git a/tests/nsstest.c b/tests/nsstest.c
index 734e4cbc07..d146100747 100644
--- a/tests/nsstest.c
+++ b/tests/nsstest.c
@@ -41,7 +41,6 @@ testGetHostByName(const void *opaque)
 {
     const struct testNSSData *data = opaque;
     const bool existent = data->hostname && data->ipAddr && data->ipAddr[0];
-    int ret = -1;
     struct hostent resolved;
     char buf[BUF_SIZE] = { 0 };
     char **addrList;
@@ -64,16 +63,16 @@ testGetHostByName(const void *opaque)
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "Resolving of %s failed due to internal error",
                        data->hostname);
-        goto cleanup;
+        return -1;
     } else if (rv == NSS_STATUS_NOTFOUND) {
         /* Resolving failed. Should it? */
         if (!existent)
-            ret = 0;
+            return 0;
         else
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            "Resolving of %s failed",
                            data->hostname);
-        goto cleanup;
+        return -1;
     }
 
     /* Resolving succeeded. Should it? */
@@ -81,7 +80,7 @@ testGetHostByName(const void *opaque)
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "Resolving of %s succeeded but was expected to fail",
                        data->hostname);
-        goto cleanup;
+        return -1;
     }
 
     /* Now lets see if resolved address match our expectations. */
@@ -89,7 +88,7 @@ testGetHostByName(const void *opaque)
     if (!resolved.h_name) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        "resolved.h_name empty");
-        goto cleanup;
+        return -1;
     }
 
     if (data->af != AF_UNSPEC &&
@@ -97,7 +96,7 @@ testGetHostByName(const void *opaque)
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "Expected AF_INET (%d) got %d",
                        data->af, resolved.h_addrtype);
-        goto cleanup;
+        return -1;
     }
 
     if ((resolved.h_addrtype == AF_INET && resolved.h_length != 4) ||
@@ -107,13 +106,13 @@ testGetHostByName(const void *opaque)
                        "Expected %d bytes long address, got %d",
                        resolved.h_addrtype == AF_INET ? 4 : 16,
                        resolved.h_length);
-        goto cleanup;
+        return -1;
     }
 
     if (!resolved.h_addr_list) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        "resolved.h_addr_list empty");
-        goto cleanup;
+        return -1;
     }
 
     addrList = resolved.h_addr_list;
@@ -133,7 +132,7 @@ testGetHostByName(const void *opaque)
 
         if (!(ipAddr = virSocketAddrFormat(&sa))) {
             /* error reported by helper */
-            goto cleanup;
+            return -1;
         }
 
         if (STRNEQ_NULLABLE(data->ipAddr[i], ipAddr)) {
@@ -141,7 +140,7 @@ testGetHostByName(const void *opaque)
                            "Unexpected address %s, expecting %s",
                            ipAddr, NULLSTR(data->ipAddr[i]));
             VIR_FREE(ipAddr);
-            goto cleanup;
+            return -1;
         }
         VIR_FREE(ipAddr);
 
@@ -153,12 +152,10 @@ testGetHostByName(const void *opaque)
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "Expected %s address, got NULL",
                        data->ipAddr[i]);
-        goto cleanup;
+        return -1;
     }
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 static int
diff --git a/tests/nwfilterebiptablestest.c b/tests/nwfilterebiptablestest.c
index 61b3284397..97f2ff8ac8 100644
--- a/tests/nwfilterebiptablestest.c
+++ b/tests/nwfilterebiptablestest.c
@@ -539,8 +539,7 @@ mymain(void)
             return EXIT_AM_SKIP;
         }
 
-        ret = -1;
-        goto cleanup;
+        return EXIT_FAILURE;
     }
 
     if (virTestRun("ebiptablesAllTeardown",
@@ -578,7 +577,6 @@ mymain(void)
                    NULL) < 0)
         ret = -1;
 
- cleanup:
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
diff --git a/tests/nwfilterxml2firewalltest.c b/tests/nwfilterxml2firewalltest.c
index bef3790da2..84a4656c5b 100644
--- a/tests/nwfilterxml2firewalltest.c
+++ b/tests/nwfilterxml2firewalltest.c
@@ -328,24 +328,22 @@ static int testSetOneParameter(virHashTablePtr vars,
                                const char *name,
                                const char *value)
 {
-    int ret = -1;
     virNWFilterVarValuePtr val;
 
     if ((val = virHashLookup(vars, name)) == NULL) {
         val = virNWFilterVarValueCreateSimpleCopyValue(value);
         if (!val)
-            goto cleanup;
+            return -1;
         if (virHashUpdateEntry(vars, name, val) < 0) {
             virNWFilterVarValueFree(val);
-            goto cleanup;
+            return -1;
         }
     } else {
         if (virNWFilterVarValueAddValueCopy(val, value) < 0)
-            goto cleanup;
+            return -1;
     }
-    ret = 0;
- cleanup:
-    return ret;
+
+    return 0;
 }
 
 static int testSetDefaultParameters(virHashTablePtr vars)
@@ -474,8 +472,7 @@ mymain(void)
             fprintf(stderr, "iptables/ip6tables/ebtables tools not present");
             return EXIT_AM_SKIP;
         }
-        ret = -1;
-        goto cleanup;
+        return EXIT_FAILURE;
     }
 
     DO_TEST("ah");
@@ -518,7 +515,6 @@ mymain(void)
     DO_TEST("udplite-ipv6");
     DO_TEST("vlan");
 
- cleanup:
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c
index 4ff2b38c83..90cbf56408 100644
--- a/tests/qemuhotplugtest.c
+++ b/tests/qemuhotplugtest.c
@@ -62,17 +62,16 @@ qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt,
                          virDomainObjPtr *vm,
                          const char *domxml)
 {
-    int ret = -1;
     qemuDomainObjPrivatePtr priv = NULL;
     const unsigned int parseFlags = 0;
 
     if (!(*vm = virDomainObjNew(xmlopt)))
-        goto cleanup;
+        return -1;
 
     priv = (*vm)->privateData;
 
     if (!(priv->qemuCaps = virQEMUCapsNew()))
-        goto cleanup;
+        return -1;
 
     virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_VIRTIO_SCSI);
     virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_USB_STORAGE);
@@ -84,31 +83,29 @@ qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt,
     virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE);
 
     if (qemuTestCapsCacheInsert(driver.qemuCapsCache, priv->qemuCaps) < 0)
-        goto cleanup;
+        return -1;
 
     if (!((*vm)->def = virDomainDefParseString(domxml,
                                                driver.caps,
                                                driver.xmlopt,
                                                NULL,
                                                parseFlags)))
-        goto cleanup;
+        return -1;
 
     if (qemuDomainAssignAddresses((*vm)->def, priv->qemuCaps,
                                   &driver, *vm, true) < 0) {
-        goto cleanup;
+        return -1;
     }
 
     if (qemuAssignDeviceAliases((*vm)->def, priv->qemuCaps) < 0)
-        goto cleanup;
+        return -1;
 
     (*vm)->def->id = QEMU_HOTPLUG_TEST_DOMAIN_ID;
 
     if (qemuDomainSetPrivatePaths(&driver, *vm) < 0)
-        goto cleanup;
+        return -1;
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 static int
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index fd330df3e0..b795075d49 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -365,10 +365,8 @@ testUpdateQEMUCaps(const struct testQemuInfo *info,
                    virDomainObjPtr vm,
                    virCapsPtr caps)
 {
-    int ret = -1;
-
     if (!caps)
-        goto cleanup;
+        return -1;
 
     virQEMUCapsSetArch(info->qemuCaps, vm->def->os.arch);
 
@@ -376,17 +374,14 @@ testUpdateQEMUCaps(const struct testQemuInfo *info,
 
     if (testAddCPUModels(info->qemuCaps,
                          !!(info->flags & FLAG_SKIP_LEGACY_CPUS)) < 0)
-        goto cleanup;
+        return -1;
 
     virQEMUCapsInitHostCPUModel(info->qemuCaps, caps->host.arch,
                                 VIR_DOMAIN_VIRT_KVM);
     virQEMUCapsInitHostCPUModel(info->qemuCaps, caps->host.arch,
                                 VIR_DOMAIN_VIRT_QEMU);
 
-    ret = 0;
-
- cleanup:
-    return ret;
+    return 0;
 }
 
 
diff --git a/tests/storagebackendsheepdogtest.c b/tests/storagebackendsheepdogtest.c
index a5403e7136..62f3208a91 100644
--- a/tests/storagebackendsheepdogtest.c
+++ b/tests/storagebackendsheepdogtest.c
@@ -160,11 +160,11 @@ mymain(void)
 
     if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/pool-sheepdog.xml",
                     abs_srcdir) < 0)
-        goto cleanup;
+        return EXIT_SUCCESS;
 
     if (virAsprintf(&volxml, "%s/storagevolxml2xmlin/vol-sheepdog.xml",
                     abs_srcdir) < 0)
-        goto cleanup;
+        return EXIT_SUCCESS;
 
 #define DO_TEST_NODE(collie) \
     do { \
@@ -202,7 +202,6 @@ mymain(void)
         ++test;
     }
 
- cleanup:
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
diff --git a/tests/virauthconfigtest.c b/tests/virauthconfigtest.c
index 42e62cd874..e3bd927dcb 100644
--- a/tests/virauthconfigtest.c
+++ b/tests/virauthconfigtest.c
@@ -41,7 +41,6 @@ struct ConfigLookupData {
 
 static int testAuthLookup(const void *args)
 {
-    int ret = -1;
     const struct ConfigLookupData *data = args;
     const char *actual = NULL;
     int rv;
@@ -53,7 +52,7 @@ static int testAuthLookup(const void *args)
                              &actual);
 
     if (rv < 0)
-        goto cleanup;
+        return -1;
 
     if (data->expect) {
         if (!actual ||
@@ -62,7 +61,7 @@ static int testAuthLookup(const void *args)
                      data->expect, data->hostname,
                      data->service, data->credname,
                      NULLSTR(actual));
-            goto cleanup;
+            return -1;
         }
     } else {
         if (actual) {
@@ -70,13 +69,11 @@ static int testAuthLookup(const void *args)
                      data->hostname,
                      data->service, data->credname,
                      actual);
-            goto cleanup;
+            return -1;
         }
     }
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 
diff --git a/tests/vircgroupmock.c b/tests/vircgroupmock.c
index 7bbaa6dd0f..1b7394232e 100644
--- a/tests/vircgroupmock.c
+++ b/tests/vircgroupmock.c
@@ -103,7 +103,6 @@ static int make_file(const char *path,
 
 static int make_controller_v1(const char *path, mode_t mode)
 {
-    int ret = -1;
     const char *controller;
 
     if (!STRPREFIX(path, fakesysfscgroupdir)) {
@@ -118,12 +117,12 @@ static int make_controller_v1(const char *path, mode_t mode)
         return symlink("cpu,cpuacct", path);
 
     if (real_mkdir(path, mode) < 0)
-        goto cleanup;
+        return -1;
 
 # define MAKE_FILE(name, value) \
     do { \
         if (make_file(path, name, value) < 0) \
-            goto cleanup; \
+            return -1; \
     } while (0)
 
     if (STRPREFIX(controller, "cpu,cpuacct")) {
@@ -224,14 +223,12 @@ static int make_controller_v1(const char *path, mode_t mode)
 
     } else {
         errno = EINVAL;
-        goto cleanup;
+        return -1;
     }
 
 # undef MAKE_FILE
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 
diff --git a/tests/virendiantest.c b/tests/virendiantest.c
index 7e2eff66dc..38adef9353 100644
--- a/tests/virendiantest.c
+++ b/tests/virendiantest.c
@@ -30,38 +30,35 @@ test1(const void *data G_GNUC_UNUSED)
      * unaligned access.  */
     char array[] = { 1, 2, 3, 4, 5, 6, 7, 8,
                      0x89, 0x8a, 0x8b, 0x8c, 0x8d };
-    int ret = -1;
 
     if (virReadBufInt64BE(array) != 0x0102030405060708ULL)
-        goto cleanup;
+        return -1;
     if (virReadBufInt64BE(array + 5) != 0x060708898a8b8c8dULL)
-        goto cleanup;
+        return -1;
     if (virReadBufInt64LE(array) != 0x0807060504030201ULL)
-        goto cleanup;
+        return -1;
     if (virReadBufInt64LE(array + 5) != 0x8d8c8b8a89080706ULL)
-        goto cleanup;
+        return -1;
 
     if (virReadBufInt32BE(array) != 0x01020304U)
-        goto cleanup;
+        return -1;
     if (virReadBufInt32BE(array + 9) != 0x8a8b8c8dU)
-        goto cleanup;
+        return -1;
     if (virReadBufInt32LE(array) != 0x04030201U)
-        goto cleanup;
+        return -1;
     if (virReadBufInt32LE(array + 9) != 0x8d8c8b8aU)
-        goto cleanup;
+        return -1;
 
     if (virReadBufInt16BE(array) != 0x0102U)
-        goto cleanup;
+        return -1;
     if (virReadBufInt16BE(array + 11) != 0x8c8dU)
-        goto cleanup;
+        return -1;
     if (virReadBufInt16LE(array) != 0x0201U)
-        goto cleanup;
+        return -1;
     if (virReadBufInt16LE(array + 11) != 0x8d8cU)
-        goto cleanup;
+        return -1;
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 static int
@@ -70,38 +67,35 @@ test2(const void *data G_GNUC_UNUSED)
     /* Unsigned char should work without cast, even if unaligned access.  */
     unsigned char array[] = { 1, 2, 3, 4, 5, 6, 7, 8,
                               0x89, 0x8a, 0x8b, 0x8c, 0x8d };
-    int ret = -1;
 
     if (virReadBufInt64BE(array) != 0x0102030405060708ULL)
-        goto cleanup;
+        return -1;
     if (virReadBufInt64BE(array + 5) != 0x060708898a8b8c8dULL)
-        goto cleanup;
+        return -1;
     if (virReadBufInt64LE(array) != 0x0807060504030201ULL)
-        goto cleanup;
+        return -1;
     if (virReadBufInt64LE(array + 5) != 0x8d8c8b8a89080706ULL)
-        goto cleanup;
+        return -1;
 
     if (virReadBufInt32BE(array) != 0x01020304U)
-        goto cleanup;
+        return -1;
     if (virReadBufInt32BE(array + 9) != 0x8a8b8c8dU)
-        goto cleanup;
+        return -1;
     if (virReadBufInt32LE(array) != 0x04030201U)
-        goto cleanup;
+        return -1;
     if (virReadBufInt32LE(array + 9) != 0x8d8c8b8aU)
-        goto cleanup;
+        return -1;
 
     if (virReadBufInt16BE(array) != 0x0102U)
-        goto cleanup;
+        return -1;
     if (virReadBufInt16BE(array + 11) != 0x8c8dU)
-        goto cleanup;
+        return -1;
     if (virReadBufInt16LE(array) != 0x0201U)
-        goto cleanup;
+        return -1;
     if (virReadBufInt16LE(array + 11) != 0x8d8cU)
-        goto cleanup;
+        return -1;
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 static int
diff --git a/tests/virkeycodetest.c b/tests/virkeycodetest.c
index c2e756cdd0..298409e919 100644
--- a/tests/virkeycodetest.c
+++ b/tests/virkeycodetest.c
@@ -35,7 +35,6 @@ VIR_LOG_INIT("tests.keycodetest");
 
 static int testKeycodeMapping(const void *data G_GNUC_UNUSED)
 {
-    int ret = -1;
     int got;
 
 #define TRANSLATE(from, to, val, want) \
@@ -45,7 +44,7 @@ static int testKeycodeMapping(const void *data G_GNUC_UNUSED)
                                             val)) != want) { \
             fprintf(stderr, "Translating %d from %s to %s, got %d want %d\n", \
                     val, #from, #to, got, want); \
-            goto cleanup; \
+            return -1; \
         } \
     } while (0)
 
@@ -60,15 +59,12 @@ static int testKeycodeMapping(const void *data G_GNUC_UNUSED)
 
 #undef TRANSLATE
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 
 static int testKeycodeStrings(const void *data G_GNUC_UNUSED)
 {
-    int ret = -1;
     int got;
 
 #define TRANSLATE(from, str, want) \
@@ -77,7 +73,7 @@ static int testKeycodeStrings(const void *data G_GNUC_UNUSED)
                                              str)) != want) { \
             fprintf(stderr, "Converting %s from %s, got %d want %d\n", \
                     str, #from, got, want); \
-            goto cleanup; \
+            return -1; \
         } \
     } while (0)
 
@@ -90,9 +86,7 @@ static int testKeycodeStrings(const void *data G_GNUC_UNUSED)
 
 #undef TRANSLATE
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 static int
diff --git a/tests/virmacmaptest.c b/tests/virmacmaptest.c
index 995aff1178..73b8265a42 100644
--- a/tests/virmacmaptest.c
+++ b/tests/virmacmaptest.c
@@ -170,8 +170,7 @@ mymain(void)
 #define DO_TEST_FLUSH_PROLOGUE \
     do { \
         if (!(mgr = virMacMapNew(NULL))) { \
-            ret = -1; \
-            goto cleanup; \
+            return EXIT_FAILURE; \
         } \
     } while (0)
 
@@ -228,7 +227,7 @@ mymain(void)
     DO_TEST_FLUSH("dom1", "9e:89:49:99:51:0e", "89:b4:3f:08:88:2c", "54:0b:4c:e2:0a:39");
     DO_TEST_FLUSH("dom1", "bb:88:07:19:51:9d", "b7:f1:1a:40:a2:95", "88:94:39:a3:90:b4");
     DO_TEST_FLUSH_EPILOGUE("complex");
- cleanup:
+
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
diff --git a/tests/virnetdevtest.c b/tests/virnetdevtest.c
index 5d266a28ee..aadbeb1ef4 100644
--- a/tests/virnetdevtest.c
+++ b/tests/virnetdevtest.c
@@ -35,31 +35,28 @@ struct testVirNetDevGetLinkInfoData {
 static int
 testVirNetDevGetLinkInfo(const void *opaque)
 {
-    int ret = -1;
     const struct testVirNetDevGetLinkInfoData *data = opaque;
     virNetDevIfLink lnk;
 
     if (virNetDevGetLinkInfo(data->ifname, &lnk) < 0)
-        goto cleanup;
+        return -1;
 
     if (lnk.state != data->state) {
         fprintf(stderr,
                 "Fetched link state (%s) doesn't match the expected one (%s)",
                 virNetDevIfStateTypeToString(lnk.state),
                 virNetDevIfStateTypeToString(data->state));
-        goto cleanup;
+        return -1;
     }
 
     if (lnk.speed != data->speed) {
         fprintf(stderr,
                 "Fetched link speed (%u) doesn't match the expected one (%u)",
                 lnk.speed, data->speed);
-        goto cleanup;
+        return -1;
     }
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 static int
diff --git a/tests/virpcimock.c b/tests/virpcimock.c
index d7dc0b00f0..50bd79737d 100644
--- a/tests/virpcimock.c
+++ b/tests/virpcimock.c
@@ -314,7 +314,6 @@ find_fd(int fd, size_t *indx)
 static int
 add_fd(int fd, const char *path)
 {
-    int ret = -1;
     size_t i;
 
     if (find_fd(fd, &i)) {
@@ -325,38 +324,34 @@ add_fd(int fd, const char *path)
 
     if (VIR_REALLOC_N_QUIET(callbacks, nCallbacks + 1) < 0) {
         errno = ENOMEM;
-        goto cleanup;
+        return -1;
     }
 
     callbacks[nCallbacks].path = g_strdup(path);
     callbacks[nCallbacks++].fd = fd;
-    ret = 0;
- cleanup:
-    return ret;
+
+    return 0;
 }
 
 static int
 remove_fd(int fd)
 {
-    int ret = -1;
     size_t i;
 
     if (find_fd(fd, &i)) {
         struct fdCallback cb = callbacks[i];
 
         if (pci_driver_handle_change(cb.fd, cb.path) < 0)
-            goto cleanup;
+            return -1;
 
         VIR_FREE(cb.path);
         if (VIR_DELETE_ELEMENT(callbacks, i, nCallbacks) < 0) {
             errno = EINVAL;
-            goto cleanup;
+            return -1;
         }
     }
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 
@@ -931,36 +926,30 @@ pci_driver_handle_change(int fd G_GNUC_UNUSED, const char *path)
 static int
 pci_driver_handle_bind(const char *path)
 {
-    int ret = -1;
     struct pciDevice *dev = pci_device_find_by_content(path);
     struct pciDriver *driver = pci_driver_find_by_path(path);
 
     if (!driver || !dev) {
         /* No driver, no device or failing driver requested */
         errno = ENODEV;
-        goto cleanup;
+        return -1;
     }
 
-    ret = pci_driver_bind(driver, dev);
- cleanup:
-    return ret;
+    return pci_driver_bind(driver, dev);
 }
 
 static int
 pci_driver_handle_unbind(const char *path)
 {
-    int ret = -1;
     struct pciDevice *dev = pci_device_find_by_content(path);
 
     if (!dev || !dev->driver) {
         /* No device, device not binded or failing driver requested */
         errno = ENODEV;
-        goto cleanup;
+        return -1;
     }
 
-    ret = pci_driver_unbind(dev->driver, dev);
- cleanup:
-    return ret;
+    return pci_driver_unbind(dev->driver, dev);
 }
 
 
diff --git a/tests/virpcitest.c b/tests/virpcitest.c
index de2ffc7d41..f9c36d5af8 100644
--- a/tests/virpcitest.c
+++ b/tests/virpcitest.c
@@ -224,13 +224,12 @@ testVirPCIDeviceIsAssignable(const void *opaque)
     virPCIDevicePtr dev;
 
     if (!(dev = virPCIDeviceNew(data->domain, data->bus, data->slot, data->function)))
-        goto cleanup;
+        return -1;
 
     if (virPCIDeviceIsAssignable(dev, true))
         ret = 0;
 
     virPCIDeviceFree(dev);
- cleanup:
     return ret;
 }
 
diff --git a/tests/virpolkittest.c b/tests/virpolkittest.c
index 97fa877445..fe7a3b5b91 100644
--- a/tests/virpolkittest.c
+++ b/tests/virpolkittest.c
@@ -145,26 +145,20 @@ VIR_MOCK_WRAP_RET_ARGS(dbus_connection_send_with_reply_and_block,
 
 static int testPolkitAuthSuccess(const void *opaque G_GNUC_UNUSED)
 {
-    int ret = -1;
-
     if (virPolkitCheckAuth("org.libvirt.test.success",
                            THE_PID,
                            THE_TIME,
                            THE_UID,
                            NULL,
                            true) < 0)
-        goto cleanup;
-
-    ret = 0;
+        return -1;
 
- cleanup:
-    return ret;
+    return 0;
 }
 
 
 static int testPolkitAuthDenied(const void *opaque G_GNUC_UNUSED)
 {
-    int ret = -1;
     int rv;
     virErrorPtr err;
 
@@ -177,28 +171,24 @@ static int testPolkitAuthDenied(const void *opaque G_GNUC_UNUSED)
 
     if (rv == 0) {
         fprintf(stderr, "Unexpected auth success\n");
-        goto cleanup;
+        return -1;
     } else if (rv != -2) {
-        goto cleanup;
+        return -1;
     }
 
     err = virGetLastError();
     if (!err || !strstr(err->message,
                         _("access denied by policy"))) {
         fprintf(stderr, "Incorrect error response\n");
-        goto cleanup;
+        return -1;
     }
 
-    ret = 0;
-
- cleanup:
-    return ret;
+    return 0;
 }
 
 
 static int testPolkitAuthChallenge(const void *opaque G_GNUC_UNUSED)
 {
-    int ret = -1;
     int rv;
     virErrorPtr err;
 
@@ -211,9 +201,9 @@ static int testPolkitAuthChallenge(const void *opaque G_GNUC_UNUSED)
 
     if (rv == 0) {
         fprintf(stderr, "Unexpected auth success\n");
-        goto cleanup;
+        return -1;
     } else if (rv != -2) {
-        goto cleanup;
+        return -1;
     }
 
     err = virGetLastError();
@@ -221,19 +211,15 @@ static int testPolkitAuthChallenge(const void *opaque G_GNUC_UNUSED)
         err->code != VIR_ERR_AUTH_UNAVAILABLE ||
         !strstr(err->message, _("no polkit agent available to authenticate"))) {
         fprintf(stderr, "Incorrect error response\n");
-        goto cleanup;
+        return -1;
     }
 
-    ret = 0;
-
- cleanup:
-    return ret;
+    return 0;
 }
 
 
 static int testPolkitAuthCancelled(const void *opaque G_GNUC_UNUSED)
 {
-    int ret = -1;
     int rv;
     virErrorPtr err;
 
@@ -246,28 +232,24 @@ static int testPolkitAuthCancelled(const void *opaque G_GNUC_UNUSED)
 
     if (rv == 0) {
         fprintf(stderr, "Unexpected auth success\n");
-        goto cleanup;
+        return -1;
     } else if (rv != -2) {
-        goto cleanup;
+        return -1;
     }
 
     err = virGetLastError();
     if (!err || !strstr(err->message,
                        _("user cancelled authentication process"))) {
         fprintf(stderr, "Incorrect error response\n");
-        goto cleanup;
+        return -1;
     }
 
-    ret = 0;
-
- cleanup:
-    return ret;
+    return 0;
 }
 
 
 static int testPolkitAuthDetailsSuccess(const void *opaque G_GNUC_UNUSED)
 {
-    int ret = -1;
     const char *details[] = {
         "org.libvirt.test.person", "Fred",
         NULL,
@@ -279,18 +261,14 @@ static int testPolkitAuthDetailsSuccess(const void *opaque G_GNUC_UNUSED)
                            THE_UID,
                            details,
                            true) < 0)
-        goto cleanup;
-
-    ret = 0;
+        return -1;
 
- cleanup:
-    return ret;
+    return 0;
 }
 
 
 static int testPolkitAuthDetailsDenied(const void *opaque G_GNUC_UNUSED)
 {
-    int ret = -1;
     int rv;
     virErrorPtr err;
     const char *details[] = {
@@ -307,22 +285,19 @@ static int testPolkitAuthDetailsDenied(const void *opaque G_GNUC_UNUSED)
 
     if (rv == 0) {
         fprintf(stderr, "Unexpected auth success\n");
-        goto cleanup;
+        return -1;
     } else if (rv != -2) {
-        goto cleanup;
+        return -1;
     }
 
     err = virGetLastError();
     if (!err || !strstr(err->message,
                         _("access denied by policy"))) {
         fprintf(stderr, "Incorrect error response\n");
-        goto cleanup;
+        return -1;
     }
 
-    ret = 0;
-
- cleanup:
-    return ret;
+    return 0;
 }
 
 
diff --git a/tests/virstringtest.c b/tests/virstringtest.c
index 1e408f2757..fc5f9bf937 100644
--- a/tests/virstringtest.c
+++ b/tests/virstringtest.c
@@ -39,7 +39,6 @@ struct testStreqData {
 static int testStreq(const void *args)
 {
     const struct testStreqData *data = args;
-    int ret = -1;
     bool equal = true;
     bool streq_rv, strneq_rv;
     size_t i;
@@ -63,19 +62,17 @@ static int testStreq(const void *args)
         virFilePrintf(stderr,
                       "STREQ not working correctly. Expected %d got %d",
                       (int) equal, (int) streq_rv);
-        goto cleanup;
+        return -1;
     }
 
     if (strneq_rv == equal) {
         virFilePrintf(stderr,
                       "STRNEQ not working correctly. Expected %d got %d",
                       (int) equal, (int) strneq_rv);
-        goto cleanup;
+        return -1;
     }
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 struct testSplitData {
@@ -381,7 +378,6 @@ testStringSortCompare(const void *opaque G_GNUC_UNUSED)
     const char *sortrlist[] = {
         "turducken", "tasty", "goat", "chicken", "astro",
     };
-    int ret = -1;
     size_t i;
 
     qsort(randlist, G_N_ELEMENTS(randlist), sizeof(randlist[0]),
@@ -393,18 +389,16 @@ testStringSortCompare(const void *opaque G_GNUC_UNUSED)
         if (STRNEQ(randlist[i], sortlist[i])) {
             fprintf(stderr, "sortlist[%zu] '%s' != randlist[%zu] '%s'\n",
                     i, sortlist[i], i, randlist[i]);
-            goto cleanup;
+            return -1;
         }
         if (STRNEQ(randrlist[i], sortrlist[i])) {
             fprintf(stderr, "sortrlist[%zu] '%s' != randrlist[%zu] '%s'\n",
                     i, sortrlist[i], i, randrlist[i]);
-            goto cleanup;
+            return -1;
         }
     }
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 
-- 
2.21.0




More information about the libvir-list mailing list