From nobody Mon Feb 9 03:52:11 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1554104023966834.583858182705; Mon, 1 Apr 2019 00:33:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 619C48667A; Mon, 1 Apr 2019 07:33:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 38A73272A4; Mon, 1 Apr 2019 07:33:42 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E8229181A00D; Mon, 1 Apr 2019 07:33:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x317XcvE013928 for ; Mon, 1 Apr 2019 03:33:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7DE0A60FAB; Mon, 1 Apr 2019 07:33:38 +0000 (UTC) Received: from lpt.redhat.com (ovpn-204-90.brq.redhat.com [10.40.204.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0C6E60BFC for ; Mon, 1 Apr 2019 07:33:37 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Mon, 1 Apr 2019 09:33:29 +0200 Message-Id: <723653ec7296528dc923196df9ad6b2178dc8831.1554103986.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 12/14] virsh-completer: remove excessive labels X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 01 Apr 2019 07:33:43 +0000 (UTC) Now that we have a shared cleanup section everywhere, delete all the 'error' labels which all contain just 'goto cleanup' anyway. Also remove all the 'cleanup' labels that only 'return ret' - we can simply return NULL instead of jumping to that label. Signed-off-by: J=C3=A1n Tomko --- tools/virsh-completer.c | 207 +++++++++++++--------------------------- 1 file changed, 68 insertions(+), 139 deletions(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 025eee19e2..2b9749300a 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -97,13 +97,13 @@ virshDomainNameCompleter(vshControl *ctl, return NULL; =20 if (VIR_ALLOC_N(tmp, ndomains + 1) < 0) - goto error; + goto cleanup; =20 for (i =3D 0; i < ndomains; i++) { const char *name =3D virDomainGetName(domains[i]); =20 if (VIR_STRDUP(tmp[i], name) < 0) - goto error; + goto cleanup; } =20 VIR_STEAL_PTR(ret, tmp); @@ -113,9 +113,6 @@ virshDomainNameCompleter(vshControl *ctl, virshDomainFree(domains[i]); VIR_FREE(domains); return ret; - - error: - goto cleanup; } =20 =20 @@ -143,14 +140,14 @@ virshDomainInterfaceCompleter(vshControl *ctl, domainXMLFlags =3D VIR_DOMAIN_XML_INACTIVE; =20 if (virshDomainGetXML(ctl, cmd, domainXMLFlags, &xmldoc, &ctxt) < 0) - goto cleanup; + return NULL; =20 ninterfaces =3D virXPathNodeSet("./devices/interface", ctxt, &interfac= es); if (ninterfaces < 0) - goto cleanup; + return NULL; =20 if (VIR_ALLOC_N(tmp, ninterfaces + 1) < 0) - goto cleanup; + return NULL; =20 for (i =3D 0; i < ninterfaces; i++) { ctxt->node =3D interfaces[i]; @@ -162,11 +159,10 @@ virshDomainInterfaceCompleter(vshControl *ctl, /* In case we are dealing with inactive domain XML there's no * . Offer MAC addresses then. */ if (!(tmp[i] =3D virXPathString("string(./mac/@address)", ctxt))) - goto cleanup; + return NULL; } =20 VIR_STEAL_PTR(ret, tmp); - cleanup: return ret; } =20 @@ -191,23 +187,22 @@ virshDomainDiskTargetCompleter(vshControl *ctl, return NULL; =20 if (virshDomainGetXML(ctl, cmd, 0, &xmldoc, &ctxt) < 0) - goto cleanup; + return NULL; =20 ndisks =3D virXPathNodeSet("./devices/disk", ctxt, &disks); if (ndisks < 0) - goto cleanup; + return NULL; =20 if (VIR_ALLOC_N(tmp, ndisks + 1) < 0) - goto cleanup; + return NULL; =20 for (i =3D 0; i < ndisks; i++) { ctxt->node =3D disks[i]; if (!(tmp[i] =3D virXPathString("string(./target/@dev)", ctxt))) - goto cleanup; + return NULL; } =20 VIR_STEAL_PTR(ret, tmp); - cleanup: return ret; } =20 @@ -236,13 +231,13 @@ virshStoragePoolNameCompleter(vshControl *ctl, return NULL; =20 if (VIR_ALLOC_N(tmp, npools + 1) < 0) - goto error; + goto cleanup; =20 for (i =3D 0; i < npools; i++) { const char *name =3D virStoragePoolGetName(pools[i]); =20 if (VIR_STRDUP(tmp[i], name) < 0) - goto error; + goto cleanup; } =20 VIR_STEAL_PTR(ret, tmp); @@ -252,9 +247,6 @@ virshStoragePoolNameCompleter(vshControl *ctl, virStoragePoolFree(pools[i]); VIR_FREE(pools); return ret; - - error: - goto cleanup; } =20 =20 @@ -281,17 +273,17 @@ virshStorageVolNameCompleter(vshControl *ctl, return NULL; =20 if ((rc =3D virStoragePoolListAllVolumes(pool, &vols, flags)) < 0) - goto error; + goto cleanup; nvols =3D rc; =20 if (VIR_ALLOC_N(tmp, nvols + 1) < 0) - goto error; + goto cleanup; =20 for (i =3D 0; i < nvols; i++) { const char *name =3D virStorageVolGetName(vols[i]); =20 if (VIR_STRDUP(tmp[i], name) < 0) - goto error; + goto cleanup; } =20 VIR_STEAL_PTR(ret, tmp); @@ -302,9 +294,6 @@ virshStorageVolNameCompleter(vshControl *ctl, virStorageVolFree(vols[i]); VIR_FREE(vols); return ret; - - error: - goto cleanup; } =20 =20 @@ -331,13 +320,13 @@ virshInterfaceNameCompleter(vshControl *ctl, return NULL; =20 if (VIR_ALLOC_N(tmp, nifaces + 1) < 0) - goto error; + goto cleanup; =20 for (i =3D 0; i < nifaces; i++) { const char *name =3D virInterfaceGetName(ifaces[i]); =20 if (VIR_STRDUP(tmp[i], name) < 0) - goto error; + goto cleanup; } =20 VIR_STEAL_PTR(ret, tmp); @@ -347,9 +336,6 @@ virshInterfaceNameCompleter(vshControl *ctl, virInterfaceFree(ifaces[i]); VIR_FREE(ifaces); return ret; - - error: - goto cleanup; } =20 =20 @@ -377,13 +363,13 @@ virshNetworkNameCompleter(vshControl *ctl, return NULL; =20 if (VIR_ALLOC_N(tmp, nnets + 1) < 0) - goto error; + goto cleanup; =20 for (i =3D 0; i < nnets; i++) { const char *name =3D virNetworkGetName(nets[i]); =20 if (VIR_STRDUP(tmp[i], name) < 0) - goto error; + goto cleanup; } =20 VIR_STEAL_PTR(ret, tmp); @@ -393,9 +379,6 @@ virshNetworkNameCompleter(vshControl *ctl, virNetworkFree(nets[i]); VIR_FREE(nets); return ret; - - error: - goto cleanup; } =20 =20 @@ -411,20 +394,17 @@ virshNetworkEventNameCompleter(vshControl *ctl ATTRIB= UTE_UNUSED, virCheckFlags(0, NULL); =20 if (VIR_ALLOC_N(tmp, VIR_NETWORK_EVENT_ID_LAST + 1) < 0) - goto error; + goto cleanup; =20 for (i =3D 0; i < VIR_NETWORK_EVENT_ID_LAST; i++) { if (VIR_STRDUP(tmp[i], virshNetworkEventCallbacks[i].name) < 0) - goto error; + goto cleanup; } =20 VIR_STEAL_PTR(ret, tmp); =20 cleanup: return ret; - - error: - goto cleanup; } =20 =20 @@ -449,13 +429,13 @@ virshNodeDeviceNameCompleter(vshControl *ctl, return NULL; =20 if (VIR_ALLOC_N(tmp, ndevs + 1) < 0) - goto error; + goto cleanup; =20 for (i =3D 0; i < ndevs; i++) { const char *name =3D virNodeDeviceGetName(devs[i]); =20 if (VIR_STRDUP(tmp[i], name) < 0) - goto error; + goto cleanup; } =20 VIR_STEAL_PTR(ret, tmp); @@ -465,9 +445,6 @@ virshNodeDeviceNameCompleter(vshControl *ctl, virNodeDeviceFree(devs[i]); VIR_FREE(devs); return ret; - - error: - goto cleanup; } =20 =20 @@ -492,13 +469,13 @@ virshNWFilterNameCompleter(vshControl *ctl, return NULL; =20 if (VIR_ALLOC_N(tmp, nnwfilters + 1) < 0) - goto error; + goto cleanup; =20 for (i =3D 0; i < nnwfilters; i++) { const char *name =3D virNWFilterGetName(nwfilters[i]); =20 if (VIR_STRDUP(tmp[i], name) < 0) - goto error; + goto cleanup; } =20 VIR_STEAL_PTR(ret, tmp); @@ -508,9 +485,6 @@ virshNWFilterNameCompleter(vshControl *ctl, virNWFilterFree(nwfilters[i]); VIR_FREE(nwfilters); return ret; - - error: - goto cleanup; } =20 =20 @@ -535,13 +509,13 @@ virshNWFilterBindingNameCompleter(vshControl *ctl, return NULL; =20 if (VIR_ALLOC_N(tmp, nbindings + 1) < 0) - goto error; + goto cleanup; =20 for (i =3D 0; i < nbindings; i++) { const char *name =3D virNWFilterBindingGetPortDev(bindings[i]); =20 if (VIR_STRDUP(tmp[i], name) < 0) - goto error; + goto cleanup; } =20 VIR_STEAL_PTR(ret, tmp); @@ -551,9 +525,6 @@ virshNWFilterBindingNameCompleter(vshControl *ctl, virNWFilterBindingFree(bindings[i]); VIR_FREE(bindings); return ret; - - error: - goto cleanup; } =20 =20 @@ -578,14 +549,14 @@ virshSecretUUIDCompleter(vshControl *ctl, return NULL; =20 if (VIR_ALLOC_N(tmp, nsecrets + 1) < 0) - goto error; + goto cleanup; =20 for (i =3D 0; i < nsecrets; i++) { char uuid[VIR_UUID_STRING_BUFLEN]; =20 if (virSecretGetUUIDString(secrets[i], uuid) < 0 || VIR_STRDUP(tmp[i], uuid) < 0) - goto error; + goto cleanup; } =20 VIR_STEAL_PTR(ret, tmp); @@ -595,9 +566,6 @@ virshSecretUUIDCompleter(vshControl *ctl, virSecretFree(secrets[i]); VIR_FREE(secrets); return ret; - - error: - goto cleanup; } =20 =20 @@ -624,17 +592,17 @@ virshSnapshotNameCompleter(vshControl *ctl, return NULL; =20 if ((rc =3D virDomainListAllSnapshots(dom, &snapshots, flags)) < 0) - goto error; + goto cleanup; nsnapshots =3D rc; =20 if (VIR_ALLOC_N(tmp, nsnapshots + 1) < 0) - goto error; + goto cleanup; =20 for (i =3D 0; i < nsnapshots; i++) { const char *name =3D virDomainSnapshotGetName(snapshots[i]); =20 if (VIR_STRDUP(tmp[i], name) < 0) - goto error; + goto cleanup; } =20 VIR_STEAL_PTR(ret, tmp); @@ -645,9 +613,6 @@ virshSnapshotNameCompleter(vshControl *ctl, virshDomainSnapshotFree(snapshots[i]); VIR_FREE(snapshots); return ret; - - error: - goto cleanup; } =20 char ** @@ -676,30 +641,30 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl, virCheckFlags(0, NULL); =20 if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) - goto error; + return NULL; =20 if (!(cap_xml =3D virConnectGetCapabilities(priv->conn))) - goto error; + return NULL; =20 if (!(doc =3D virXMLParseStringCtxt(cap_xml, _("capabilities"), &ctxt)= )) - goto error; + return NULL; =20 if (cellno && vshCommandOptStringQuiet(ctl, cmd, "cellno", &cellnum) >= 0) { if (virAsprintf(&path, "/capabilities/host/topology/cells/cell[@id=3D\"%s= \"]/pages", cellnum) < 0) - goto error; + return NULL; } else { if (virAsprintf(&path, "/capabilities/host/cpu/pages") < 0) - goto error; + return NULL; } =20 npages =3D virXPathNodeSet(path, ctxt, &pages); if (npages <=3D 0) - goto error; + return NULL; =20 if (VIR_ALLOC_N(tmp, npages + 1) < 0) - goto error; + return NULL; =20 for (i =3D 0; i < npages; i++) { VIR_FREE(pagesize); @@ -707,21 +672,16 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl, pagesize =3D virXMLPropString(pages[i], "size"); unit =3D virXMLPropString(pages[i], "unit"); if (virStrToLong_ull(pagesize, NULL, 10, &byteval) < 0) - goto error; + return NULL; if (virScaleInteger(&byteval, unit, 1024, UINT_MAX) < 0) - goto error; + return NULL; size =3D vshPrettyCapacity(byteval, &suffix); if (virAsprintf(&tmp[i], "%.0f%s", size, suffix) < 0) - goto error; + return NULL; } =20 VIR_STEAL_PTR(ret, tmp); - - cleanup: return ret; - - error: - goto cleanup; } =20 =20 @@ -737,20 +697,15 @@ virshSecretEventNameCompleter(vshControl *ctl ATTRIBU= TE_UNUSED, virCheckFlags(0, NULL); =20 if (VIR_ALLOC_N(tmp, VIR_SECRET_EVENT_ID_LAST + 1) < 0) - goto error; + return NULL; =20 for (i =3D 0; i < VIR_SECRET_EVENT_ID_LAST; i++) { if (VIR_STRDUP(tmp[i], virshSecretEventCallbacks[i].name) < 0) - goto error; + return NULL; } =20 VIR_STEAL_PTR(ret, tmp); - - cleanup: return ret; - - error: - goto cleanup; } =20 =20 @@ -766,20 +721,15 @@ virshDomainEventNameCompleter(vshControl *ctl ATTRIBU= TE_UNUSED, virCheckFlags(0, NULL); =20 if (VIR_ALLOC_N(tmp, VIR_DOMAIN_EVENT_ID_LAST + 1) < 0) - goto error; + return NULL; =20 for (i =3D 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) { if (VIR_STRDUP(tmp[i], virshDomainEventCallbacks[i].name) < 0) - goto error; + return NULL; } =20 VIR_STEAL_PTR(ret, tmp); - - cleanup: return ret; - - error: - goto cleanup; } =20 =20 @@ -795,20 +745,15 @@ virshPoolEventNameCompleter(vshControl *ctl ATTRIBUTE= _UNUSED, virCheckFlags(0, NULL); =20 if (VIR_ALLOC_N(tmp, VIR_STORAGE_POOL_EVENT_ID_LAST + 1) < 0) - goto error; + return NULL; =20 for (i =3D 0; i < VIR_STORAGE_POOL_EVENT_ID_LAST; i++) { if (VIR_STRDUP(tmp[i], virshPoolEventCallbacks[i].name) < 0) - goto error; + return NULL; } =20 VIR_STEAL_PTR(ret, tmp); - - cleanup: return ret; - - error: - goto cleanup; } =20 =20 @@ -836,10 +781,10 @@ virshDomainInterfaceStateCompleter(vshControl *ctl, return NULL; =20 if (virshDomainGetXML(ctl, cmd, flags, &xml, &ctxt) < 0) - goto cleanup; + return NULL; =20 if (vshCommandOptStringReq(ctl, cmd, "interface", &iface) < 0) - goto cleanup; + return NULL; =20 /* normalize the mac addr */ if (virMacAddrParse(iface, &macaddr) =3D=3D 0) @@ -848,35 +793,30 @@ virshDomainInterfaceStateCompleter(vshControl *ctl, if (virAsprintf(&xpath, "/domain/devices/interface[(mac/@address =3D '= %s') or " " (target/@dev =3D '%= s')]", macstr, iface) < 0) - goto cleanup; + return NULL; =20 if ((ninterfaces =3D virXPathNodeSet(xpath, ctxt, &interfaces)) < 0) - goto cleanup; + return NULL; =20 if (ninterfaces !=3D 1) - goto cleanup; + return NULL; =20 ctxt->node =3D interfaces[0]; =20 if (VIR_ALLOC_N(tmp, 2) < 0) - goto error; + return NULL; =20 if ((state =3D virXPathString("string(./link/@state)", ctxt)) && STREQ(state, "down")) { if (VIR_STRDUP(tmp[0], "up") < 0) - goto error; + return NULL; } else { if (VIR_STRDUP(tmp[0], "down") < 0) - goto error; + return NULL; } =20 VIR_STEAL_PTR(ret, tmp); - - cleanup: return ret; - - error: - goto cleanup; } =20 =20 @@ -892,20 +832,15 @@ virshNodedevEventNameCompleter(vshControl *ctl ATTRIB= UTE_UNUSED, virCheckFlags(0, NULL); =20 if (VIR_ALLOC_N(tmp, VIR_NODE_DEVICE_EVENT_ID_LAST + 1) < 0) - goto error; + return NULL; =20 for (i =3D 0; i < VIR_NODE_DEVICE_EVENT_ID_LAST; i++) { if (VIR_STRDUP(tmp[i], virshNodedevEventCallbacks[i].name) < 0) - goto error; + return NULL; } =20 VIR_STEAL_PTR(ret, tmp); - - cleanup: return ret; - - error: - goto cleanup; } =20 =20 @@ -927,33 +862,28 @@ virshCellnoCompleter(vshControl *ctl, virCheckFlags(0, NULL); =20 if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) - goto error; + return NULL; =20 if (!(cap_xml =3D virConnectGetCapabilities(priv->conn))) - goto error; + return NULL; =20 if (!(doc =3D virXMLParseStringCtxt(cap_xml, _("capabilities"), &ctxt)= )) - goto error; + return NULL; =20 ncells =3D virXPathNodeSet("/capabilities/host/topology/cells/cell", c= txt, &cells); if (ncells <=3D 0) - goto error; + return NULL; =20 if (VIR_ALLOC_N(tmp, ncells + 1)) - goto error; + return NULL; =20 for (i =3D 0; i < ncells; i++) { if (!(tmp[i] =3D virXMLPropString(cells[i], "id"))) - goto error; + return NULL; } =20 VIR_STEAL_PTR(ret, tmp); - - cleanup: return ret; - - error: - goto cleanup; } =20 =20 @@ -981,21 +911,20 @@ virshDomainDeviceAliasCompleter(vshControl *ctl, domainXMLFlags =3D VIR_DOMAIN_XML_INACTIVE; =20 if (virshDomainGetXML(ctl, cmd, domainXMLFlags, &xmldoc, &ctxt) < 0) - goto cleanup; + return NULL; =20 naliases =3D virXPathNodeSet("./devices//alias/@name", ctxt, &aliases); if (naliases < 0) - goto cleanup; + return NULL; =20 if (VIR_ALLOC_N(tmp, naliases + 1) < 0) - goto cleanup; + return NULL; =20 for (i =3D 0; i < naliases; i++) { if (!(tmp[i] =3D virXMLNodeContentString(aliases[i]))) - goto cleanup; + return NULL; } =20 VIR_STEAL_PTR(ret, tmp); - cleanup: return ret; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list