From nobody Mon Feb 9 06:26:45 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 ARC-Seal: i=1; a=rsa-sha256; t=1565610881; cv=none; d=zoho.com; s=zohoarc; b=kA2p5JnQu8yFRlKNuUK4bOjK1d9RnzZ9VxMi5FWvMqSw7WJQhaOowiVRGTH6+1Qp3C9FrCRL+v2UBW8P9aU++Rzgd/Kp1eS7NkhzbWRKye8KhpiF/+vj61Tf9eHCZIGu87q1LCzeQQW5nJUcRgcAlvHD17J3O0pB5CanA8TL/Co= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565610881; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=+CUEEXL2pAQt8v7NHpOKdH6KhykiJsq9qYGfJqeZr4g=; b=OOSb+LhcdJaQ1mucO9pmIfUMYoUGdQgYdOSYCJldZD741GmmylNezn77xcJuneRkIu2z52HPAxTcw8C0DcIfEfvjenEcYDXik0MfWQTLf8BU71a4rqfd7jdzM0DzQl0GlSnrNi8+TxojjDlLavCw2FkYmzP5NmikbWf3KsNLv7E= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 156561088107013.815406210835363; Mon, 12 Aug 2019 04:54:41 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9D06F3066FD9; Mon, 12 Aug 2019 11:54:39 +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 79C1E7CD9C; Mon, 12 Aug 2019 11:54:39 +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 4241624F37; Mon, 12 Aug 2019 11:54:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7CBsZDr016171 for ; Mon, 12 Aug 2019 07:54:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 957D21001B20; Mon, 12 Aug 2019 11:54:35 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 215E01001B17 for ; Mon, 12 Aug 2019 11:54:34 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 12 Aug 2019 13:54:21 +0200 Message-Id: <6d4972c218e75d853a9740ff5a11ee2595af3e39.1565610801.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/9] virhostdevtest: Drop most of 'cleanup' and 'out' 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-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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Mon, 12 Aug 2019 11:54:40 +0000 (UTC) Content-Type: text/plain; charset="utf-8" From: Michal Privoznik In this test there is this macro CHECK_LIST_COUNT() which checks if a list of PCI devices contains expected count. If it doesn't an error is reported and 'goto cleanup' is invoked. There's no real reason for that as even since its introduction there is no cleanup done and all 'cleanup' labels contains nothing but 'return'. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- tests/virhostdevtest.c | 147 ++++++++++++----------------------------- 1 file changed, 42 insertions(+), 105 deletions(-) diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c index 2c65db2068..713e0ff9a6 100644 --- a/tests/virhostdevtest.c +++ b/tests/virhostdevtest.c @@ -41,7 +41,7 @@ VIR_LOG_INIT("tests.hostdevtest"); virReportError(VIR_ERR_INTERNAL_ERROR, \ "Unexpected count of items in " #list ": %zu, "= \ "expecting %zu", actualCount, (size_t) cnt); \ - goto cleanup; \ + return -1; \ } \ } while (0) =20 @@ -132,7 +132,6 @@ myInit(void) static int testVirHostdevPreparePCIHostdevs_unmanaged(void) { - int ret =3D -1; size_t active_count, inactive_count, i; =20 for (i =3D 0; i < nhostdevs; i++) @@ -145,7 +144,7 @@ testVirHostdevPreparePCIHostdevs_unmanaged(void) VIR_DEBUG("Test 0 hostdevs"); if (virHostdevPreparePCIDevices(mgr, drv_name, dom_name, uuid, NULL, 0, 0) < 0) - goto cleanup; + return -1; CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); =20 @@ -153,7 +152,7 @@ testVirHostdevPreparePCIHostdevs_unmanaged(void) VIR_DEBUG("Test >=3D1 unmanaged hostdevs"); if (virHostdevPreparePCIDevices(mgr, drv_name, dom_name, uuid, hostdevs, nhostdevs, 0) < 0) - goto cleanup; + return -1; CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count + nhostdevs); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count - nhostd= evs); =20 @@ -163,35 +162,30 @@ testVirHostdevPreparePCIHostdevs_unmanaged(void) VIR_DEBUG("Test: prepare same hostdevs for same driver/domain again"); if (virHostdevPreparePCIDevices(mgr, drv_name, dom_name, uuid, &hostdevs[0], 1, 0) =3D=3D 0) - goto cleanup; + return -1; CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); =20 VIR_DEBUG("Test: prepare same hostdevs for same driver, diff domain ag= ain"); if (virHostdevPreparePCIDevices(mgr, drv_name, "test_domain1", uuid, &hostdevs[1], 1, 0) =3D=3D 0) - goto cleanup; + return -1; CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); =20 VIR_DEBUG("Test: prepare same hostdevs for diff driver/domain again"); if (virHostdevPreparePCIDevices(mgr, "test_driver1", dom_name, uuid, &hostdevs[2], 1, 0) =3D=3D 0) - goto cleanup; + return -1; CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); =20 - ret =3D 0; - - cleanup: - return ret; - + return 0; } =20 static int testVirHostdevReAttachPCIHostdevs_unmanaged(void) { - int ret =3D -1; size_t active_count, inactive_count, i; =20 for (i =3D 0; i < nhostdevs; i++) { @@ -215,17 +209,12 @@ testVirHostdevReAttachPCIHostdevs_unmanaged(void) CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count - nhostdevs); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count + nhostd= evs); =20 - ret =3D 0; - - cleanup: - return ret; - + return 0; } =20 static int testVirHostdevPreparePCIHostdevs_managed(bool mixed) { - int ret =3D -1; size_t active_count, inactive_count, i; =20 for (i =3D 0; i < nhostdevs; i++) @@ -238,7 +227,7 @@ testVirHostdevPreparePCIHostdevs_managed(bool mixed) VIR_DEBUG("Test >=3D1 hostdevs"); if (virHostdevPreparePCIDevices(mgr, drv_name, dom_name, uuid, hostdevs, nhostdevs, 0) < 0) - goto cleanup; + return -1; CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count + nhostdevs); /* If testing a mixed roundtrip, devices are already in the inactive l= ist * before we start and are removed from it as soon as we attach them to @@ -254,35 +243,30 @@ testVirHostdevPreparePCIHostdevs_managed(bool mixed) VIR_DEBUG("Test: prepare same hostdevs for same driver/domain again"); if (virHostdevPreparePCIDevices(mgr, drv_name, dom_name, uuid, &hostdevs[0], 1, 0) =3D=3D 0) - goto cleanup; + return -1; CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); =20 VIR_DEBUG("Test: prepare same hostdevs for same driver, diff domain ag= ain"); if (virHostdevPreparePCIDevices(mgr, drv_name, "test_domain1", uuid, &hostdevs[1], 1, 0) =3D=3D 0) - goto cleanup; + return -1; CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); =20 VIR_DEBUG("Test: prepare same hostdevs for diff driver/domain again"); if (virHostdevPreparePCIDevices(mgr, "test_driver1", dom_name, uuid, &hostdevs[2], 1, 0) =3D=3D 0) - goto cleanup; + return -1; CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); =20 - ret =3D 0; - - cleanup: - return ret; - + return 0; } =20 static int testVirHostdevReAttachPCIHostdevs_managed(bool mixed) { - int ret =3D -1; size_t active_count, inactive_count, i; =20 for (i =3D 0; i < nhostdevs; i++) { @@ -311,82 +295,63 @@ testVirHostdevReAttachPCIHostdevs_managed(bool mixed) else CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); =20 - ret =3D 0; - - cleanup: - return ret; - + return 0; } =20 static int testVirHostdevDetachPCINodeDevice(void) { - int ret =3D -1; size_t active_count, inactive_count, i; =20 for (i =3D 0; i < nhostdevs; i++) { active_count =3D virPCIDeviceListCount(mgr->activePCIHostdevs); inactive_count =3D virPCIDeviceListCount(mgr->inactivePCIHostdevs); if (virHostdevPCINodeDeviceDetach(mgr, dev[i]) < 0) - goto cleanup; + return -1; CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count + 1); } =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 static int testVirHostdevResetPCINodeDevice(void) { - int ret =3D -1; size_t active_count, inactive_count, i; =20 for (i =3D 0; i < nhostdevs; i++) { active_count =3D virPCIDeviceListCount(mgr->activePCIHostdevs); inactive_count =3D virPCIDeviceListCount(mgr->inactivePCIHostdevs); if (virHostdevPCINodeDeviceReset(mgr, dev[i]) < 0) - goto cleanup; + return -1; CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); } =20 - ret =3D 0; - - cleanup: - return ret; - + return 0; } =20 static int testVirHostdevReAttachPCINodeDevice(void) { - int ret =3D -1; size_t active_count, inactive_count, i; =20 for (i =3D 0; i < nhostdevs; i++) { active_count =3D virPCIDeviceListCount(mgr->activePCIHostdevs); inactive_count =3D virPCIDeviceListCount(mgr->inactivePCIHostdevs); if (virHostdevPCINodeDeviceReAttach(mgr, dev[i]) < 0) - goto cleanup; + return -1; CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count - 1); } =20 - ret =3D 0; - - cleanup: - return ret; - + return 0; } =20 static int testVirHostdevUpdateActivePCIHostdevs(void) { - int ret =3D -1; size_t active_count, inactive_count; =20 active_count =3D virPCIDeviceListCount(mgr->activePCIHostdevs); @@ -395,21 +360,18 @@ testVirHostdevUpdateActivePCIHostdevs(void) VIR_DEBUG("Test 0 hostdevs"); if (virHostdevUpdateActivePCIDevices(mgr, NULL, 0, drv_name, dom_name) < 0) - goto cleanup; + return -1; CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); =20 VIR_DEBUG("Test >=3D1 hostdevs"); if (virHostdevUpdateActivePCIDevices(mgr, hostdevs, nhostdevs, drv_name, dom_name) < 0) - goto cleanup; + return -1; CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count + nhostdevs); CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 /** @@ -424,17 +386,12 @@ testVirHostdevUpdateActivePCIHostdevs(void) static int testVirHostdevRoundtripNoGuest(const void *opaque ATTRIBUTE_UNUSED) { - int ret =3D -1; - if (testVirHostdevDetachPCINodeDevice() < 0) - goto out; + return -1; if (testVirHostdevReAttachPCINodeDevice() < 0) - goto out; + return -1; =20 - ret =3D 0; - - out: - return ret; + return 0; } =20 /** @@ -451,21 +408,16 @@ testVirHostdevRoundtripNoGuest(const void *opaque ATT= RIBUTE_UNUSED) static int testVirHostdevRoundtripUnmanaged(const void *opaque ATTRIBUTE_UNUSED) { - int ret =3D -1; - if (testVirHostdevDetachPCINodeDevice() < 0) - goto out; + return -1; if (testVirHostdevPreparePCIHostdevs_unmanaged() < 0) - goto out; + return -1; if (testVirHostdevReAttachPCIHostdevs_unmanaged() < 0) - goto out; + return -1; if (testVirHostdevReAttachPCINodeDevice() < 0) - goto out; + return -1; =20 - ret =3D 0; - - out: - return ret; + return 0; } =20 /** @@ -480,17 +432,12 @@ testVirHostdevRoundtripUnmanaged(const void *opaque A= TTRIBUTE_UNUSED) static int testVirHostdevRoundtripManaged(const void *opaque ATTRIBUTE_UNUSED) { - int ret =3D -1; - if (testVirHostdevPreparePCIHostdevs_managed(false) < 0) - goto out; + return -1; if (testVirHostdevReAttachPCIHostdevs_managed(false) < 0) - goto out; + return -1; =20 - ret =3D 0; - - out: - return ret; + return 0; } =20 /** @@ -508,21 +455,16 @@ testVirHostdevRoundtripManaged(const void *opaque ATT= RIBUTE_UNUSED) static int testVirHostdevRoundtripMixed(const void *opaque ATTRIBUTE_UNUSED) { - int ret =3D -1; - if (testVirHostdevDetachPCINodeDevice() < 0) - goto out; + return -1; if (testVirHostdevPreparePCIHostdevs_managed(true) < 0) - goto out; + return -1; if (testVirHostdevReAttachPCIHostdevs_managed(true) < 0) - goto out; + return -1; if (testVirHostdevReAttachPCINodeDevice() < 0) - goto out; + return -1; =20 - ret =3D 0; - - out: - return ret; + return 0; } =20 /** @@ -537,17 +479,12 @@ testVirHostdevRoundtripMixed(const void *opaque ATTRI= BUTE_UNUSED) static int testVirHostdevOther(const void *opaque ATTRIBUTE_UNUSED) { - int ret =3D -1; - if (testVirHostdevResetPCINodeDevice() < 0) - goto out; + return -1; if (testVirHostdevUpdateActivePCIHostdevs() < 0) - goto out; + return -1; =20 - ret =3D 0; - - out: - return ret; + return 0; } =20 # define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX" --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list