From nobody Mon May 6 03:50:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1603848996; cv=none; d=zohomail.com; s=zohoarc; b=dYVkQgn7WlqWIQM7jg/X0lvc+rB2xoD/7R+ctJonydUmpnHdSp7ttQ+n/7W1WZeoJG4G0AOz0rByaRiZmthdkf8v4mB1aSB9f1Pr09aUeE+G4OGiJa6Fpvm7zoARYsKu8VRSdWEm59v3EVVCVFQGhZxypOnRj0DAWcmkMIFiVk4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603848996; 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; bh=Fqd3pPwCTfizE0ff0k7W8LdBlskuAJyizGvh5npcCao=; b=NYXt8UAvHx43rrKdzXcXYxHEGnvAbmf7nC8qcf2VhKSGlfPFKPY6xVdJczj3EEuy/hWb+CfKLWgYo4zZ2zOLzlR7gwqXkqNBbx2S3wYwB3NEmjRT5EwYdzYoX3MGDaW3CObb/YAM1FyxD+1qPfZF7rogkxi+++8jMi7u2xXRV1I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 160384899696046.74304606181238; Tue, 27 Oct 2020 18:36:36 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-452-Da1NYeZPPfCXx1vSRwCOog-1; Tue, 27 Oct 2020 21:36:33 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4E497802B61; Wed, 28 Oct 2020 01:36:28 +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 0810F6EF55; Wed, 28 Oct 2020 01:36:28 +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 9D8F258127; Wed, 28 Oct 2020 01:36:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 09S1a61D028225 for ; Tue, 27 Oct 2020 21:36:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id B494D5C22B; Wed, 28 Oct 2020 01:36:06 +0000 (UTC) Received: from vhost2.laine.org (ovpn-113-144.phx2.redhat.com [10.3.113.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id 76E985C22A for ; Wed, 28 Oct 2020 01:36:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603848995; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Fqd3pPwCTfizE0ff0k7W8LdBlskuAJyizGvh5npcCao=; b=OctTuSF8EoDIOjsWZU4EuZUhmf4Alwl9YdQgmBVspYloCMTXnurBQuX7JpS5HwXkrVPV0/ CLI//7DKO1Zj9GE6lWYcNLvRjYZ5w0bUpsish3an/D6HvsdgVJ1AP1LGZgy0YCGC316txi X2p5MXDgg+lbypkOOeUzHzTBrKoGDao= X-MC-Unique: Da1NYeZPPfCXx1vSRwCOog-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 01/12] consistently use VIR_DIR_CLOSE() instead of virDirClose() Date: Tue, 27 Oct 2020 21:35:47 -0400 Message-Id: <20201028013558.424925-2-laine@redhat.com> In-Reply-To: <20201028013558.424925-1-laine@redhat.com> References: <20201028013558.424925-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This will make it easier to review upcoming patches that use g_autoptr to auto-close all DIRs. Signed-off-by: Laine Stump Reviewed-by: Daniel Henrique Barboza --- src/qemu/qemu_interop_config.c | 2 +- src/security/security_selinux.c | 6 ++---- src/util/virdevmapper.c | 2 +- src/util/virfile.c | 3 +-- tests/testutilsqemu.c | 5 ++--- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_interop_config.c b/src/qemu/qemu_interop_config.c index 53b251f056..7edca7540a 100644 --- a/src/qemu/qemu_interop_config.c +++ b/src/qemu/qemu_interop_config.c @@ -79,7 +79,7 @@ qemuBuildFileList(virHashTablePtr files, const char *dir) =20 ret =3D 0; cleanup: - virDirClose(&dirp); + VIR_DIR_CLOSE(dirp); return ret; } =20 diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 733bcf23d9..7d9e62a239 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -3487,8 +3487,7 @@ virSecuritySELinuxSetFileLabels(virSecurityManagerPtr= mgr, virReportSystemError(errno, _("Unable to label files under %s"), path); =20 - virDirClose(&dir); - + VIR_DIR_CLOSE(dir); return ret; } =20 @@ -3532,8 +3531,7 @@ virSecuritySELinuxRestoreFileLabels(virSecurityManage= rPtr mgr, virReportSystemError(errno, _("Unable to restore file labels under= %s"), path); =20 - virDirClose(&dir); - + VIR_DIR_CLOSE(dir); return ret; } =20 diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c index 4d27c9f104..f26d36832a 100644 --- a/src/util/virdevmapper.c +++ b/src/util/virdevmapper.c @@ -211,7 +211,7 @@ virDMSanitizepath(const char *path) } } =20 - virDirClose(&dh); + VIR_DIR_CLOSE(dh); return ret; } =20 diff --git a/src/util/virfile.c b/src/util/virfile.c index 7d0a40b0fb..970d4bd234 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -2983,8 +2983,7 @@ int virFileChownFiles(const char *name, ret =3D 0; =20 cleanup: - virDirClose(&dir); - + VIR_DIR_CLOSE(dir); return ret; } =20 diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 4defba0b7b..278587767f 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -558,7 +558,7 @@ testQemuGetLatestCapsForArch(const char *arch, ret =3D g_strdup_printf("%s/%s", TEST_QEMU_CAPS_PATH, maxname); =20 cleanup: - virDirClose(&dir); + VIR_DIR_CLOSE(dir); return ret; } =20 @@ -667,8 +667,7 @@ testQemuCapsIterate(const char *suffix, ret =3D 0; =20 cleanup: - virDirClose(&dir); - + VIR_DIR_CLOSE(dir); return ret; } =20 --=20 2.26.2 From nobody Mon May 6 03:50:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1603848981; cv=none; d=zohomail.com; s=zohoarc; b=KZkLpxqxmGai+VRcf/E/1J9dT7ACJ4tG5ZPxkWTH43baBYMSCAiS4VJiRHHAOU9QymgUjG6HfwVAWj0qXZRDkXEg72glO7hCDweGezWKQwoGmbtvxxhFIRauyFdUP3gpgtwdcFYlIj3HLffbzM9UcVjxKbp3rCithL874ub9K9Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603848981; 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; bh=LKRLFjg6HjWIeMICvQ+MzoJ4lbvMhgtDqCD1amZQMCw=; b=c15oPVp89Joc/0PhiLKHeieGfazzxfliu5vzkambIkbY86DCVcQjvWdSsd+krdPqGsQ8UrB/kFcccf9Xrhwj8T03lUny2JqwtbtWxtR5JO18oS/zKIelKUPemOePIMSMZM0kEr4sBH9ScNyfW85mh5qRfkFQvaEFPrqM9DCXKxU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1603848981510264.43184227602535; Tue, 27 Oct 2020 18:36:21 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-501-LzqSwDdzOsixBFRPTTT0SA-1; Tue, 27 Oct 2020 21:36:18 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CDEF364A75; Wed, 28 Oct 2020 01:36:11 +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 A0BC76EF71; Wed, 28 Oct 2020 01:36:11 +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 B4C5458103; Wed, 28 Oct 2020 01:36:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 09S1a7jF028231 for ; Tue, 27 Oct 2020 21:36:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 244AF5C22B; Wed, 28 Oct 2020 01:36:07 +0000 (UTC) Received: from vhost2.laine.org (ovpn-113-144.phx2.redhat.com [10.3.113.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB1F55C22A for ; Wed, 28 Oct 2020 01:36:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603848980; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=LKRLFjg6HjWIeMICvQ+MzoJ4lbvMhgtDqCD1amZQMCw=; b=SSjD2FDHj5CvnMGdbOedUyGCItSAHgZMiki/K5GfX56HF+aR9gzzo8BrTmInVORi0+F/Wb Az8y6CvZR9H5yT8mG0L1Cx8tLw4HeqD8mTgrh8b5Hm/xMuAqFq9hkbdHhp+1uNSlMMNZc5 mWgy5SM9u72KRN0vP54j9fePgUwnqsk= X-MC-Unique: LzqSwDdzOsixBFRPTTT0SA-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 02/12] tools: reduce scope of a DIR* in virHostValidateIOMMU() Date: Tue, 27 Oct 2020 21:35:48 -0400 Message-Id: <20201028013558.424925-3-laine@redhat.com> In-Reply-To: <20201028013558.424925-1-laine@redhat.com> References: <20201028013558.424925-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This will make the trivial nature of a conversion to g_autoptr (in a later patch) more obvious. Signed-off-by: Laine Stump Reviewed-by: Daniel Henrique Barboza --- tools/virt-host-validate-common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-c= ommon.c index 9779eb7b3b..61284ae4da 100644 --- a/tools/virt-host-validate-common.c +++ b/tools/virt-host-validate-common.c @@ -336,7 +336,6 @@ int virHostValidateIOMMU(const char *hvname, bool isAMD =3D false, isIntel =3D false; virArch arch =3D virArchFromHost(); struct dirent *dent; - DIR *dir; int rc; =20 flags =3D virHostValidateGetCPUFlags(); @@ -375,6 +374,8 @@ int virHostValidateIOMMU(const char *hvname, } else if (ARCH_IS_PPC64(arch)) { /* Empty Block */ } else if (ARCH_IS_S390(arch)) { + DIR *dir; + /* On s390x, we skip the IOMMU check if there are no PCI * devices (which is quite usual on s390x). If there are * no PCI devices the directory is still there but is --=20 2.26.2 From nobody Mon May 6 03:50:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1603848998; cv=none; d=zohomail.com; s=zohoarc; b=LUrZLvw7DGtCG7WtygiS5SL5oF/+Ma0SpX3AGkigjg2pb3RMUQnJw6VL7AfNrmi/LBYp6K9X9S40Zv3wRzucLtFiH66eX1S7uUX3+j66pr/eAD73PIdr7ahoQEHEN5RD4Cr+hXFJXm967B1U1ry8aPyCw40m/gQXkBiFATP65Sg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603848998; 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; bh=QVPJi0Jk29oNXhvtPD75KQ9H8mXHfQxB3uptfYC2hSQ=; b=TjHzKd0fkoxO0fgW2RkdfsThqvoZjst2vyO+VlvmmETwZ7RzqFli47QvvmsCv/fnddnxhL7AcDyiLHNinEzuU39N9mHmyJIKKqURjjS85veUvKcOMUEQWP1YKot63FPfJkbR7ks7LPp3xjo9vnwbunsUILrM3I6CbLkyQY9qRdk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1603848998333219.66087997912416; Tue, 27 Oct 2020 18:36:38 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-223-coX6ZD9EOzqHP_fanMWiKA-1; Tue, 27 Oct 2020 21:36:34 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2AEFE802B48; Wed, 28 Oct 2020 01:36:28 +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 075336266E; Wed, 28 Oct 2020 01:36:28 +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 99AE7181A87F; Wed, 28 Oct 2020 01:36:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 09S1a7Ai028239 for ; Tue, 27 Oct 2020 21:36:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 884BE5C22B; Wed, 28 Oct 2020 01:36:07 +0000 (UTC) Received: from vhost2.laine.org (ovpn-113-144.phx2.redhat.com [10.3.113.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id 49F155C22A for ; Wed, 28 Oct 2020 01:36:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603848997; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=QVPJi0Jk29oNXhvtPD75KQ9H8mXHfQxB3uptfYC2hSQ=; b=VLfdmpx+DWAwGT0GQvDlObyN9Z29wBcYidT5eqkLlcv4zcuqwgBBGMLZj8VumMRHxuqsBI 61NxpP9yewhBOHtRemKoIpG2G5ZmcBgBoNY1unPH9l9ZxEUqaualTYNUFENDNdY7ijvtdz yRea/YldbcFmuRweG7iiewgY8ayu/ts= X-MC-Unique: coX6ZD9EOzqHP_fanMWiKA-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 03/12] storage: remove extraneous call to VIR_DIR_CLOSE() Date: Tue, 27 Oct 2020 21:35:49 -0400 Message-Id: <20201028013558.424925-4-laine@redhat.com> In-Reply-To: <20201028013558.424925-1-laine@redhat.com> References: <20201028013558.424925-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" VIR_DIR_CLOSE(dir) is called in the middle of virStorageBackendRefreshLocal(), which is okay, but redundant - there is no reference to dir between that call and the end of the function, where VIR_DIR_CLOSE() is called again. Remove the extra call in the middle to simplify the function and make the conversion to g_autoptr trivial/mechanical. Signed-off-by: Laine Stump Reviewed-by: Daniel Henrique Barboza --- src/storage/storage_util.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 21ad54ac54..7eaf899883 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -3553,7 +3553,6 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr po= ol) } if (direrr < 0) goto cleanup; - VIR_DIR_CLOSE(dir); =20 target =3D virStorageSourceNew(); =20 --=20 2.26.2 From nobody Mon May 6 03:50:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1603848980; cv=none; d=zohomail.com; s=zohoarc; b=myaHQqaYKVfED7k8XfgIokuZMtMyUTbbcVIqqWI/Pf5c8ZrONj9p5nMfPj50SLqpB5IwVRJuK2e2vh9u8qAStIZktsH8Km62Z50fLPBZD7aEbTjIS8Tv0ouajVelOXvMkB81KS18AuGzwyBkbm/fIgqi56jktIzgoE0nZLK8jf4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603848980; 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; bh=u9Kd1eGQAvlRfuH0NCn4FSsJwduyZwkPC4lekfAdhCc=; b=Udb49810qWmR8erQda3mHbqA27OeB14rmTpwMRBXrr1klxqw5lidh2t/sC5mrLdviRP0Z07RPY170s5OMy9jIp5suonYM5uKEsvhr7w5gP178q3FDU0eiTnrWP0A7k2iKPfhZRcXVorNVuXofAz3l7aaQ7XQv4wSbQyjiJqBLws= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1603848980925744.2691645422796; Tue, 27 Oct 2020 18:36:20 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-590-9fcgIWpFMtqk95L85_4Edw-1; Tue, 27 Oct 2020 21:36:17 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5380A83DC24; Wed, 28 Oct 2020 01:36:12 +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 2E5EF6EF71; Wed, 28 Oct 2020 01:36:12 +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 CB5B75810F; Wed, 28 Oct 2020 01:36:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 09S1a7LU028245 for ; Tue, 27 Oct 2020 21:36:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id EF8195C22B; Wed, 28 Oct 2020 01:36:07 +0000 (UTC) Received: from vhost2.laine.org (ovpn-113-144.phx2.redhat.com [10.3.113.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF03C5C22A for ; Wed, 28 Oct 2020 01:36:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603848979; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=u9Kd1eGQAvlRfuH0NCn4FSsJwduyZwkPC4lekfAdhCc=; b=ax8fPk+nZXma7G/6GjYpj5DruMD6PSx0v5amYQ7IdPr4zCLn/KI7BsXKhv/ldvohGTc8+3 emrVVaOXTuvspPvTwsPDzHA208C+eSPvFwPOGU2RLQVQPvKi3HtN5yQELGYyzCmBJ+zzv4 AEfNXSWDBoJZiqLfaH+M36+qjVfcbpM= X-MC-Unique: 9fcgIWpFMtqk95L85_4Edw-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 04/12] util: reduce scope of a DIR * in virCgroupV1SetOwner() Date: Tue, 27 Oct 2020 21:35:50 -0400 Message-Id: <20201028013558.424925-5-laine@redhat.com> In-Reply-To: <20201028013558.424925-1-laine@redhat.com> References: <20201028013558.424925-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" DIR *dh is being re-used each time through the for loop of this function, so it must be closed and then re-opened, which means we can't convert it to g_autoptr. By moving the definition of dh inside the for loop, we make it possible to trivially convert to g_autoptr (which will happen in a subsequent patch) NB: VIR_DIR_CLOSE() is already called at the bottom of the for loop, so removing the VIR_DIR_CLOSE() at the end of the function is *not* creating a leak of a DIR*! Signed-off-by: Laine Stump Reviewed-by: Daniel Henrique Barboza --- src/util/vircgroupv1.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 91c1c4d4b1..67b35c1b9a 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -875,12 +875,12 @@ virCgroupV1SetOwner(virCgroupPtr cgroup, { int ret =3D -1; size_t i; - DIR *dh =3D NULL; int direrr; =20 for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { g_autofree char *base =3D NULL; struct dirent *de; + DIR *dh =3D NULL; =20 if (!((1 << i) & controllers)) continue; @@ -922,7 +922,6 @@ virCgroupV1SetOwner(virCgroupPtr cgroup, ret =3D 0; =20 cleanup: - VIR_DIR_CLOSE(dh); return ret; } =20 --=20 2.26.2 From nobody Mon May 6 03:50:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1603849026; cv=none; d=zohomail.com; s=zohoarc; b=e9AXdCoUXmBynQCE4RDDh8vPlOUFV0P2fP7kJAp3Or7UVVdLK8EyKqytD4dQpuNGMxazQr3zlBFSLRZ+rMZ/3KUXDduazdTS3KA1+3KHyC2214cLBM6etaJj1xI8CiORoqXoZ1dRWSsowhiZLjBjRaspyuU/gL7kDk+6RNO7lR0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603849026; 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; bh=VKtbTN3vMaVM1U+n9sSJhNDUgP7di/KY44HzdEANQEk=; b=Gqv+Qq0NZDp7UUIdd0MgtxBVt5UI0SJVYeySXlXOBhskpopeYRTECAV3D5A9wQ4l4qPjCTrwDuSS9+T/X9j8X7APR69M4lDICxl3LKfmm5CJJrxVEu0IreohL4rL8rJByClA0hkl2Jhlxm6J8F3LhO09Mx+MJU8WcCHCy8PPxGk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1603849026147986.3604186968507; Tue, 27 Oct 2020 18:37:06 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-555-EzsW8GrCPTu_Hp8Na12BiA-1; Tue, 27 Oct 2020 21:36:42 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 090D91084D75; Wed, 28 Oct 2020 01:36:31 +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 DC3F460C11; Wed, 28 Oct 2020 01:36:30 +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 A5C3DCF4B; Wed, 28 Oct 2020 01:36:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 09S1a8pV028250 for ; Tue, 27 Oct 2020 21:36:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5EC9B5C22B; Wed, 28 Oct 2020 01:36:08 +0000 (UTC) Received: from vhost2.laine.org (ovpn-113-144.phx2.redhat.com [10.3.113.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id 217BA5C22A for ; Wed, 28 Oct 2020 01:36:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603849025; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=VKtbTN3vMaVM1U+n9sSJhNDUgP7di/KY44HzdEANQEk=; b=OgYK+edxzsP/0/kjlpbpRTeXMAE68T72DGBjpsvjF8B+4S3sXivbItOUDh4ieQkcP0p2PY FYFl4mISEMh+i/4NFTvyYS0EJi/g7HyJNcTl0iMZ8qaIGixAH2dRoCLEO1TAt7ZtcqSYxK wyGz/uLKKFZ5jQ0kzwBFYkkq2Vcy0iU= X-MC-Unique: EzsW8GrCPTu_Hp8Na12BiA-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 05/12] util: manually set dirp to NULL after closing in virCapabilitiesInitCache() Date: Tue, 27 Oct 2020 21:35:51 -0400 Message-Id: <20201028013558.424925-6-laine@redhat.com> In-Reply-To: <20201028013558.424925-1-laine@redhat.com> References: <20201028013558.424925-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" In all uses of VIR_DIR_CLOSE() except one, the DIR* is never referenced after closing all the way until it goes out of scope. virCapabilitiesInitCaches(), however, reuses the same DIR* over and over in a loop, but due to having many error conditions that result in a goto out of the loop, it's not well suited to reducing the scope of the variable until we introduce a g_autoptr cleanup function for DIR*. In preparation for doing just that, we need to get rid of the side effect of VIR_DIR_CLOSE() setting the DIR* to NULL, so in this one case, let's manually set the DIR* to NULL. Then in an upcoming patch we can safely remove the side effect from VIR_DIR_CLOSE(). This extra/ugly bit of code is only temporary: once we introduce the g_autoptr cleanup function for DIR*, we will remove this manual close/clear completely anyway. Signed-off-by: Laine Stump Reviewed-by: Daniel Henrique Barboza --- src/conf/capabilities.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 90ad4e0c13..18b2612d2e 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -1865,6 +1865,7 @@ virCapabilitiesInitCaches(virCapsPtr caps) path =3D g_strdup_printf("%s/cpu/cpu%zd/cache/", SYSFS_SYSTEM_PATH= , pos); =20 VIR_DIR_CLOSE(dirp); + dirp =3D NULL; =20 rv =3D virDirOpenIfExists(&dirp, path); if (rv < 0) --=20 2.26.2 From nobody Mon May 6 03:50:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1603849005; cv=none; d=zohomail.com; s=zohoarc; b=JUchsj3Av7cIBGLGyabZrUbARJnl9QeHARVyScw78UBw3iqiYtxM6/3NDhdABEkYOwA9A5bajvZ7r1LYuGHXe03GkxlpUDgLetbz4EhFmv7ih4+eGdBMO2Tq/llAkcOeZZKOe7JkW4FISqKfRXwGxc87bBLK/YiovKZsD51c5E4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603849005; 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; bh=1dspbdOCeIXSYo4u44driwE+2NSKYgM4fTeXnPxVQrU=; b=FnIEMa8Lvj8iBF/ZrrOH5D2dSjPi/f1jTiwzlXbKHRi98rx2b0kX4MNJsQiROt5es1UptULuENjvd4su2QJH3TUqhymliraPlrOp0O1qFKdURN/K68r54+HbIqE1YkiFR36UDTvzf9skIoJ2pABS6eIgNyAVq2PGZKiTfnPrLAY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1603849005894481.1294080599512; Tue, 27 Oct 2020 18:36:45 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-555--Dr21_RFO6m91_HkV6q5wA-1; Tue, 27 Oct 2020 21:36:42 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7FEFF1084D76; Wed, 28 Oct 2020 01:36:31 +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 5BB2119D61; Wed, 28 Oct 2020 01:36:31 +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 22100181A88C; Wed, 28 Oct 2020 01:36:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 09S1a8mt028258 for ; Tue, 27 Oct 2020 21:36:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id C8F585C6DD; Wed, 28 Oct 2020 01:36:08 +0000 (UTC) Received: from vhost2.laine.org (ovpn-113-144.phx2.redhat.com [10.3.113.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id 830F55C22A for ; Wed, 28 Oct 2020 01:36:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603849004; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=1dspbdOCeIXSYo4u44driwE+2NSKYgM4fTeXnPxVQrU=; b=aoSEoP+fHo+xAmP3VIVKVKfx9pOx9aPvmqzegr2liEuG1v6DuWHM2suo25Lg2ruFCfdluf Vy6AVMqgtqEOh8IuDMvLFD6sbAWwwUvunzsVWfoovYnkIRpr3/GSBCQHT/zT17mG+FIOKI D+bYv/KGUe04yIvkDvEMCjq1ARHhKlo= X-MC-Unique: -Dr21_RFO6m91_HkV6q5wA-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 06/12] util: change virDirClose to take a DIR* instead of DIR**. Date: Tue, 27 Oct 2020 21:35:52 -0400 Message-Id: <20201028013558.424925-7-laine@redhat.com> In-Reply-To: <20201028013558.424925-1-laine@redhat.com> References: <20201028013558.424925-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" In order to make a usable g_autoptr(DIR), we need to have a close function that is a NOP when the pointer is NULL, but takes a simple DIR*. But virDirClose() (candidate to be the g_autoptr cleanup function) currently takes a DIR**, not DIR*. It does this so that it can clear the pointer, thus making it safe to call virDirClose on the same DIR multiple times. In the past the clearing of the DIR* was essential in a few places, but those few places have now been changed, so we can modify virDirClose() to take a DIR*, and remove the side effect of clearing the DIR*. This will make it directly usable as the g_autoptr cleanup, and will mean that this: { DIR *dirp =3D NULL; blah blah ... VIR_DIR_CLOSE(dirp) } is functionally identical to { g_autoptr(DIR) dirp =3D NULL; blah blah ... } which will make conversion to using g_autoptr mechanical and simple to revi= ew. (Note that virDirClose() will still check for NULL before attempting to close, so that it can always be safely called, as long as the DIR* was initialized to NULL (another prerequisite of becoming a g_autoptr cleanup function) Signed-off-by: Laine Stump Reviewed-by: Daniel Henrique Barboza --- src/util/virfile.c | 7 +++---- src/util/virfile.h | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 970d4bd234..442d2fab96 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -2927,13 +2927,12 @@ int virDirRead(DIR *dirp, struct dirent **ent, cons= t char *name) return !!*ent; } =20 -void virDirClose(DIR **dirp) +void virDirClose(DIR *dirp) { - if (!*dirp) + if (!dirp) return; =20 - closedir(*dirp); /* exempt from syntax-check */ - *dirp =3D NULL; + closedir(dirp); /* exempt from syntax-check */ } =20 =20 diff --git a/src/util/virfile.h b/src/util/virfile.h index 09488398c5..6fde4f88ca 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -269,9 +269,9 @@ int virDirOpenQuiet(DIR **dirp, const char *dirname) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; int virDirRead(DIR *dirp, struct dirent **ent, const char *dirname) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; -void virDirClose(DIR **dirp) +void virDirClose(DIR *dirp) ATTRIBUTE_NONNULL(1); -#define VIR_DIR_CLOSE(dir) virDirClose(&(dir)) +#define VIR_DIR_CLOSE(dir) virDirClose(dir) =20 int virFileMakePath(const char *path) G_GNUC_WARN_UNUSED_RESULT; int virFileMakePathWithMode(const char *path, --=20 2.26.2 From nobody Mon May 6 03:50:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1603849143; cv=none; d=zohomail.com; s=zohoarc; b=irArvSwzmTRrSWjyBuuDsPwMYqbpV2PRteWDnXvt6QHOcGasdAidk5PcBOXdFIh5gMt+mEYhtp9C25V/ZZ9rGtj7+fVFmcnf87ozr8u6ogetUlzZp2Gtf/avOV5MEAxAkIriKA2UPvy0u5Pynvls5yCgBjaSz8xtuzuhUonpyaQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603849143; 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; bh=YUJNTkLZzNk7awBKTtCj4UYizlVP0y37A2lc4lOR2ss=; b=HRs5nsy7VI0qD6du/8D68QjtJLr3ES34r66kraXTs8t64ugc/ymgHgxetvN9nCmLlqXLriNBfKK+ry1MoFlHHgA1wbPpooxU4FMU47qps9iKqUH9anvWp31YhISK+veqvIsHQWjKk5PN+PZVBpE29oDxIHgpFL8jry6iBDYSm+c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1603849143927886.0331621238445; Tue, 27 Oct 2020 18:39:03 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-298-p4jlaezTPOa3a5QV84yQ5A-1; Tue, 27 Oct 2020 21:36:41 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 78F421009E53; Wed, 28 Oct 2020 01:36:34 +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 5B6E46EF46; Wed, 28 Oct 2020 01:36:34 +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 D53D11826D39; Wed, 28 Oct 2020 01:36:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 09S1a9B4028263 for ; Tue, 27 Oct 2020 21:36:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 35D5B5C1C5; Wed, 28 Oct 2020 01:36:09 +0000 (UTC) Received: from vhost2.laine.org (ovpn-113-144.phx2.redhat.com [10.3.113.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id E9F015C1DC for ; Wed, 28 Oct 2020 01:36:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603849142; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=YUJNTkLZzNk7awBKTtCj4UYizlVP0y37A2lc4lOR2ss=; b=D+deqw/lOBi/Wu8F3UiWX72GIk+kgvRoTuZG9z8m+Zp8POFryO1IJA2ZAiPC8oZadnoYzA cBJQOYZc9EM36scAfNe/QIvMMK7tR8uz4Uzc0xl5hHarn9/T7kEpYC7Oph4BNMR7NN+h/C zIpura58HfEuT1NLqkVrXCSYxbLUNK0= X-MC-Unique: p4jlaezTPOa3a5QV84yQ5A-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 07/12] util: declare g_autoptr cleanup function to auto-close DIR* Date: Tue, 27 Oct 2020 21:35:53 -0400 Message-Id: <20201028013558.424925-8-laine@redhat.com> In-Reply-To: <20201028013558.424925-1-laine@redhat.com> References: <20201028013558.424925-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Laine Stump Reviewed-by: Daniel Henrique Barboza --- src/util/virfile.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/virfile.h b/src/util/virfile.h index 6fde4f88ca..6973fbd54a 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -271,6 +271,7 @@ int virDirRead(DIR *dirp, struct dirent **ent, const ch= ar *dirname) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; void virDirClose(DIR *dirp) ATTRIBUTE_NONNULL(1); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(DIR, virDirClose); #define VIR_DIR_CLOSE(dir) virDirClose(dir) =20 int virFileMakePath(const char *path) G_GNUC_WARN_UNUSED_RESULT; --=20 2.26.2 From nobody Mon May 6 03:50:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1603849009; cv=none; d=zohomail.com; s=zohoarc; b=NaLkFInS4y3w/ex5p9CPjENZ3cFo0L1qO+4LbDPL5b4BsPEetYgqPagjZziwUbHFfCJrARgr3tCnsUkWl6AM/BihKi39g4Jc5pVhHggL20gEDj9WPoWJ491PDXgCjM+sGgqZeDqJU05aS5NwRosBSwJNZcRRzjA86CXT78EC6MY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603849009; 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; bh=rS+AJoL7puWREDAyX7EwpT8r/vVPjCgHtIrP+gqXfPE=; b=Yk1IMYk2bKuwEWZe1KfPZYxTvGSj++DlCFvOqjkzu8E8RdouzZk4KkESN01KF4jRU1eXIZ7rFrisrX7e6XBAt3E3/b5fw29lTld+XRpSoDwCybBktqmrwJYiCckABXkrHruMzSKuDGXySlprTq15/LhtcoqAvRPKGRhwiK1tAeM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1603849009828862.1427593809492; Tue, 27 Oct 2020 18:36:49 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-494-GHsKlQZVMt2Glm8gOiRRsA-1; Tue, 27 Oct 2020 21:36:46 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2E07F835B50; Wed, 28 Oct 2020 01:36:37 +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 0AD535D9F7; Wed, 28 Oct 2020 01:36:37 +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 B4253CF64; Wed, 28 Oct 2020 01:36:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 09S1a9Kq028272 for ; Tue, 27 Oct 2020 21:36:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id AE7A75C22A; Wed, 28 Oct 2020 01:36:09 +0000 (UTC) Received: from vhost2.laine.org (ovpn-113-144.phx2.redhat.com [10.3.113.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D3945C1C5 for ; Wed, 28 Oct 2020 01:36:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603849008; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=rS+AJoL7puWREDAyX7EwpT8r/vVPjCgHtIrP+gqXfPE=; b=B4qfdbyKN72sxsNgy1uyUqQklDYniQ098Y56kMHihpeY5DoKFC8fK8F3fJ7mpW/ZyDeUMx l4bsQ3pB4P4XEKwPhnCA58TP+MrMO3dEAzybaKrA9whs4ej3RFpl1fb0eshnPujnyg/wCI UNlzwQoYIrwTRv6pM19uarr5b3CCdas= X-MC-Unique: GHsKlQZVMt2Glm8gOiRRsA-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 08/12] change DIR* int g_autoptr(DIR) where appropriate Date: Tue, 27 Oct 2020 21:35:54 -0400 Message-Id: <20201028013558.424925-9-laine@redhat.com> In-Reply-To: <20201028013558.424925-1-laine@redhat.com> References: <20201028013558.424925-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" All of these conversions are trivial - VIR_DIR_CLOSE() (aka virDirClose()) is called only once on the DIR*, and it happens just before going out of scope. Signed-off-by: Laine Stump Reviewed-by: Daniel Henrique Barboza --- src/bhyve/bhyve_capabilities.c | 3 +-- src/conf/virdomainobjlist.c | 3 +-- src/conf/virnetworkobj.c | 12 ++++-------- src/conf/virnwfilterbindingobjlist.c | 3 +-- src/conf/virnwfilterobj.c | 3 +-- src/conf/virsecretobj.c | 3 +-- src/conf/virstorageobj.c | 6 ++---- src/openvz/openvz_conf.c | 3 +-- src/qemu/qemu_driver.c | 6 ++---- src/qemu/qemu_interop_config.c | 3 +-- src/security/security_selinux.c | 6 ++---- src/storage/storage_backend_iscsi.c | 3 +-- src/storage/storage_util.c | 18 +++++------------- src/util/vircgroup.c | 7 ++----- src/util/vircgroupv1.c | 4 +--- src/util/vircommand.c | 3 +-- src/util/virdevmapper.c | 3 +-- src/util/virfile.c | 12 ++++-------- src/util/virhook.c | 8 ++------ src/util/virhostcpu.c | 6 ++---- src/util/virnetdev.c | 3 +-- src/util/virnuma.c | 3 +-- src/util/virpci.c | 15 +++++---------- src/util/virprocess.c | 3 +-- src/util/virresctrl.c | 9 +++------ src/util/virscsi.c | 6 ++---- src/util/virscsihost.c | 3 +-- src/util/virusb.c | 3 +-- src/util/virutil.c | 6 ++---- src/util/virvhba.c | 9 +++------ tests/testutilsqemu.c | 6 ++---- tests/virschematest.c | 3 +-- tools/virt-host-validate-common.c | 3 +-- 33 files changed, 60 insertions(+), 127 deletions(-) diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c index 8a9acf52b0..e9b4e5176d 100644 --- a/src/bhyve/bhyve_capabilities.c +++ b/src/bhyve/bhyve_capabilities.c @@ -134,7 +134,7 @@ virBhyveDomainCapsBuild(bhyveConnPtr conn, { virDomainCapsPtr caps =3D NULL; unsigned int bhyve_caps =3D 0; - DIR *dir; + g_autoptr(DIR) dir =3D NULL; struct dirent *entry; size_t firmwares_alloc =3D 0; virBhyveDriverConfigPtr cfg =3D virBhyveDriverGetConfig(conn); @@ -171,7 +171,6 @@ virBhyveDomainCapsBuild(bhyveConnPtr conn, =20 cleanup: VIR_FREE(firmwares); - VIR_DIR_CLOSE(dir); virObjectUnref(cfg); return caps; } diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c index e9a4b271df..9c10090b32 100644 --- a/src/conf/virdomainobjlist.c +++ b/src/conf/virdomainobjlist.c @@ -588,7 +588,7 @@ virDomainObjListLoadAllConfigs(virDomainObjListPtr doms, virDomainLoadConfigNotify notify, void *opaque) { - DIR *dir; + g_autoptr(DIR) dir =3D NULL; struct dirent *entry; int ret =3D -1; int rc; @@ -633,7 +633,6 @@ virDomainObjListLoadAllConfigs(virDomainObjListPtr doms, } } =20 - VIR_DIR_CLOSE(dir); virObjectRWUnlock(doms); return ret; } diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c index 46205b163c..acf1442f88 100644 --- a/src/conf/virnetworkobj.c +++ b/src/conf/virnetworkobj.c @@ -1072,7 +1072,7 @@ virNetworkObjLoadAllState(virNetworkObjListPtr nets, const char *stateDir, virNetworkXMLOptionPtr xmlopt) { - DIR *dir; + g_autoptr(DIR) dir =3D NULL; struct dirent *entry; int ret =3D -1; int rc; @@ -1097,7 +1097,6 @@ virNetworkObjLoadAllState(virNetworkObjListPtr nets, } =20 cleanup: - VIR_DIR_CLOSE(dir); return ret; } =20 @@ -1108,7 +1107,7 @@ virNetworkObjLoadAllConfigs(virNetworkObjListPtr nets, const char *autostartDir, virNetworkXMLOptionPtr xmlopt) { - DIR *dir; + g_autoptr(DIR) dir =3D NULL; struct dirent *entry; int ret =3D -1; int rc; @@ -1132,7 +1131,6 @@ virNetworkObjLoadAllConfigs(virNetworkObjListPtr nets, virNetworkObjEndAPI(&obj); } =20 - VIR_DIR_CLOSE(dir); return ret; } =20 @@ -1707,7 +1705,7 @@ virNetworkObjDeleteAllPorts(virNetworkObjPtr net, const char *stateDir) { g_autofree char *dir =3D NULL; - DIR *dh =3D NULL; + g_autoptr(DIR) dh =3D NULL; struct dirent *de; int rc; int ret =3D -1; @@ -1738,7 +1736,6 @@ virNetworkObjDeleteAllPorts(virNetworkObjPtr net, =20 ret =3D 0; cleanup: - VIR_DIR_CLOSE(dh); return ret; } =20 @@ -1863,7 +1860,7 @@ virNetworkObjLoadAllPorts(virNetworkObjPtr net, const char *stateDir) { g_autofree char *dir =3D NULL; - DIR *dh =3D NULL; + g_autoptr(DIR) dh =3D NULL; struct dirent *de; int ret =3D -1; int rc; @@ -1901,6 +1898,5 @@ virNetworkObjLoadAllPorts(virNetworkObjPtr net, =20 ret =3D 0; cleanup: - VIR_DIR_CLOSE(dh); return ret; } diff --git a/src/conf/virnwfilterbindingobjlist.c b/src/conf/virnwfilterbin= dingobjlist.c index 4cbb62abfa..194348d062 100644 --- a/src/conf/virnwfilterbindingobjlist.c +++ b/src/conf/virnwfilterbindingobjlist.c @@ -300,7 +300,7 @@ int virNWFilterBindingObjListLoadAllConfigs(virNWFilterBindingObjListPtr bindi= ngs, const char *configDir) { - DIR *dir; + g_autoptr(DIR) dir =3D NULL; struct dirent *entry; int ret =3D -1; int rc; @@ -330,7 +330,6 @@ virNWFilterBindingObjListLoadAllConfigs(virNWFilterBind= ingObjListPtr bindings, VIR_ERROR(_("Failed to load config for binding '%s'"), entry->= d_name); } =20 - VIR_DIR_CLOSE(dir); virObjectRWUnlock(bindings); return ret; } diff --git a/src/conf/virnwfilterobj.c b/src/conf/virnwfilterobj.c index fce402f907..a6a5aa01c7 100644 --- a/src/conf/virnwfilterobj.c +++ b/src/conf/virnwfilterobj.c @@ -524,7 +524,7 @@ int virNWFilterObjListLoadAllConfigs(virNWFilterObjListPtr nwfilters, const char *configDir) { - DIR *dir; + g_autoptr(DIR) dir =3D NULL; struct dirent *entry; int ret =3D -1; int rc; @@ -543,7 +543,6 @@ virNWFilterObjListLoadAllConfigs(virNWFilterObjListPtr = nwfilters, virNWFilterObjUnlock(obj); } =20 - VIR_DIR_CLOSE(dir); return ret; } =20 diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 146210fbe7..fda3702415 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -896,7 +896,7 @@ int virSecretLoadAllConfigs(virSecretObjListPtr secrets, const char *configDir) { - DIR *dir =3D NULL; + g_autoptr(DIR) dir =3D NULL; struct dirent *de; int rc; =20 @@ -926,6 +926,5 @@ virSecretLoadAllConfigs(virSecretObjListPtr secrets, virSecretObjEndAPI(&obj); } =20 - VIR_DIR_CLOSE(dir); return 0; } diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 219594582c..4aff62434f 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -1707,7 +1707,7 @@ int virStoragePoolObjLoadAllState(virStoragePoolObjListPtr pools, const char *stateDir) { - DIR *dir; + g_autoptr(DIR) dir =3D NULL; struct dirent *entry; int ret =3D -1; int rc; @@ -1726,7 +1726,6 @@ virStoragePoolObjLoadAllState(virStoragePoolObjListPt= r pools, virStoragePoolObjEndAPI(&obj); } =20 - VIR_DIR_CLOSE(dir); return ret; } =20 @@ -1736,7 +1735,7 @@ virStoragePoolObjLoadAllConfigs(virStoragePoolObjList= Ptr pools, const char *configDir, const char *autostartDir) { - DIR *dir; + g_autoptr(DIR) dir =3D NULL; struct dirent *entry; int ret; int rc; @@ -1768,7 +1767,6 @@ virStoragePoolObjLoadAllConfigs(virStoragePoolObjList= Ptr pools, VIR_FREE(autostartLink); } =20 - VIR_DIR_CLOSE(dir); return ret; } =20 diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 8f1740863c..1783dce233 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -1003,7 +1003,7 @@ openvzSetUUID(int vpsid) =20 static int openvzAssignUUIDs(void) { - DIR *dp; + g_autoptr(DIR) dp =3D NULL; struct dirent *dent; char *conf_dir; int vpsid; @@ -1028,7 +1028,6 @@ static int openvzAssignUUIDs(void) openvzSetUUID(vpsid); } =20 - VIR_DIR_CLOSE(dp); VIR_FREE(conf_dir); return ret; } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f1191c1210..cb56fbbfcf 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -357,7 +357,7 @@ qemuDomainSnapshotLoad(virDomainObjPtr vm, { char *baseDir =3D (char *)data; g_autofree char *snapDir =3D NULL; - DIR *dir =3D NULL; + g_autoptr(DIR) dir =3D NULL; struct dirent *entry; virDomainSnapshotDefPtr def =3D NULL; virDomainMomentObjPtr snap =3D NULL; @@ -457,7 +457,6 @@ qemuDomainSnapshotLoad(virDomainObjPtr vm, =20 ret =3D 0; cleanup: - VIR_DIR_CLOSE(dir); virObjectUnlock(vm); return ret; } @@ -469,7 +468,7 @@ qemuDomainCheckpointLoad(virDomainObjPtr vm, { char *baseDir =3D (char *)data; g_autofree char *chkDir =3D NULL; - DIR *dir =3D NULL; + g_autoptr(DIR) dir =3D NULL; struct dirent *entry; virDomainCheckpointDefPtr def =3D NULL; virDomainMomentObjPtr chk =3D NULL; @@ -557,7 +556,6 @@ qemuDomainCheckpointLoad(virDomainObjPtr vm, =20 ret =3D 0; cleanup: - VIR_DIR_CLOSE(dir); virObjectUnlock(vm); return ret; } diff --git a/src/qemu/qemu_interop_config.c b/src/qemu/qemu_interop_config.c index 7edca7540a..f2d83eae93 100644 --- a/src/qemu/qemu_interop_config.c +++ b/src/qemu/qemu_interop_config.c @@ -37,7 +37,7 @@ VIR_LOG_INIT("qemu.qemu_configs"); static int qemuBuildFileList(virHashTablePtr files, const char *dir) { - DIR *dirp; + g_autoptr(DIR) dirp =3D NULL; struct dirent *ent =3D NULL; int rc; int ret =3D -1; @@ -79,7 +79,6 @@ qemuBuildFileList(virHashTablePtr files, const char *dir) =20 ret =3D 0; cleanup: - VIR_DIR_CLOSE(dirp); return ret; } =20 diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 7d9e62a239..6681ce194b 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -3464,7 +3464,7 @@ virSecuritySELinuxSetFileLabels(virSecurityManagerPtr= mgr, int ret =3D 0; struct dirent *ent; char *filename =3D NULL; - DIR *dir; + g_autoptr(DIR) dir =3D NULL; =20 if ((ret =3D virSecuritySELinuxSetFilecon(mgr, path, seclabel->imagela= bel, true))) return ret; @@ -3487,7 +3487,6 @@ virSecuritySELinuxSetFileLabels(virSecurityManagerPtr= mgr, virReportSystemError(errno, _("Unable to label files under %s"), path); =20 - VIR_DIR_CLOSE(dir); return ret; } =20 @@ -3509,7 +3508,7 @@ virSecuritySELinuxRestoreFileLabels(virSecurityManage= rPtr mgr, int ret =3D 0; struct dirent *ent; char *filename =3D NULL; - DIR *dir; + g_autoptr(DIR) dir =3D NULL; =20 if ((ret =3D virSecuritySELinuxRestoreFileLabel(mgr, path, true))) return ret; @@ -3531,7 +3530,6 @@ virSecuritySELinuxRestoreFileLabels(virSecurityManage= rPtr mgr, virReportSystemError(errno, _("Unable to restore file labels under= %s"), path); =20 - VIR_DIR_CLOSE(dir); return ret; } =20 diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_back= end_iscsi.c index 436d5e09c7..45167e4490 100644 --- a/src/storage/storage_backend_iscsi.c +++ b/src/storage/storage_backend_iscsi.c @@ -90,7 +90,7 @@ virStorageBackendISCSIGetHostNumber(const char *sysfs_pat= h, uint32_t *host) { int ret =3D -1; - DIR *sysdir =3D NULL; + g_autoptr(DIR) sysdir =3D NULL; struct dirent *dirent =3D NULL; int direrr; =20 @@ -122,7 +122,6 @@ virStorageBackendISCSIGetHostNumber(const char *sysfs_p= ath, } =20 cleanup: - VIR_DIR_CLOSE(sysdir); return ret; } =20 diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 7eaf899883..5a5e517b15 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -1920,7 +1920,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool, bool loop) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - DIR *dh; + g_autoptr(DIR) dh =3D NULL; struct dirent *dent; char *stablepath; int opentries =3D 0; @@ -1963,7 +1963,6 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool, stablepath =3D g_strdup_printf("%s/%s", def->target.path, dent->d_= name); =20 if (virFileLinkPointsTo(stablepath, devpath)) { - VIR_DIR_CLOSE(dh); return stablepath; } =20 @@ -1975,8 +1974,6 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool, goto retry; } =20 - VIR_DIR_CLOSE(dh); - ret_strdup: /* Couldn't find any matching stable link so give back * the original non-stable dev path @@ -3505,7 +3502,7 @@ int virStorageBackendRefreshLocal(virStoragePoolObjPtr pool) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - DIR *dir; + g_autoptr(DIR) dir =3D NULL; struct dirent *ent; struct statvfs sb; struct stat statbuf; @@ -3595,7 +3592,6 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr po= ol) =20 ret =3D 0; cleanup: - VIR_DIR_CLOSE(dir); return ret; } =20 @@ -3726,7 +3722,7 @@ getNewStyleBlockDevice(const char *lun_path, const char *block_name G_GNUC_UNUSED, char **block_device) { - DIR *block_dir =3D NULL; + g_autoptr(DIR) block_dir =3D NULL; struct dirent *block_dirent =3D NULL; int retval =3D -1; int direrr; @@ -3753,7 +3749,6 @@ getNewStyleBlockDevice(const char *lun_path, retval =3D 0; =20 cleanup: - VIR_DIR_CLOSE(block_dir); return retval; } =20 @@ -3799,7 +3794,7 @@ getBlockDevice(uint32_t host, uint32_t lun, char **block_device) { - DIR *lun_dir =3D NULL; + g_autoptr(DIR) lun_dir =3D NULL; struct dirent *lun_dirent =3D NULL; int retval =3D -1; int direrr; @@ -3839,7 +3834,6 @@ getBlockDevice(uint32_t host, retval =3D 0; =20 cleanup: - VIR_DIR_CLOSE(lun_dir); return retval; } =20 @@ -3968,7 +3962,7 @@ virStorageBackendSCSIFindLUs(virStoragePoolObjPtr poo= l, int retval =3D 0; uint32_t bus, target, lun; const char *device_path =3D "/sys/bus/scsi/devices"; - DIR *devicedir =3D NULL; + g_autoptr(DIR) devicedir =3D NULL; struct dirent *lun_dirent =3D NULL; char devicepattern[64]; int found =3D 0; @@ -4001,8 +3995,6 @@ virStorageBackendSCSIFindLUs(virStoragePoolObjPtr poo= l, found++; } =20 - VIR_DIR_CLOSE(devicedir); - if (retval < 0) return -1; =20 diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index b1caf11f47..6ba030bf9b 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -2303,7 +2303,7 @@ virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, ch= ar **usage) int virCgroupRemoveRecursively(char *grppath) { - DIR *grpdir; + g_autoptr(DIR) grpdir =3D NULL; struct dirent *ent; int rc =3D 0; int direrr; @@ -2334,8 +2334,6 @@ virCgroupRemoveRecursively(char *grppath) VIR_ERROR(_("Failed to readdir for %s (%d)"), grppath, errno); } =20 - VIR_DIR_CLOSE(grpdir); - VIR_DEBUG("Removing cgroup %s", grppath); if (rmdir(grppath) !=3D 0 && errno !=3D ENOENT) { rc =3D -errno; @@ -2471,7 +2469,7 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, int rc; bool killedAny =3D false; g_autofree char *keypath =3D NULL; - DIR *dp =3D NULL; + g_autoptr(DIR) dp =3D NULL; struct dirent *ent; int direrr; VIR_DEBUG("group=3D%p path=3D%s signum=3D%d pids=3D%p", @@ -2524,7 +2522,6 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, ret =3D killedAny ? 1 : 0; =20 cleanup: - VIR_DIR_CLOSE(dp); return ret; } =20 diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 67b35c1b9a..61fb359f8d 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -880,7 +880,7 @@ virCgroupV1SetOwner(virCgroupPtr cgroup, for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { g_autofree char *base =3D NULL; struct dirent *de; - DIR *dh =3D NULL; + g_autoptr(DIR) dh =3D NULL; =20 if (!((1 << i) & controllers)) continue; @@ -915,8 +915,6 @@ virCgroupV1SetOwner(virCgroupPtr cgroup, base, uid, gid); goto cleanup; } - - VIR_DIR_CLOSE(dh); } =20 ret =3D 0; diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 6350e77523..5ae2ad9ef9 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -452,7 +452,7 @@ static int virCommandMassCloseGetFDsLinux(virCommandPtr cmd G_GNUC_UNUSED, virBitmapPtr fds) { - DIR *dp =3D NULL; + g_autoptr(DIR) dp =3D NULL; struct dirent *entry; const char *dirName =3D "/proc/self/fd"; int rc; @@ -479,7 +479,6 @@ virCommandMassCloseGetFDsLinux(virCommandPtr cmd G_GNUC= _UNUSED, =20 ret =3D 0; cleanup: - VIR_DIR_CLOSE(dp); return ret; } =20 diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c index f26d36832a..323102d36e 100644 --- a/src/util/virdevmapper.c +++ b/src/util/virdevmapper.c @@ -169,7 +169,7 @@ virDMSanitizepath(const char *path) g_autofree char *dmDirPath =3D NULL; struct dirent *ent =3D NULL; struct stat sb[2]; - DIR *dh =3D NULL; + g_autoptr(DIR) dh =3D NULL; const char *p; char *ret =3D NULL; =20 @@ -211,7 +211,6 @@ virDMSanitizepath(const char *path) } } =20 - VIR_DIR_CLOSE(dh); return ret; } =20 diff --git a/src/util/virfile.c b/src/util/virfile.c index 442d2fab96..fc0021036a 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -669,7 +669,7 @@ static int virFileLoopDeviceOpenLoopCtl(char **dev_name= , int *fd) static int virFileLoopDeviceOpenSearch(char **dev_name) { int fd =3D -1; - DIR *dh =3D NULL; + g_autoptr(DIR) dh =3D NULL; struct dirent *de; char *looppath =3D NULL; struct loop_info64 lo; @@ -726,7 +726,6 @@ static int virFileLoopDeviceOpenSearch(char **dev_name) VIR_DEBUG("No free loop devices available"); VIR_FREE(looppath); } - VIR_DIR_CLOSE(dh); return fd; } =20 @@ -836,7 +835,7 @@ virFileNBDDeviceIsBusy(const char *dev_name) static char * virFileNBDDeviceFindUnused(void) { - DIR *dh; + g_autoptr(DIR) dh =3D NULL; char *ret =3D NULL; struct dirent *de; int direrr; @@ -861,7 +860,6 @@ virFileNBDDeviceFindUnused(void) _("No free NBD devices")); =20 cleanup: - VIR_DIR_CLOSE(dh); return ret; } =20 @@ -979,7 +977,7 @@ int virFileNBDDeviceAssociate(const char *file, */ int virFileDeleteTree(const char *dir) { - DIR *dh; + g_autoptr(DIR) dh =3D NULL; struct dirent *de; int ret =3D -1; int direrr; @@ -1028,7 +1026,6 @@ int virFileDeleteTree(const char *dir) ret =3D 0; =20 cleanup: - VIR_DIR_CLOSE(dh); return ret; } =20 @@ -2954,7 +2951,7 @@ int virFileChownFiles(const char *name, struct dirent *ent; int ret =3D -1; int direrr; - DIR *dir; + g_autoptr(DIR) dir =3D NULL; =20 if (virDirOpen(&dir, name) < 0) return -1; @@ -2982,7 +2979,6 @@ int virFileChownFiles(const char *name, ret =3D 0; =20 cleanup: - VIR_DIR_CLOSE(dir); return ret; } =20 diff --git a/src/util/virhook.c b/src/util/virhook.c index 119ad1aae6..aad3e667d3 100644 --- a/src/util/virhook.c +++ b/src/util/virhook.c @@ -143,7 +143,7 @@ static int virHookCheck(int no, const char *driver) { int ret; - DIR *dir; + g_autoptr(DIR) dir =3D NULL; struct dirent *entry; g_autofree char *path =3D NULL; g_autofree char *dir_path =3D NULL; @@ -199,8 +199,6 @@ virHookCheck(int no, const char *driver) break; } =20 - VIR_DIR_CLOSE(dir); - return ret; } =20 @@ -341,7 +339,7 @@ virHookCall(int driver, char **output) { int ret, script_ret; - DIR *dir; + g_autoptr(DIR) dir =3D NULL; struct dirent *entry; g_autofree char *path =3D NULL; g_autofree char *dir_path =3D NULL; @@ -438,8 +436,6 @@ virHookCall(int driver, virStringListAdd(&entries, entry_path); } =20 - VIR_DIR_CLOSE(dir); - if (ret < 0) return -1; =20 diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index 4ae4dca067..c531d65f86 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -308,7 +308,7 @@ virHostCPUParseNode(const char *node, { int ret =3D -1; int processors =3D 0; - DIR *cpudir =3D NULL; + g_autoptr(DIR) cpudir =3D NULL; struct dirent *cpudirent =3D NULL; virBitmapPtr node_cpus_map =3D NULL; virBitmapPtr sockets_map =3D NULL; @@ -443,7 +443,6 @@ virHostCPUParseNode(const char *node, ret =3D processors; =20 cleanup: - VIR_DIR_CLOSE(cpudir); if (cores_maps) for (i =3D 0; i < sock_max; i++) virBitmapFree(cores_maps[i]); @@ -611,7 +610,7 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo, { virBitmapPtr present_cpus_map =3D NULL; virBitmapPtr online_cpus_map =3D NULL; - DIR *nodedir =3D NULL; + g_autoptr(DIR) nodedir =3D NULL; struct dirent *nodedirent =3D NULL; int nodecpus, nodecores, nodesockets, nodethreads, offline =3D 0; int threads_per_subcore =3D 0; @@ -772,7 +771,6 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo, ret =3D 0; =20 cleanup: - VIR_DIR_CLOSE(nodedir); virBitmapFree(present_cpus_map); virBitmapFree(online_cpus_map); VIR_FREE(sysfs_nodedir); diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 91b12fc131..256179c052 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -2898,7 +2898,7 @@ virNetDevRDMAFeature(const char *ifname, { g_autofree char *eth_devpath =3D NULL; g_autofree char *eth_res_buf =3D NULL; - DIR *dirp =3D NULL; + g_autoptr(DIR) dirp =3D NULL; struct dirent *dp; int ret =3D -1; =20 @@ -2934,7 +2934,6 @@ virNetDevRDMAFeature(const char *ifname, ret =3D 0; =20 cleanup: - VIR_DIR_CLOSE(dirp); return ret; } =20 diff --git a/src/util/virnuma.c b/src/util/virnuma.c index 5d40d13977..51a5d6e8a6 100644 --- a/src/util/virnuma.c +++ b/src/util/virnuma.c @@ -740,7 +740,7 @@ virNumaGetPages(int node, size_t *npages) { int ret =3D -1; - DIR *dir =3D NULL; + g_autoptr(DIR) dir =3D NULL; int direrr =3D 0; struct dirent *entry; unsigned int ntmp =3D 0; @@ -854,7 +854,6 @@ virNumaGetPages(int node, *npages =3D ntmp; ret =3D 0; cleanup: - VIR_DIR_CLOSE(dir); return ret; } =20 diff --git a/src/util/virpci.c b/src/util/virpci.c index 1f679a7b45..b44208e05a 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -432,7 +432,7 @@ virPCIDeviceIterDevices(virPCIDeviceIterPredicate predi= cate, virPCIDevicePtr *matched, void *data) { - DIR *dir; + g_autoptr(DIR) dir =3D NULL; struct dirent *entry; int ret =3D 0; int rc; @@ -480,7 +480,6 @@ virPCIDeviceIterDevices(virPCIDeviceIterPredicate predi= cate, break; } } - VIR_DIR_CLOSE(dir); return ret; } =20 @@ -1706,7 +1705,7 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev, void *opaque) { g_autofree char *pcidir =3D NULL; - DIR *dir =3D NULL; + g_autoptr(DIR) dir =3D NULL; int ret =3D -1; struct dirent *ent; int direrr; @@ -1741,7 +1740,6 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev, ret =3D 0; =20 cleanup: - VIR_DIR_CLOSE(dir); return ret; } =20 @@ -1757,7 +1755,7 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddr= essPtr orig, void *opaque) { g_autofree char *groupPath =3D NULL; - DIR *groupDir =3D NULL; + g_autoptr(DIR) groupDir =3D NULL; int ret =3D -1; struct dirent *ent; int direrr; @@ -1790,7 +1788,6 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddr= essPtr orig, ret =3D 0; =20 cleanup: - VIR_DIR_CLOSE(groupDir); return ret; } =20 @@ -2388,7 +2385,7 @@ virPCIGetNetName(const char *device_link_sysfs_path, g_autofree char *pcidev_sysfs_net_path =3D NULL; g_autofree char *firstEntryName =3D NULL; int ret =3D -1; - DIR *dir =3D NULL; + g_autoptr(DIR) dir =3D NULL; struct dirent *entry =3D NULL; size_t i =3D 0; =20 @@ -2461,7 +2458,6 @@ virPCIGetNetName(const char *device_link_sysfs_path, } } cleanup: - VIR_DIR_CLOSE(dir); return ret; } =20 @@ -2535,7 +2531,7 @@ virPCIGetMdevTypes(const char *sysfspath, { ssize_t ret =3D -1; int dirret =3D -1; - DIR *dir =3D NULL; + g_autoptr(DIR) dir =3D NULL; struct dirent *entry; g_autofree char *types_path =3D NULL; g_autoptr(virMediatedDeviceType) mdev_type =3D NULL; @@ -2575,7 +2571,6 @@ virPCIGetMdevTypes(const char *sysfspath, for (i =3D 0; i < ntypes; i++) virMediatedDeviceTypeFree(mdev_types[i]); VIR_FREE(mdev_types); - VIR_DIR_CLOSE(dir); return ret; } =20 diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 37413796b3..dccfc2558e 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -616,7 +616,7 @@ virProcessGetAffinity(pid_t pid G_GNUC_UNUSED) int virProcessGetPids(pid_t pid, size_t *npids, pid_t **pids) { int ret =3D -1; - DIR *dir =3D NULL; + g_autoptr(DIR) dir =3D NULL; int value; struct dirent *ent; g_autofree char *taskPath =3D NULL; @@ -647,7 +647,6 @@ int virProcessGetPids(pid_t pid, size_t *npids, pid_t *= *pids) ret =3D 0; =20 cleanup: - VIR_DIR_CLOSE(dir); if (ret < 0) VIR_FREE(*pids); return ret; diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 400c8e9981..aa466592fc 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -781,7 +781,7 @@ virResctrlGetMonitorInfo(virResctrlInfoPtr resctrl) static int virResctrlGetInfo(virResctrlInfoPtr resctrl) { - DIR *dirp =3D NULL; + g_autoptr(DIR) dirp =3D NULL; int ret =3D -1; =20 ret =3D virDirOpenIfExists(&dirp, SYSFS_RESCTRL_PATH "/info"); @@ -802,7 +802,6 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl) =20 ret =3D 0; cleanup: - VIR_DIR_CLOSE(dirp); return ret; } =20 @@ -1900,7 +1899,7 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl) virResctrlAllocPtr ret =3D NULL; virResctrlAllocPtr alloc =3D NULL; struct dirent *ent =3D NULL; - DIR *dirp =3D NULL; + g_autoptr(DIR) dirp =3D NULL; int rv =3D -1; =20 if (virResctrlInfoIsEmpty(resctrl)) { @@ -1947,7 +1946,6 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl) =20 cleanup: virObjectUnref(alloc); - VIR_DIR_CLOSE(dirp); return ret; =20 error: @@ -2663,7 +2661,7 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monito= r, int ret =3D -1; size_t i =3D 0; unsigned long long val =3D 0; - DIR *dirp =3D NULL; + g_autoptr(DIR) dirp =3D NULL; char *datapath =3D NULL; char *filepath =3D NULL; struct dirent *ent =3D NULL; @@ -2747,7 +2745,6 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monito= r, VIR_FREE(datapath); VIR_FREE(filepath); virResctrlMonitorStatsFree(stat); - VIR_DIR_CLOSE(dirp); return ret; } =20 diff --git a/src/util/virscsi.c b/src/util/virscsi.c index 4dcd68d53a..256acc37fa 100644 --- a/src/util/virscsi.c +++ b/src/util/virscsi.c @@ -106,7 +106,7 @@ virSCSIDeviceGetSgName(const char *sysfs_prefix, unsigned int target, unsigned long long unit) { - DIR *dir =3D NULL; + g_autoptr(DIR) dir =3D NULL; struct dirent *entry; g_autofree char *path =3D NULL; char *sg =3D NULL; @@ -129,7 +129,6 @@ virSCSIDeviceGetSgName(const char *sysfs_prefix, } =20 cleanup: - VIR_DIR_CLOSE(dir); return sg; } =20 @@ -143,7 +142,7 @@ virSCSIDeviceGetDevName(const char *sysfs_prefix, unsigned int target, unsigned long long unit) { - DIR *dir =3D NULL; + g_autoptr(DIR) dir =3D NULL; struct dirent *entry; g_autofree char *path =3D NULL; char *name =3D NULL; @@ -165,7 +164,6 @@ virSCSIDeviceGetDevName(const char *sysfs_prefix, } =20 cleanup: - VIR_DIR_CLOSE(dir); return name; } =20 diff --git a/src/util/virscsihost.c b/src/util/virscsihost.c index 7d8e5299b8..c259e63000 100644 --- a/src/util/virscsihost.c +++ b/src/util/virscsihost.c @@ -100,7 +100,7 @@ virSCSIHostFindByPCI(const char *sysfs_prefix, { const char *prefix =3D sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_HOST_P= ATH; struct dirent *entry =3D NULL; - DIR *dir =3D NULL; + g_autoptr(DIR) dir =3D NULL; char *host_link =3D NULL; char *host_path =3D NULL; char *p =3D NULL; @@ -157,7 +157,6 @@ virSCSIHostFindByPCI(const char *sysfs_prefix, } =20 cleanup: - VIR_DIR_CLOSE(dir); VIR_FREE(unique_path); VIR_FREE(host_link); VIR_FREE(host_path); diff --git a/src/util/virusb.c b/src/util/virusb.c index 3e7e4281a3..a8afd6e6f0 100644 --- a/src/util/virusb.c +++ b/src/util/virusb.c @@ -110,7 +110,7 @@ virUSBDeviceSearch(unsigned int vendor, const char *vroot, unsigned int flags) { - DIR *dir =3D NULL; + g_autoptr(DIR) dir =3D NULL; bool found =3D false; char *ignore =3D NULL; struct dirent *de; @@ -180,7 +180,6 @@ virUSBDeviceSearch(unsigned int vendor, ret =3D list; =20 cleanup: - VIR_DIR_CLOSE(dir); if (!ret) virObjectUnref(list); return ret; diff --git a/src/util/virutil.c b/src/util/virutil.c index 708c3cf9ef..41e92023fc 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1621,7 +1621,7 @@ virMemoryMaxValue(bool capped) bool virHostHasIOMMU(void) { - DIR *iommuDir =3D NULL; + g_autoptr(DIR) iommuDir =3D NULL; struct dirent *iommuGroup =3D NULL; bool ret =3D false; int direrr; @@ -1638,7 +1638,6 @@ virHostHasIOMMU(void) ret =3D true; =20 cleanup: - VIR_DIR_CLOSE(iommuDir); return ret; } =20 @@ -1658,7 +1657,7 @@ char * virHostGetDRMRenderNode(void) { char *ret =3D NULL; - DIR *driDir =3D NULL; + g_autoptr(DIR) driDir =3D NULL; const char *driPath =3D "/dev/dri"; struct dirent *ent =3D NULL; int dirErr =3D 0; @@ -1687,7 +1686,6 @@ virHostGetDRMRenderNode(void) ret =3D g_strdup_printf("%s/%s", driPath, ent->d_name); =20 cleanup: - VIR_DIR_CLOSE(driDir); return ret; } =20 diff --git a/src/util/virvhba.c b/src/util/virvhba.c index df0691a658..471d94d3dd 100644 --- a/src/util/virvhba.c +++ b/src/util/virvhba.c @@ -158,7 +158,7 @@ char * virVHBAFindVportHost(const char *sysfs_prefix) { const char *prefix =3D sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PAT= H; - DIR *dir =3D NULL; + g_autoptr(DIR) dir =3D NULL; struct dirent *entry =3D NULL; char *max_vports =3D NULL; char *vports =3D NULL; @@ -220,7 +220,6 @@ virVHBAFindVportHost(const char *sysfs_prefix) } =20 cleanup: - VIR_DIR_CLOSE(dir); VIR_FREE(max_vports); VIR_FREE(vports); return ret; @@ -365,7 +364,7 @@ virVHBAGetHostByWWN(const char *sysfs_prefix, { const char *prefix =3D sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PAT= H; struct dirent *entry =3D NULL; - DIR *dir =3D NULL; + g_autoptr(DIR) dir =3D NULL; char *ret =3D NULL; =20 if (virDirOpen(&dir, prefix) < 0) @@ -393,7 +392,6 @@ virVHBAGetHostByWWN(const char *sysfs_prefix, } =20 cleanup: - VIR_DIR_CLOSE(dir); return ret; } =20 @@ -411,7 +409,7 @@ virVHBAGetHostByFabricWWN(const char *sysfs_prefix, { const char *prefix =3D sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PAT= H; struct dirent *entry =3D NULL; - DIR *dir =3D NULL; + g_autoptr(DIR) dir =3D NULL; char *vport_create_path =3D NULL; char *ret =3D NULL; =20 @@ -443,7 +441,6 @@ virVHBAGetHostByFabricWWN(const char *sysfs_prefix, } =20 cleanup: - VIR_DIR_CLOSE(dir); VIR_FREE(vport_create_path); return ret; } diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 278587767f..5ae1d64337 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -510,7 +510,7 @@ testQemuGetLatestCapsForArch(const char *arch, const char *suffix) { struct dirent *ent; - DIR *dir =3D NULL; + g_autoptr(DIR) dir =3D NULL; int rc; g_autofree char *fullsuffix =3D NULL; unsigned long maxver =3D 0; @@ -558,7 +558,6 @@ testQemuGetLatestCapsForArch(const char *arch, ret =3D g_strdup_printf("%s/%s", TEST_QEMU_CAPS_PATH, maxname); =20 cleanup: - VIR_DIR_CLOSE(dir); return ret; } =20 @@ -606,7 +605,7 @@ testQemuCapsIterate(const char *suffix, void *opaque) { struct dirent *ent; - DIR *dir =3D NULL; + g_autoptr(DIR) dir =3D NULL; int rc; int ret =3D -1; bool fail =3D false; @@ -667,7 +666,6 @@ testQemuCapsIterate(const char *suffix, ret =3D 0; =20 cleanup: - VIR_DIR_CLOSE(dir); return ret; } =20 diff --git a/tests/virschematest.c b/tests/virschematest.c index 0e587c3ff0..9a947f61f2 100644 --- a/tests/virschematest.c +++ b/tests/virschematest.c @@ -86,7 +86,7 @@ testSchemaDir(const char *schema, const char *dir_path, const char *filterstr) { - DIR *dir =3D NULL; + g_autoptr(DIR) dir =3D NULL; struct dirent *ent; int ret =3D 0; int rc; @@ -128,7 +128,6 @@ testSchemaDir(const char *schema, ret =3D -1; } =20 - VIR_DIR_CLOSE(dir); return ret; } =20 diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-c= ommon.c index 61284ae4da..a10ac03293 100644 --- a/tools/virt-host-validate-common.c +++ b/tools/virt-host-validate-common.c @@ -374,7 +374,7 @@ int virHostValidateIOMMU(const char *hvname, } else if (ARCH_IS_PPC64(arch)) { /* Empty Block */ } else if (ARCH_IS_S390(arch)) { - DIR *dir; + g_autoptr(DIR) dir =3D NULL; =20 /* On s390x, we skip the IOMMU check if there are no PCI * devices (which is quite usual on s390x). If there are @@ -383,7 +383,6 @@ int virHostValidateIOMMU(const char *hvname, if (!virDirOpen(&dir, "/sys/bus/pci/devices")) return 0; rc =3D virDirRead(dir, &dent, NULL); - VIR_DIR_CLOSE(dir); if (rc <=3D 0) return 0; } else { --=20 2.26.2 From nobody Mon May 6 03:50:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1603849006; cv=none; d=zohomail.com; s=zohoarc; b=VhrreoZnweubR19oyfBTtZgSLCMCWMxanJGlWvps0KIIb9fl1xlorIItVqE0kqERqXfWok2ayoO9Wh1MD5QWbfOUcnbMkld3KRtnSXloNdAqg6dAnREHQ7yVhh4M5Vg8nJatpgrQHT1DQlS6iFywxXzkOBh2Q3r6MbPZ0oCCILQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603849006; 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; bh=zKHDXxI9YqoGl25WcGRHrELmnqvhxyAR7hPmEecJ3DE=; b=TBi9gonAzgX8+uyLkESHYBvSbAlVQjfiODewNTXcCgtEmb91MlTUB9qQdqisEpDZZ1DVeme85ewJwgNbM6OQ3gcz3ShVH4W0kNzxI/TJHEJzOaZ6UUrSHLlIQMlwHChfq1TaonRWBFX6GpeiJdx8yW6yTf5LbrUDG3PVMuluEbY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 160384900644712.19199899478292; Tue, 27 Oct 2020 18:36:46 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-340-yb38IspuMfyAt4-x6Ocj9Q-1; Tue, 27 Oct 2020 21:36:43 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6300B760CE; Wed, 28 Oct 2020 01:36:34 +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 435815B4C1; Wed, 28 Oct 2020 01:36:34 +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 134F9CF5F; Wed, 28 Oct 2020 01:36:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 09S1aDXL028301 for ; Tue, 27 Oct 2020 21:36:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 67CBA5C1DC; Wed, 28 Oct 2020 01:36:13 +0000 (UTC) Received: from vhost2.laine.org (ovpn-113-144.phx2.redhat.com [10.3.113.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id B09165C22A for ; Wed, 28 Oct 2020 01:36:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603849005; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=zKHDXxI9YqoGl25WcGRHrELmnqvhxyAR7hPmEecJ3DE=; b=Yxty+iGYobKB+WeR40PQANJGLFxEinYUy+1chlj1NqA77Rr+Ch3RrCEMdhGTb59EsIms2E RzS73Iqh39OpSIQ9/NyhElqN7hGcrw2IoKbwuljh0/XeKEYXvMYTcrY+U9x4pLziVUm21n CCeroi45kp76u+UjscA/Db9ZCcL6MAs= X-MC-Unique: yb38IspuMfyAt4-x6Ocj9Q-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 09/12] conf: convert final DIR* to g_autoptr Date: Tue, 27 Oct 2020 21:35:55 -0400 Message-Id: <20201028013558.424925-10-laine@redhat.com> In-Reply-To: <20201028013558.424925-1-laine@redhat.com> References: <20201028013558.424925-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This use of DIR* was re-using the same function-scope DIR* each time through a for loop, and due to multiple error gotos in the loop, it needed to have the scope of the DIR* reduced to just the loop at the same time as switching to g_autoptr. That's what this patch does. Signed-off-by: Laine Stump Reviewed-by: Daniel Henrique Barboza --- src/conf/capabilities.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 18b2612d2e..425f34113a 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -1837,7 +1837,6 @@ virCapabilitiesInitCaches(virCapsPtr caps) size_t i =3D 0; virBitmapPtr cpus =3D NULL; ssize_t pos =3D -1; - DIR *dirp =3D NULL; int ret =3D -1; char *path =3D NULL; char *type =3D NULL; @@ -1860,13 +1859,11 @@ virCapabilitiesInitCaches(virCapsPtr caps) =20 while ((pos =3D virBitmapNextSetBit(cpus, pos)) >=3D 0) { int rv =3D -1; + g_autoptr(DIR) dirp =3D NULL; =20 VIR_FREE(path); path =3D g_strdup_printf("%s/cpu/cpu%zd/cache/", SYSFS_SYSTEM_PATH= , pos); =20 - VIR_DIR_CLOSE(dirp); - dirp =3D NULL; - rv =3D virDirOpenIfExists(&dirp, path); if (rv < 0) goto cleanup; @@ -1971,7 +1968,6 @@ virCapabilitiesInitCaches(virCapsPtr caps) cleanup: VIR_FREE(type); VIR_FREE(path); - VIR_DIR_CLOSE(dirp); virCapsHostCacheBankFree(bank); virBitmapFree(cpus); return ret; --=20 2.26.2 From nobody Mon May 6 03:50:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1603849005; cv=none; d=zohomail.com; s=zohoarc; b=L+QFpO+hzNQ339OyDZ1Mel6sQbBuHPgjbv2s+4v4JBhm4ScsHL4TcutNUqQUIOFLcGDzPOoNvW5btE2QVCp9uIdbVW2E26o29tmoV+ukK0NQirDm8j+VNSG4ssY2u/xenSlnZ8Mvf/iAoCbJ3ZapIubfWR2nwgrvYSu6ANrKZkw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603849005; 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; bh=C4me0R6jD5gRBRSXqsucknRVb05gu/Rccxd/A2R57M8=; b=JDx+oYQ21fpRT0d2WDBe5tU+Sfr6N7l5vDZh2CP436v/ZP1IbbhcvyfYhbhtSK7Yy5PxbX0YjqgIkHwiciCUZ71GXnVpZDMiQK4NHCzNAW+ju2sd0GKD4s/lJ3CDylW3Rf3m2eSQ13IV0HRvPUhxrOs5c3pkCCMQkoDy1IdsIR4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1603849005700200.392109716361; Tue, 27 Oct 2020 18:36:45 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-274-Z-4vKWhIOna_sJGqvyuZTg-1; Tue, 27 Oct 2020 21:36:41 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 25A6C8030A2; Wed, 28 Oct 2020 01:36:31 +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 01EDC6EF53; Wed, 28 Oct 2020 01:36:31 +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 C109D181A894; Wed, 28 Oct 2020 01:36:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 09S1aDG1028311 for ; Tue, 27 Oct 2020 21:36:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id CDCAB5C1DC; Wed, 28 Oct 2020 01:36:13 +0000 (UTC) Received: from vhost2.laine.org (ovpn-113-144.phx2.redhat.com [10.3.113.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EDCE5C1C5 for ; Wed, 28 Oct 2020 01:36:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603849004; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=C4me0R6jD5gRBRSXqsucknRVb05gu/Rccxd/A2R57M8=; b=ioznJWNp/2ZPNQq7eRGLUW0piCWppYi0Q2Z97KWqMXVSMk3++KdnfQ5+EpFg5+aLnN5L/r 7ysU7ohb8KdifjTG5zc8iJA9wzQCKp/32wNgDlFhlMjxqnv8mFRE+UQnPGcFDtfyRzoNsT qDTm7ZAc6nQS6ppkKcstZlCW9+PK56s= X-MC-Unique: Z-4vKWhIOna_sJGqvyuZTg-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 10/12] util: remove unused VIR_DIR_CLOSE() macro Date: Tue, 27 Oct 2020 21:35:56 -0400 Message-Id: <20201028013558.424925-11-laine@redhat.com> In-Reply-To: <20201028013558.424925-1-laine@redhat.com> References: <20201028013558.424925-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Since every single use of DIR* was converted to use g_autoptr, this function is not currently needed. Even if someone comes up with a usage for a non-g_autoptr DIR* in the future, they can just use virDirClose(), since there is no longer a semantic difference between the two (VIR_DIR_CLOSE() previously had an extra & on the pointer so that it could be transparently passed as a DIR** to virDirClose(), but that was removed several commits back.) Signed-off-by: Laine Stump Reviewed-by: Daniel Henrique Barboza --- src/util/virfile.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/util/virfile.h b/src/util/virfile.h index 6973fbd54a..ba31a78e58 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -272,7 +272,6 @@ int virDirRead(DIR *dirp, struct dirent **ent, const ch= ar *dirname) void virDirClose(DIR *dirp) ATTRIBUTE_NONNULL(1); G_DEFINE_AUTOPTR_CLEANUP_FUNC(DIR, virDirClose); -#define VIR_DIR_CLOSE(dir) virDirClose(dir) =20 int virFileMakePath(const char *path) G_GNUC_WARN_UNUSED_RESULT; int virFileMakePathWithMode(const char *path, --=20 2.26.2 From nobody Mon May 6 03:50:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1603849191; cv=none; d=zohomail.com; s=zohoarc; b=NH7NM5Tz4hGBxmvm6D8fgPIqGsSDxwZjdePyFWoWBiu5oKfLSMSxz33qlNTjq+uAJZyg4U37mNqLt+3we8+Qr4olPjRcESg5E/B/bYxC/5JweHbaVl/dydYPol7S0lGhmgns7Vh48vjsT51L5fN+yv5BGtA3TIxEgStty5RwUjY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603849191; 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; bh=MvrvKNcxSSw4IncpHxc7MqR1LmPV5qS0Jn4Vnc7DRjg=; b=DVHy3xixkhUcCS5EVZylZJ00UeaDxPoxDDPWOPl8OMDKLP6HkC0ChEmWNdO4GOOis0AkRZrtMxL3r6cCrtsfIZ460jL2CN2uyR1t2zo226f7MPb6AmhmaxlSRgFriMRDray+WizW1CPldd1p+ztXJyBuUr3PyeT/wubRxXJtRA8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1603849191518658.542589817963; Tue, 27 Oct 2020 18:39:51 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-559-uOpVzQAJPvGZYPOw0IlP0w-1; Tue, 27 Oct 2020 21:36:42 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6B841188C12B; Wed, 28 Oct 2020 01:36:34 +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 4632210002A6; Wed, 28 Oct 2020 01:36:34 +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 11104CF5E; Wed, 28 Oct 2020 01:36:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 09S1aEkG028316 for ; Tue, 27 Oct 2020 21:36:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3A7225C1DC; Wed, 28 Oct 2020 01:36:14 +0000 (UTC) Received: from vhost2.laine.org (ovpn-113-144.phx2.redhat.com [10.3.113.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id F25A05C1C5 for ; Wed, 28 Oct 2020 01:36:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603849190; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=MvrvKNcxSSw4IncpHxc7MqR1LmPV5qS0Jn4Vnc7DRjg=; b=ImPmmmlcWGZ24++yyIt5SMOLx3g3WEW1xKR82FTg83YWR5xLwdiD7GtoKLWneK+VuAkzQs SwDgNgpXuaYRG3uWNJfa5P02wMeL9DCt1bEW2wvYqZ912dDVVDAZRKeIujzaCOyiIY+t4M CuasKmXr+GQuPIlB/CKTKHeHy25ekkg= X-MC-Unique: uOpVzQAJPvGZYPOw0IlP0w-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 11/12] util: refactor function to simplify and remove label Date: Tue, 27 Oct 2020 21:35:57 -0400 Message-Id: <20201028013558.424925-12-laine@redhat.com> In-Reply-To: <20201028013558.424925-1-laine@redhat.com> References: <20201028013558.424925-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Once the DIR* in virPCIGetName() was made g_autoptr, the cleanup: label just had a "return ret;", but the rest of the function was more compilcated than it needed to be, doing funky things with the value of ret inside multi-level conditionals and a while loop that might exit early via a break with ret =3D=3D 0 or exit early via a goto cleanup with ret =3D=3D -1. It really didn't need to be nearly as complicated. After doing the trivial replacements of "goto cleanup" with appropriate direct returns, it became obvious that: 1) the outermost level of the nested conditional at the end of the function ("if (ret < 0)") was now redundant, since ret is now *always* < 0 by that point (otherwise the function has returned). 2) by switching the sense of the next level of the conditional (making it "if (!physPortID)", the "else" (which is now just "return 0;" becomes the "if", and the new "else" no longer needs to be inside the conditional. 3) the value of firstEntryName can be moved into *netname with g_steal_pointer() Once that is all done, ret is no longer used and can be removed. Signed-off-by: Laine Stump Reviewed-by: Daniel Henrique Barboza --- src/util/virpci.c | 49 +++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index b44208e05a..025eb9d91c 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -2384,7 +2384,6 @@ virPCIGetNetName(const char *device_link_sysfs_path, { g_autofree char *pcidev_sysfs_net_path =3D NULL; g_autofree char *firstEntryName =3D NULL; - int ret =3D -1; g_autoptr(DIR) dir =3D NULL; struct dirent *entry =3D NULL; size_t i =3D 0; @@ -2399,8 +2398,7 @@ virPCIGetNetName(const char *device_link_sysfs_path, =20 if (virDirOpenQuiet(&dir, pcidev_sysfs_net_path) < 0) { /* this *isn't* an error - caller needs to check for netname =3D= =3D NULL */ - ret =3D 0; - goto cleanup; + return 0; } =20 while (virDirRead(dir, &entry, pcidev_sysfs_net_path) > 0) { @@ -2411,7 +2409,7 @@ virPCIGetNetName(const char *device_link_sysfs_path, g_autofree char *thisPhysPortID =3D NULL; =20 if (virNetDevGetPhysPortID(entry->d_name, &thisPhysPortID) < 0) - goto cleanup; + return -1; =20 /* if this one doesn't match, keep looking */ if (STRNEQ_NULLABLE(physPortID, thisPhysPortID)) { @@ -2431,34 +2429,27 @@ virPCIGetNetName(const char *device_link_sysfs_path, } =20 *netname =3D g_strdup(entry->d_name); - - ret =3D 0; - break; + return 0; } =20 - if (ret < 0) { - if (physPortID) { - if (firstEntryName) { - /* we didn't match the provided phys_port_id, but this - * is probably because phys_port_id isn't implemented - * for this NIC driver, so just return the first - * (probably only) netname we found. - */ - *netname =3D firstEntryName; - firstEntryName =3D NULL; - ret =3D 0; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Could not find network device with " - "phys_port_id '%s' under PCI device at %s= "), - physPortID, device_link_sysfs_path); - } - } else { - ret =3D 0; /* no netdev at the given index is *not* an error */ - } + if (!physPortID) + return 0; + + if (firstEntryName) { + /* we didn't match the provided phys_port_id, but this + * is probably because phys_port_id isn't implemented + * for this NIC driver, so just return the first + * (probably only) netname we found. + */ + *netname =3D g_steal_pointer(&firstEntryName); + return 0; } - cleanup: - return ret; + + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not find network device with " + "phys_port_id '%s' under PCI device at %s"), + physPortID, device_link_sysfs_path); + return -1; } =20 int --=20 2.26.2 From nobody Mon May 6 03:50:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1603849153; cv=none; d=zohomail.com; s=zohoarc; b=aInyCiOW4vnI+FLJUgHl1q3UCAHoXVoJ+9zE2TUTnYxsYM3syUIxwSDwb6U+8TZOvU3j/02Hkt8mZspHsFLC1EU7h5T8yoiDZfeua+YoRmxFcJigwC4jkLysmMO7hmwX2OudoPrR3DLU3ddUlWXofa+RbL6XtIDdSAE5ENIL3Aw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603849153; 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; bh=GqPgUQxTCfH4dpzDsT8iBrYBbCrbC5+o6eJ1tBkRM9E=; b=Pa2ms/74eann8IEvcZ7ePDVURnTT22FsrPPj4xQQpSaxciBNhYx3OptApjdVoxmBgqR7zOzFEAW9X3vJNN6l/D3U1Im6OCQIEsgfDxEkL4AuJlkOzi9VJiSnnM5GpkCW474WviQzg4mITSWtr9kdBHLlWpuheOFGohJoAPAeSJI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1603849153242956.0837033268698; Tue, 27 Oct 2020 18:39:13 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-336-FoaKoPhlPCCaeSTbAW-_7g-1; Tue, 27 Oct 2020 21:36:45 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E15E7188C135; Wed, 28 Oct 2020 01:36: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 C17266EF50; Wed, 28 Oct 2020 01:36: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 8E980CF66; Wed, 28 Oct 2020 01:36:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 09S1aEtO028321 for ; Tue, 27 Oct 2020 21:36:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id A23745C1DC; Wed, 28 Oct 2020 01:36:14 +0000 (UTC) Received: from vhost2.laine.org (ovpn-113-144.phx2.redhat.com [10.3.113.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id 614685C1C5 for ; Wed, 28 Oct 2020 01:36:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603849152; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=GqPgUQxTCfH4dpzDsT8iBrYBbCrbC5+o6eJ1tBkRM9E=; b=FmXOZG+Rhamme5s8Pe3hiL1Tkry3W4TiQkrqsB0RRVCzjoSDSnyIBdQcC2iikxEGVJ+LEr roMkz4hH3XrOeB0KfWpWSZrC0La0ZupHfavqaXeebJj1EecVQoM5CiYqZDno8xu2qGOPxv Rcmn7qEnsWf8nlejSKt1ikvouAwHyrw= X-MC-Unique: FoaKoPhlPCCaeSTbAW-_7g-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 12/12] remove unnecessary cleanup labels and unused return variables Date: Tue, 27 Oct 2020 21:35:58 -0400 Message-Id: <20201028013558.424925-13-laine@redhat.com> In-Reply-To: <20201028013558.424925-1-laine@redhat.com> References: <20201028013558.424925-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" After converting all DIR* to g_autoptr(DIR), many cleanup: labels ended up just having "return ret", and every place that set ret would just immediately goto cleanup. Remove the cleanup label and its return, and just return the set value immediately, thus eliminating the need for the return variable itself. Signed-off-by: Laine Stump Reviewed-by: Daniel Henrique Barboza --- src/conf/virnetworkobj.c | 32 +++++++--------------- src/qemu/qemu_interop_config.c | 11 +++----- src/storage/storage_util.c | 50 +++++++++++++--------------------- src/util/vircgroup.c | 16 ++++------- src/util/vircommand.c | 9 ++---- src/util/virdevmapper.c | 6 ++-- src/util/virfile.c | 45 ++++++++++++------------------ src/util/virnetdev.c | 10 ++----- src/util/virnuma.c | 21 ++++++-------- src/util/virpci.c | 27 ++++++------------ src/util/virresctrl.c | 21 ++++++-------- src/util/virscsi.c | 26 ++++++------------ src/util/virutil.c | 20 ++++---------- src/util/virvhba.c | 11 +++----- tests/testutilsqemu.c | 28 +++++++------------ 15 files changed, 119 insertions(+), 214 deletions(-) diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c index acf1442f88..8b3eb0f41c 100644 --- a/src/conf/virnetworkobj.c +++ b/src/conf/virnetworkobj.c @@ -1091,12 +1091,11 @@ virNetworkObjLoadAllState(virNetworkObjListPtr nets, if (obj && virNetworkObjLoadAllPorts(obj, stateDir) < 0) { virNetworkObjEndAPI(&obj); - goto cleanup; + return -1; } virNetworkObjEndAPI(&obj); } =20 - cleanup: return ret; } =20 @@ -1708,15 +1707,12 @@ virNetworkObjDeleteAllPorts(virNetworkObjPtr net, g_autoptr(DIR) dh =3D NULL; struct dirent *de; int rc; - int ret =3D -1; =20 if (!(dir =3D virNetworkObjGetPortStatusDir(net, stateDir))) - goto cleanup; + return -1; =20 - if ((rc =3D virDirOpenIfExists(&dh, dir)) <=3D 0) { - ret =3D rc; - goto cleanup; - } + if ((rc =3D virDirOpenIfExists(&dh, dir)) <=3D 0) + return rc; =20 while ((rc =3D virDirRead(dh, &de, dir)) > 0) { char *file =3D NULL; @@ -1733,10 +1729,7 @@ virNetworkObjDeleteAllPorts(virNetworkObjPtr net, } =20 virHashRemoveAll(net->ports); - - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 @@ -1862,18 +1855,15 @@ virNetworkObjLoadAllPorts(virNetworkObjPtr net, g_autofree char *dir =3D NULL; g_autoptr(DIR) dh =3D NULL; struct dirent *de; - int ret =3D -1; int rc; char uuidstr[VIR_UUID_STRING_BUFLEN]; g_autoptr(virNetworkPortDef) portdef =3D NULL; =20 if (!(dir =3D virNetworkObjGetPortStatusDir(net, stateDir))) - goto cleanup; + return -1; =20 - if ((rc =3D virDirOpenIfExists(&dh, dir)) <=3D 0) { - ret =3D rc; - goto cleanup; - } + if ((rc =3D virDirOpenIfExists(&dh, dir)) <=3D 0) + return rc; =20 while ((rc =3D virDirRead(dh, &de, dir)) > 0) { g_autofree char *file =3D NULL; @@ -1891,12 +1881,10 @@ virNetworkObjLoadAllPorts(virNetworkObjPtr net, =20 virUUIDFormat(portdef->uuid, uuidstr); if (virHashAddEntry(net->ports, uuidstr, portdef) < 0) - goto cleanup; + return -1; =20 portdef =3D NULL; } =20 - ret =3D 0; - cleanup: - return ret; + return 0; } diff --git a/src/qemu/qemu_interop_config.c b/src/qemu/qemu_interop_config.c index f2d83eae93..e1c20aff11 100644 --- a/src/qemu/qemu_interop_config.c +++ b/src/qemu/qemu_interop_config.c @@ -40,7 +40,6 @@ qemuBuildFileList(virHashTablePtr files, const char *dir) g_autoptr(DIR) dirp =3D NULL; struct dirent *ent =3D NULL; int rc; - int ret =3D -1; =20 if ((rc =3D virDirOpenIfExists(&dirp, dir)) < 0) return -1; @@ -62,24 +61,22 @@ qemuBuildFileList(virHashTablePtr files, const char *di= r) =20 if (stat(path, &sb) < 0) { virReportSystemError(errno, _("Unable to access %s"), path); - goto cleanup; + return -1; } =20 if (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode)) continue; =20 if (virHashUpdateEntry(files, filename, path) < 0) - goto cleanup; + return -1; =20 path =3D NULL; } =20 if (rc < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - return ret; + return 0; } =20 static int diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 5a5e517b15..cf1f33f177 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -3507,13 +3507,12 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr = pool) struct statvfs sb; struct stat statbuf; int direrr; - int ret =3D -1; g_autoptr(virStorageVolDef) vol =3D NULL; VIR_AUTOCLOSE fd =3D -1; g_autoptr(virStorageSource) target =3D NULL; =20 if (virDirOpen(&dir, def->target.path) < 0) - goto cleanup; + return -1; =20 while ((direrr =3D virDirRead(dir, &ent, def->target.path)) > 0) { int err; @@ -3541,15 +3540,15 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr = pool) vol =3D NULL; continue; } - goto cleanup; + return -1; } =20 if (virStoragePoolObjAddVol(pool, vol) < 0) - goto cleanup; + return -1; vol =3D NULL; } if (direrr < 0) - goto cleanup; + return -1; =20 target =3D virStorageSourceNew(); =20 @@ -3557,25 +3556,25 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr = pool) virReportSystemError(errno, _("cannot open path '%s'"), def->target.path); - goto cleanup; + return -1; } =20 if (fstat(fd, &statbuf) < 0) { virReportSystemError(errno, _("cannot stat path '%s'"), def->target.path); - goto cleanup; + return -1; } =20 if (virStorageBackendUpdateVolTargetInfoFD(target, fd, &statbuf) < 0) - goto cleanup; + return -1; =20 /* VolTargetInfoFD doesn't update capacity correctly for the pool case= */ if (statvfs(def->target.path, &sb) < 0) { virReportSystemError(errno, _("cannot statvfs path '%s'"), def->target.path); - goto cleanup; + return -1; } =20 def->capacity =3D ((unsigned long long)sb.f_frsize * @@ -3590,9 +3589,7 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr po= ol) VIR_FREE(def->target.perms.label); def->target.perms.label =3D g_strdup(target->perms->label); =20 - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 @@ -3724,7 +3721,6 @@ getNewStyleBlockDevice(const char *lun_path, { g_autoptr(DIR) block_dir =3D NULL; struct dirent *block_dirent =3D NULL; - int retval =3D -1; int direrr; g_autofree char *block_path =3D NULL; =20 @@ -3733,7 +3729,7 @@ getNewStyleBlockDevice(const char *lun_path, VIR_DEBUG("Looking for block device in '%s'", block_path); =20 if (virDirOpen(&block_dir, block_path) < 0) - goto cleanup; + return -1; =20 while ((direrr =3D virDirRead(block_dir, &block_dirent, block_path)) >= 0) { *block_device =3D g_strdup(block_dirent->d_name); @@ -3744,12 +3740,9 @@ getNewStyleBlockDevice(const char *lun_path, } =20 if (direrr < 0) - goto cleanup; - - retval =3D 0; + return -1; =20 - cleanup: - return retval; + return 0; } =20 =20 @@ -3796,7 +3789,6 @@ getBlockDevice(uint32_t host, { g_autoptr(DIR) lun_dir =3D NULL; struct dirent *lun_dirent =3D NULL; - int retval =3D -1; int direrr; g_autofree char *lun_path =3D NULL; =20 @@ -3806,7 +3798,7 @@ getBlockDevice(uint32_t host, target, lun); =20 if (virDirOpen(&lun_dir, lun_path) < 0) - goto cleanup; + return -1; =20 while ((direrr =3D virDirRead(lun_dir, &lun_dirent, lun_path)) > 0) { if (STRPREFIX(lun_dirent->d_name, "block")) { @@ -3814,27 +3806,23 @@ getBlockDevice(uint32_t host, if (getNewStyleBlockDevice(lun_path, lun_dirent->d_name, block_device) < 0) - goto cleanup; + return -1; } else { if (getOldStyleBlockDevice(lun_path, lun_dirent->d_name, block_device) < 0) - goto cleanup; + return -1; } break; } } if (direrr < 0) - goto cleanup; - if (!*block_device) { - retval =3D -2; - goto cleanup; - } + return -1; =20 - retval =3D 0; + if (!*block_device) + return -2; =20 - cleanup: - return retval; + return 0; } =20 =20 diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 6ba030bf9b..e3c45e93cb 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -2465,7 +2465,6 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, const char *taskFile, bool dormdir) { - int ret =3D -1; int rc; bool killedAny =3D false; g_autofree char *keypath =3D NULL; @@ -2480,14 +2479,14 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, =20 if ((rc =3D virCgroupKillInternal(group, signum, pids, controller, taskFile)) < 0) { - goto cleanup; + return -1; } if (rc =3D=3D 1) killedAny =3D true; =20 VIR_DEBUG("Iterate over children of %s (killedAny=3D%d)", keypath, kil= ledAny); if ((rc =3D virDirOpenIfExists(&dp, keypath)) < 0) - goto cleanup; + return -1; =20 if (rc =3D=3D 0) { VIR_DEBUG("Path %s does not exist, assuming done", keypath); @@ -2504,11 +2503,11 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, VIR_DEBUG("Process subdir %s", ent->d_name); =20 if (virCgroupNew(-1, ent->d_name, group, -1, &subgroup) < 0) - goto cleanup; + return -1; =20 if ((rc =3D virCgroupKillRecursiveInternal(subgroup, signum, pids, controller, taskFile, tru= e)) < 0) - goto cleanup; + return -1; if (rc =3D=3D 1) killedAny =3D true; =20 @@ -2516,13 +2515,10 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, virCgroupRemove(subgroup); } if (direrr < 0) - goto cleanup; + return -1; =20 done: - ret =3D killedAny ? 1 : 0; - - cleanup: - return ret; + return killedAny ? 1 : 0; } =20 =20 diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 5ae2ad9ef9..9a4f3d7f32 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -456,7 +456,6 @@ virCommandMassCloseGetFDsLinux(virCommandPtr cmd G_GNUC= _UNUSED, struct dirent *entry; const char *dirName =3D "/proc/self/fd"; int rc; - int ret =3D -1; =20 if (virDirOpen(&dp, dirName) < 0) return -1; @@ -468,18 +467,16 @@ virCommandMassCloseGetFDsLinux(virCommandPtr cmd G_GN= UC_UNUSED, virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to parse FD: %s"), entry->d_name); - goto cleanup; + return -1; } =20 ignore_value(virBitmapSetBit(fds, fd)); } =20 if (rc < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - return ret; + return 0; } =20 # else /* !__linux__ */ diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c index 323102d36e..6c39a2a44d 100644 --- a/src/util/virdevmapper.c +++ b/src/util/virdevmapper.c @@ -171,7 +171,6 @@ virDMSanitizepath(const char *path) struct stat sb[2]; g_autoptr(DIR) dh =3D NULL; const char *p; - char *ret =3D NULL; =20 /* If a path is NOT provided then assume it's DM name */ p =3D strrchr(path, '/'); @@ -206,12 +205,11 @@ virDMSanitizepath(const char *path) =20 if (stat(tmp, &sb[1]) =3D=3D 0 && sb[0].st_rdev =3D=3D sb[0].st_rdev) { - ret =3D g_steal_pointer(&tmp); - break; + return g_steal_pointer(&tmp); } } =20 - return ret; + return NULL; } =20 =20 diff --git a/src/util/virfile.c b/src/util/virfile.c index fc0021036a..9a7dcfc9a6 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -836,7 +836,6 @@ static char * virFileNBDDeviceFindUnused(void) { g_autoptr(DIR) dh =3D NULL; - char *ret =3D NULL; struct dirent *de; int direrr; =20 @@ -846,21 +845,19 @@ virFileNBDDeviceFindUnused(void) while ((direrr =3D virDirRead(dh, &de, SYSFS_BLOCK_DIR)) > 0) { if (STRPREFIX(de->d_name, "nbd")) { int rv =3D virFileNBDDeviceIsBusy(de->d_name); + if (rv < 0) - goto cleanup; - if (rv =3D=3D 0) { - ret =3D g_strdup_printf("/dev/%s", de->d_name); - goto cleanup; - } + return NULL; + + if (rv =3D=3D 0) + return g_strdup_printf("/dev/%s", de->d_name); } } if (direrr < 0) - goto cleanup; - virReportSystemError(EBUSY, "%s", - _("No free NBD devices")); + return NULL; =20 - cleanup: - return ret; + virReportSystemError(EBUSY, "%s", _("No free NBD devices")); + return NULL; } =20 static bool @@ -979,7 +976,6 @@ int virFileDeleteTree(const char *dir) { g_autoptr(DIR) dh =3D NULL; struct dirent *de; - int ret =3D -1; int direrr; =20 /* Silently return 0 if passed NULL or directory doesn't exist */ @@ -998,35 +994,32 @@ int virFileDeleteTree(const char *dir) if (g_lstat(filepath, &sb) < 0) { virReportSystemError(errno, _("Cannot access '%s'"), filepath); - goto cleanup; + return -1; } =20 if (S_ISDIR(sb.st_mode)) { if (virFileDeleteTree(filepath) < 0) - goto cleanup; + return -1; } else { if (unlink(filepath) < 0 && errno !=3D ENOENT) { virReportSystemError(errno, _("Cannot delete file '%s'"), filepath); - goto cleanup; + return -1; } } } if (direrr < 0) - goto cleanup; + return -1; =20 if (rmdir(dir) < 0 && errno !=3D ENOENT) { virReportSystemError(errno, _("Cannot delete directory '%s'"), dir); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 /* Like read(), but restarts after EINTR. Doesn't play @@ -2949,7 +2942,6 @@ int virFileChownFiles(const char *name, gid_t gid) { struct dirent *ent; - int ret =3D -1; int direrr; g_autoptr(DIR) dir =3D NULL; =20 @@ -2969,17 +2961,14 @@ int virFileChownFiles(const char *name, _("cannot chown '%s' to (%u, %u)"), ent->d_name, (unsigned int) uid, (unsigned int) gid); - goto cleanup; + return -1; } } =20 if (direrr < 0) - goto cleanup; - - ret =3D 0; + return -1; =20 - cleanup: - return ret; + return 0; } =20 #else /* WIN32 */ diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 256179c052..5104bbe7c5 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -2900,7 +2900,6 @@ virNetDevRDMAFeature(const char *ifname, g_autofree char *eth_res_buf =3D NULL; g_autoptr(DIR) dirp =3D NULL; struct dirent *dp; - int ret =3D -1; =20 if (!virFileExists(SYSFS_INFINIBAND_DIR)) return 0; @@ -2913,12 +2912,11 @@ virNetDevRDMAFeature(const char *ifname, /* If /sys/class/net//device/resource doesn't exist it is not = a PCI * device and therefore it will not have RDMA. */ if (!virFileExists(eth_devpath)) { - ret =3D 0; - goto cleanup; + return 0; } =20 if (virFileReadAll(eth_devpath, RESOURCE_FILE_LEN, ð_res_buf) < 0) - goto cleanup; + return -1; =20 while (virDirRead(dirp, &dp, SYSFS_INFINIBAND_DIR) > 0) { g_autofree char *ib_res_buf =3D NULL; @@ -2931,10 +2929,8 @@ virNetDevRDMAFeature(const char *ifname, break; } } - ret =3D 0; =20 - cleanup: - return ret; + return 0; } =20 =20 diff --git a/src/util/virnuma.c b/src/util/virnuma.c index 51a5d6e8a6..a05e4ac72c 100644 --- a/src/util/virnuma.c +++ b/src/util/virnuma.c @@ -739,7 +739,6 @@ virNumaGetPages(int node, unsigned long long **pages_free, size_t *npages) { - int ret =3D -1; g_autoptr(DIR) dir =3D NULL; int direrr =3D 0; struct dirent *entry; @@ -763,12 +762,12 @@ virNumaGetPages(int node, * slightly different information. So we take the total memory on a no= de * and subtract memory taken by the huge pages. */ if (virNumaGetHugePageInfoDir(&path, node) < 0) - goto cleanup; + return -1; =20 /* It's okay if the @path doesn't exist. Maybe we are running on * system without huge pages support where the path may not exist. */ if (virDirOpenIfExists(&dir, path) < 0) - goto cleanup; + return -1; =20 while (dir && (direrr =3D virDirRead(dir, &entry, path)) > 0) { const char *page_name =3D entry->d_name; @@ -789,17 +788,17 @@ virNumaGetPages(int node, virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to parse %s"), entry->d_name); - goto cleanup; + return -1; } =20 if (virNumaGetHugePageInfo(node, page_size, &page_avail, &page_free) < 0) - goto cleanup; + return -1; =20 if (VIR_REALLOC_N(tmp_size, ntmp + 1) < 0 || VIR_REALLOC_N(tmp_avail, ntmp + 1) < 0 || VIR_REALLOC_N(tmp_free, ntmp + 1) < 0) - goto cleanup; + return -1; =20 tmp_size[ntmp] =3D page_size; tmp_avail[ntmp] =3D page_avail; @@ -812,17 +811,17 @@ virNumaGetPages(int node, } =20 if (direrr < 0) - goto cleanup; + return -1; =20 /* Now append the ordinary system pages */ if (VIR_REALLOC_N(tmp_size, ntmp + 1) < 0 || VIR_REALLOC_N(tmp_avail, ntmp + 1) < 0 || VIR_REALLOC_N(tmp_free, ntmp + 1) < 0) - goto cleanup; + return -1; =20 if (virNumaGetPageInfo(node, system_page_size, huge_page_sum, &tmp_avail[ntmp], &tmp_free[ntmp]) < 0) - goto cleanup; + return -1; tmp_size[ntmp] =3D system_page_size; ntmp++; =20 @@ -852,9 +851,7 @@ virNumaGetPages(int node, tmp_free =3D NULL; } *npages =3D ntmp; - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 diff --git a/src/util/virpci.c b/src/util/virpci.c index 025eb9d91c..a501db6ff7 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1706,7 +1706,6 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev, { g_autofree char *pcidir =3D NULL; g_autoptr(DIR) dir =3D NULL; - int ret =3D -1; struct dirent *ent; int direrr; =20 @@ -1715,7 +1714,7 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev, dev->address.function); =20 if (virDirOpen(&dir, pcidir) < 0) - goto cleanup; + return -1; =20 while ((direrr =3D virDirRead(dir, &ent, pcidir)) > 0) { g_autofree char *file =3D NULL; @@ -1731,16 +1730,13 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev, STREQ(ent->d_name, "reset")) { file =3D g_strdup_printf("%s/%s", pcidir, ent->d_name); if ((actor)(dev, file, opaque) < 0) - goto cleanup; + return -1; } } if (direrr < 0) - goto cleanup; - - ret =3D 0; + return -1; =20 - cleanup: - return ret; + return 0; } =20 =20 @@ -1756,7 +1752,6 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddr= essPtr orig, { g_autofree char *groupPath =3D NULL; g_autoptr(DIR) groupDir =3D NULL; - int ret =3D -1; struct dirent *ent; int direrr; =20 @@ -1765,8 +1760,7 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddr= essPtr orig, =20 if (virDirOpenQuiet(&groupDir, groupPath) < 0) { /* just process the original device, nothing more */ - ret =3D (actor)(orig, opaque); - goto cleanup; + return (actor)(orig, opaque); } =20 while ((direrr =3D virDirRead(groupDir, &ent, groupPath)) > 0) { @@ -1776,19 +1770,16 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAd= dressPtr orig, virReportError(VIR_ERR_INTERNAL_ERROR, _("Found invalid device link '%s' in '%s'"), ent->d_name, groupPath); - goto cleanup; + return -1; } =20 if ((actor)(&newDev, opaque) < 0) - goto cleanup; + return -1; } if (direrr < 0) - goto cleanup; - - ret =3D 0; + return -1; =20 - cleanup: - return ret; + return 0; } =20 =20 diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index aa466592fc..d3087b98c1 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -786,23 +786,18 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl) =20 ret =3D virDirOpenIfExists(&dirp, SYSFS_RESCTRL_PATH "/info"); if (ret <=3D 0) - goto cleanup; + return ret; =20 - ret =3D virResctrlGetMemoryBandwidthInfo(resctrl); - if (ret < 0) - goto cleanup; + if ((ret =3D virResctrlGetMemoryBandwidthInfo(resctrl)) < 0) + return -1; =20 - ret =3D virResctrlGetCacheInfo(resctrl, dirp); - if (ret < 0) - goto cleanup; + if ((ret =3D virResctrlGetCacheInfo(resctrl, dirp)) < 0) + return -1; =20 - ret =3D virResctrlGetMonitorInfo(resctrl); - if (ret < 0) - goto cleanup; + if ((ret =3D virResctrlGetMonitorInfo(resctrl)) < 0) + return -1; =20 - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 diff --git a/src/util/virscsi.c b/src/util/virscsi.c index 256acc37fa..22d4679368 100644 --- a/src/util/virscsi.c +++ b/src/util/virscsi.c @@ -109,7 +109,6 @@ virSCSIDeviceGetSgName(const char *sysfs_prefix, g_autoptr(DIR) dir =3D NULL; struct dirent *entry; g_autofree char *path =3D NULL; - char *sg =3D NULL; unsigned int adapter_id; const char *prefix =3D sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_DEVICE= S; =20 @@ -120,16 +119,13 @@ virSCSIDeviceGetSgName(const char *sysfs_prefix, bus, target, unit); =20 if (virDirOpen(&dir, path) < 0) - goto cleanup; + return NULL; =20 - while (virDirRead(dir, &entry, path) > 0) { - /* Assume a single directory entry */ - sg =3D g_strdup(entry->d_name); - break; - } + /* Assume a single directory entry */ + if (virDirRead(dir, &entry, path) > 0) + return g_strdup(entry->d_name); =20 - cleanup: - return sg; + return NULL; } =20 /* Returns device name (e.g. "sdc") on success, or NULL @@ -145,7 +141,6 @@ virSCSIDeviceGetDevName(const char *sysfs_prefix, g_autoptr(DIR) dir =3D NULL; struct dirent *entry; g_autofree char *path =3D NULL; - char *name =3D NULL; unsigned int adapter_id; const char *prefix =3D sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_DEVICE= S; =20 @@ -156,15 +151,12 @@ virSCSIDeviceGetDevName(const char *sysfs_prefix, target, unit); =20 if (virDirOpen(&dir, path) < 0) - goto cleanup; + return NULL; =20 - while (virDirRead(dir, &entry, path) > 0) { - name =3D g_strdup(entry->d_name); - break; - } + if (virDirRead(dir, &entry, path) > 0) + return g_strdup(entry->d_name); =20 - cleanup: - return name; + return NULL; } =20 virSCSIDevicePtr diff --git a/src/util/virutil.c b/src/util/virutil.c index 41e92023fc..a0cd0f1bcd 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1623,22 +1623,18 @@ virHostHasIOMMU(void) { g_autoptr(DIR) iommuDir =3D NULL; struct dirent *iommuGroup =3D NULL; - bool ret =3D false; int direrr; =20 if (virDirOpenQuiet(&iommuDir, "/sys/kernel/iommu_groups/") < 0) - goto cleanup; + return false; =20 while ((direrr =3D virDirRead(iommuDir, &iommuGroup, NULL)) > 0) break; =20 if (direrr < 0 || !iommuGroup) - goto cleanup; - - ret =3D true; + return false; =20 - cleanup: - return ret; + return true; } =20 =20 @@ -1656,7 +1652,6 @@ virHostHasIOMMU(void) char * virHostGetDRMRenderNode(void) { - char *ret =3D NULL; g_autoptr(DIR) driDir =3D NULL; const char *driPath =3D "/dev/dri"; struct dirent *ent =3D NULL; @@ -1674,19 +1669,16 @@ virHostGetDRMRenderNode(void) } =20 if (dirErr < 0) - goto cleanup; + return NULL; =20 /* even if /dev/dri exists, there might be no renderDX nodes available= */ if (!have_rendernode) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("No DRM render nodes available")); - goto cleanup; + return NULL; } =20 - ret =3D g_strdup_printf("%s/%s", driPath, ent->d_name); - - cleanup: - return ret; + return g_strdup_printf("%s/%s", driPath, ent->d_name); } =20 =20 diff --git a/src/util/virvhba.c b/src/util/virvhba.c index 471d94d3dd..a4e88024d1 100644 --- a/src/util/virvhba.c +++ b/src/util/virvhba.c @@ -365,7 +365,6 @@ virVHBAGetHostByWWN(const char *sysfs_prefix, const char *prefix =3D sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PAT= H; struct dirent *entry =3D NULL; g_autoptr(DIR) dir =3D NULL; - char *ret =3D NULL; =20 if (virDirOpen(&dir, prefix) < 0) return NULL; @@ -375,24 +374,22 @@ virVHBAGetHostByWWN(const char *sysfs_prefix, =20 if ((rc =3D vhbaReadCompareWWN(prefix, entry->d_name, "node_name", wwnn)) < 0) - goto cleanup; + return NULL; =20 if (rc =3D=3D 0) continue; =20 if ((rc =3D vhbaReadCompareWWN(prefix, entry->d_name, "port_name", wwpn)) < 0) - goto cleanup; + return NULL; =20 if (rc =3D=3D 0) continue; =20 - ret =3D g_strdup(entry->d_name); - break; + return g_strdup(entry->d_name); } =20 - cleanup: - return ret; + return NULL; } =20 /* virVHBAGetHostByFabricWWN: diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 5ae1d64337..c6848c12a2 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -516,12 +516,11 @@ testQemuGetLatestCapsForArch(const char *arch, unsigned long maxver =3D 0; unsigned long ver; g_autofree char *maxname =3D NULL; - char *ret =3D NULL; =20 fullsuffix =3D g_strdup_printf("%s.%s", arch, suffix); =20 if (virDirOpen(&dir, TEST_QEMU_CAPS_PATH) < 0) - goto cleanup; + return NULL; =20 while ((rc =3D virDirRead(dir, &ent, TEST_QEMU_CAPS_PATH)) > 0) { g_autofree char *tmp =3D NULL; @@ -547,18 +546,15 @@ testQemuGetLatestCapsForArch(const char *arch, } =20 if (rc < 0) - goto cleanup; + return NULL; =20 if (!maxname) { VIR_TEST_VERBOSE("failed to find capabilities for '%s' in '%s'", arch, TEST_QEMU_CAPS_PATH); - goto cleanup; + return NULL; } =20 - ret =3D g_strdup_printf("%s/%s", TEST_QEMU_CAPS_PATH, maxname); - - cleanup: - return ret; + return g_strdup_printf("%s/%s", TEST_QEMU_CAPS_PATH, maxname); } =20 =20 @@ -607,7 +603,6 @@ testQemuCapsIterate(const char *suffix, struct dirent *ent; g_autoptr(DIR) dir =3D NULL; int rc; - int ret =3D -1; bool fail =3D false; =20 if (!callback) @@ -616,11 +611,11 @@ testQemuCapsIterate(const char *suffix, /* Validate suffix */ if (!STRPREFIX(suffix, ".")) { VIR_TEST_VERBOSE("malformed suffix '%s'", suffix); - goto cleanup; + return -1; } =20 if (virDirOpen(&dir, TEST_QEMU_CAPS_PATH) < 0) - goto cleanup; + return -1; =20 while ((rc =3D virDirRead(dir, &ent, TEST_QEMU_CAPS_PATH)) > 0) { g_autofree char *tmp =3D g_strdup(ent->d_name); @@ -634,13 +629,13 @@ testQemuCapsIterate(const char *suffix, /* Strip the leading prefix */ if (!(version =3D STRSKIP(tmp, "caps_"))) { VIR_TEST_VERBOSE("malformed file name '%s'", ent->d_name); - goto cleanup; + return -1; } =20 /* Find the last dot */ if (!(archName =3D strrchr(tmp, '.'))) { VIR_TEST_VERBOSE("malformed file name '%s'", ent->d_name); - goto cleanup; + return -1; } =20 /* The version number and the architecture name are separated by @@ -661,12 +656,9 @@ testQemuCapsIterate(const char *suffix, } =20 if (rc < 0 || fail) - goto cleanup; - - ret =3D 0; + return -1; =20 - cleanup: - return ret; + return 0; } =20 =20 --=20 2.26.2