From nobody Fri May 16 10:03:55 2025 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.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496495545305214.90534258420655; Sat, 3 Jun 2017 06:12:25 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 00C90334590; Sat, 3 Jun 2017 13:12:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C6E9F71C48; Sat, 3 Jun 2017 13:12:22 +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 7FA644A48E; Sat, 3 Jun 2017 13:12:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v53DC6ri005741 for ; Sat, 3 Jun 2017 09:12:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id C5E767B8FD; Sat, 3 Jun 2017 13:12:06 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-124.phx2.redhat.com [10.3.116.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 870DF179C2 for ; Sat, 3 Jun 2017 13:12:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 00C90334590 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 00C90334590 From: John Ferlan To: libvir-list@redhat.com Date: Sat, 3 Jun 2017 09:11:52 -0400 Message-Id: <20170603131202.17611-3-jferlan@redhat.com> In-Reply-To: <20170603131202.17611-1-jferlan@redhat.com> References: <20170603131202.17611-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 02/12] test: Adjust cleanup/error paths for nodedev test APIs 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 03 Jun 2017 13:12:23 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" - Rather than "goto cleanup;" on failure to virNodeDeviceObjFindByName an @obj, just return directly. This then allows the cleanup: label code to not have to check "if (obj)" before calling virNodeDeviceObjUnlock. This also simplifies some exit logic... - In testNodeDeviceObjFindByName use an error: label to handle the failure and don't do the ncaps++ within the VIR_STRDUP() source target index. Only increment ncaps after success. Easier on eyes at error label too. - In testNodeDeviceDestroy use "cleanup" rather than "out" for the goto Signed-off-by: John Ferlan --- src/test/test_driver.c | 75 +++++++++++++++++++---------------------------= ---- 1 file changed, 29 insertions(+), 46 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index e323619..e91dfa3 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4509,7 +4509,6 @@ testDestroyVport(testDriverPtr privconn, const char *wwnn ATTRIBUTE_UNUSED, const char *wwpn ATTRIBUTE_UNUSED) { - int ret =3D -1; virNodeDeviceObjPtr obj =3D NULL; virObjectEventPtr event =3D NULL; =20 @@ -4523,7 +4522,7 @@ testDestroyVport(testDriverPtr privconn, if (!(obj =3D virNodeDeviceObjFindByName(&privconn->devs, "scsi_host12= "))) { virReportError(VIR_ERR_NO_NODE_DEVICE, "%s", _("no node device with matching name 'scsi_host12'"= )); - goto cleanup; + return -1; } =20 event =3D virNodeDeviceEventLifecycleNew("scsi_host12", @@ -4534,13 +4533,8 @@ testDestroyVport(testDriverPtr privconn, virNodeDeviceObjFree(obj); obj =3D NULL; =20 - ret =3D 0; - - cleanup: - if (obj) - virNodeDeviceObjUnlock(obj); testObjectEventQueue(privconn, event); - return ret; + return 0; } =20 =20 @@ -5328,7 +5322,7 @@ testNodeDeviceLookupByName(virConnectPtr conn, const = char *name) virNodeDevicePtr ret =3D NULL; =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, name))) - goto cleanup; + return NULL; def =3D virNodeDeviceObjGetDef(obj); =20 if ((ret =3D virGetNodeDevice(conn, name))) { @@ -5338,9 +5332,7 @@ testNodeDeviceLookupByName(virConnectPtr conn, const = char *name) } } =20 - cleanup: - if (obj) - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjUnlock(obj); return ret; } =20 @@ -5355,13 +5347,11 @@ testNodeDeviceGetXMLDesc(virNodeDevicePtr dev, virCheckFlags(0, NULL); =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) - goto cleanup; + return NULL; =20 ret =3D virNodeDeviceDefFormat(virNodeDeviceObjGetDef(obj)); =20 - cleanup: - if (obj) - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjUnlock(obj); return ret; } =20 @@ -5374,7 +5364,7 @@ testNodeDeviceGetParent(virNodeDevicePtr dev) char *ret =3D NULL; =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) - goto cleanup; + return NULL; def =3D virNodeDeviceObjGetDef(obj); =20 if (def->parent) { @@ -5384,9 +5374,7 @@ testNodeDeviceGetParent(virNodeDevicePtr dev) "%s", _("no parent for this device")); } =20 - cleanup: - if (obj) - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjUnlock(obj); return ret; } =20 @@ -5399,20 +5387,16 @@ testNodeDeviceNumOfCaps(virNodeDevicePtr dev) virNodeDeviceDefPtr def; virNodeDevCapsDefPtr caps; int ncaps =3D 0; - int ret =3D -1; =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) - goto cleanup; + return -1; def =3D virNodeDeviceObjGetDef(obj); =20 for (caps =3D def->caps; caps; caps =3D caps->next) ++ncaps; - ret =3D ncaps; =20 - cleanup: - if (obj) - virNodeDeviceObjUnlock(obj); - return ret; + virNodeDeviceObjUnlock(obj); + return ncaps; } =20 =20 @@ -5424,27 +5408,26 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char *= *const names, int maxnames) virNodeDeviceDefPtr def; virNodeDevCapsDefPtr caps; int ncaps =3D 0; - int ret =3D -1; =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) - goto cleanup; + return -1; def =3D virNodeDeviceObjGetDef(obj); =20 for (caps =3D def->caps; caps && ncaps < maxnames; caps =3D caps->next= ) { - if (VIR_STRDUP(names[ncaps++], virNodeDevCapTypeToString(caps->dat= a.type)) < 0) - goto cleanup; + if (VIR_STRDUP(names[ncaps], + virNodeDevCapTypeToString(caps->data.type)) < 0) + goto error; + ncaps++; } - ret =3D ncaps; =20 - cleanup: - if (obj) - virNodeDeviceObjUnlock(obj); - if (ret =3D=3D -1) { - --ncaps; - while (--ncaps >=3D 0) - VIR_FREE(names[ncaps]); - } - return ret; + virNodeDeviceObjUnlock(obj); + return ncaps; + + error: + while (--ncaps >=3D 0) + VIR_FREE(names[ncaps]); + virNodeDeviceObjUnlock(obj); + return -1; } =20 =20 @@ -5598,14 +5581,14 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) virObjectEventPtr event =3D NULL; =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) - goto out; + return -1; def =3D virNodeDeviceObjGetDef(obj); =20 if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) =3D=3D -1) - goto out; + goto cleanup; =20 if (VIR_STRDUP(parent_name, def->parent) < 0) - goto out; + goto cleanup; =20 /* virNodeDeviceGetParentHost will cause the device object's lock to be * taken, so we have to dup the parent's name and drop the lock @@ -5618,7 +5601,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) if (virNodeDeviceObjGetParentHost(&driver->devs, def, EXISTING_DEVICE) < 0) { obj =3D NULL; - goto out; + goto cleanup; } =20 event =3D virNodeDeviceEventLifecycleNew(dev->name, @@ -5630,7 +5613,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) virNodeDeviceObjFree(obj); obj =3D NULL; =20 - out: + cleanup: if (obj) virNodeDeviceObjUnlock(obj); testObjectEventQueue(driver, event); --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list