From nobody Sat Feb 7 08:02:20 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.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 1495199349551724.26081914623; Fri, 19 May 2017 06:09:09 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CF78F659AA; Fri, 19 May 2017 13:09:04 +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 ACE7A5C7A2; Fri, 19 May 2017 13:09:04 +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 6545F180BAF7; Fri, 19 May 2017 13:09:04 +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 v4JD8vN6005266 for ; Fri, 19 May 2017 09:08:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5EDD980E7D; Fri, 19 May 2017 13:08:57 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-18.phx2.redhat.com [10.3.116.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1AD7E80E7C for ; Fri, 19 May 2017 13:08:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CF78F659AA Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.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 CF78F659AA From: John Ferlan To: libvir-list@redhat.com Date: Fri, 19 May 2017 09:08:41 -0400 Message-Id: <20170519130853.13965-2-jferlan@redhat.com> In-Reply-To: <20170519130853.13965-1-jferlan@redhat.com> References: <20170519130853.13965-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 01/13] 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 19 May 2017 13:09:05 +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 2db3f7d..3389edd 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4512,7 +4512,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 @@ -4526,7 +4525,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", @@ -4535,13 +4534,8 @@ testDestroyVport(testDriverPtr privconn, =20 virNodeDeviceObjRemove(&privconn->devs, &obj); =20 - ret =3D 0; - - cleanup: - if (obj) - virNodeDeviceObjUnlock(obj); testObjectEventQueue(privconn, event); - return ret; + return 0; } =20 =20 @@ -5328,16 +5322,14 @@ testNodeDeviceLookupByName(virConnectPtr conn, cons= t char *name) virNodeDevicePtr ret =3D NULL; =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, name))) - goto cleanup; + return NULL; =20 if ((ret =3D virGetNodeDevice(conn, name))) { if (VIR_STRDUP(ret->parent, obj->def->parent) < 0) virObjectUnref(ret); } =20 - cleanup: - if (obj) - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjUnlock(obj); return ret; } =20 @@ -5352,13 +5344,11 @@ testNodeDeviceGetXMLDesc(virNodeDevicePtr dev, virCheckFlags(0, NULL); =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) - goto cleanup; + return NULL; =20 ret =3D virNodeDeviceDefFormat(obj->def); =20 - cleanup: - if (obj) - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjUnlock(obj); return ret; } =20 @@ -5370,7 +5360,7 @@ testNodeDeviceGetParent(virNodeDevicePtr dev) char *ret =3D NULL; =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) - goto cleanup; + return NULL; =20 if (obj->def->parent) { ignore_value(VIR_STRDUP(ret, obj->def->parent)); @@ -5379,9 +5369,7 @@ testNodeDeviceGetParent(virNodeDevicePtr dev) "%s", _("no parent for this device")); } =20 - cleanup: - if (obj) - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjUnlock(obj); return ret; } =20 @@ -5393,19 +5381,15 @@ testNodeDeviceNumOfCaps(virNodeDevicePtr dev) virNodeDeviceObjPtr obj; virNodeDevCapsDefPtr caps; int ncaps =3D 0; - int ret =3D -1; =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) - goto cleanup; + return -1; =20 for (caps =3D obj->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 @@ -5416,26 +5400,25 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char *= *const names, int maxnames) virNodeDeviceObjPtr obj; virNodeDevCapsDefPtr caps; int ncaps =3D 0; - int ret =3D -1; =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) - goto cleanup; + return -1; =20 for (caps =3D obj->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 @@ -5584,13 +5567,13 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) virObjectEventPtr event =3D NULL; =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) - goto out; + return -1; =20 if (virNodeDeviceGetWWNs(obj->def, &wwnn, &wwpn) =3D=3D -1) - goto out; + goto cleanup; =20 if (VIR_STRDUP(parent_name, obj->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 @@ -5603,7 +5586,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) if (virNodeDeviceObjGetParentHost(&driver->devs, obj->def, EXISTING_DEVICE) < 0) { obj =3D NULL; - goto out; + goto cleanup; } =20 event =3D virNodeDeviceEventLifecycleNew(dev->name, @@ -5613,7 +5596,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) virNodeDeviceObjLock(obj); virNodeDeviceObjRemove(&driver->devs, &obj); =20 - out: + cleanup: if (obj) virNodeDeviceObjUnlock(obj); testObjectEventQueue(driver, event); --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list