From nobody Tue Feb 10 04:02:51 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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=1594006967; cv=none; d=zohomail.com; s=zohoarc; b=JYD4qA8H+WhVUzMwmNrMv3TUR5gdxVL0X7o7NbQntwa/OcRGAJ2pvKBJG1KnM+XoAG+YBBtu6Lqsr1ORl8Joz0f3acQW3W6HzqhaumfT4fcasN9rgpojZvM1ar66YofvV0QX5qwjWcN7IcfKZu48s9qD3AM7OvBBSSyyZIgtB9s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594006967; 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=S+qa3TFsuPWNq0eEicwzQzgTVjbyaidy3TS02ZUIdP4=; b=fUY2rdrVhMThBKrYsMZMdie0OfQLT/fLuw6gZ2XYdpETbtMkwKcQ36tq4XeUJ4TNfAdson35/jYWksP61xydUCbB2t5ucoAQ4TXh36q+o9PgWgoy2BiiinP4VThHP7bf3mLekJZoEGAHkM7v7C/5w+VX3A8b/7YAcXfm9tVFrrM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1594006967921936.4532194736041; Sun, 5 Jul 2020 20:42:47 -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-214-y4OUTr5rMoOjlsiGQBJm7g-1; Sun, 05 Jul 2020 23:42:44 -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 22A5318FE867; Mon, 6 Jul 2020 03:42:39 +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 042F771678; Mon, 6 Jul 2020 03:42: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 C9C0B18005C5; Mon, 6 Jul 2020 03:42:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0663gN7T004862 for ; Sun, 5 Jul 2020 23:42:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8D1B571678; Mon, 6 Jul 2020 03:42:23 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-194.phx2.redhat.com [10.3.112.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4336F275E25 for ; Mon, 6 Jul 2020 03:42:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594006966; 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=S+qa3TFsuPWNq0eEicwzQzgTVjbyaidy3TS02ZUIdP4=; b=HOdzaQu8bY1CpBPkPC5as5P0vhkteajzEJCErVBOcswzQeD0FCH0RMJ87oPx6uhhcpH9RO YgRshfC0K2oidv+oGQRwvyE3clo1+SP5DY0m1v/V76denkpH4TlBoVzK+3VEfEeEFzc+Zj oUMldplQaOJLTfA5KzT9778MNP75RfM= X-MC-Unique: y4OUTr5rMoOjlsiGQBJm7g-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 32/32] eliminate unnecessary labels and ret variables Date: Sun, 5 Jul 2020 23:41:27 -0400 Message-Id: <20200706034127.1117504-33-laine@redhat.com> In-Reply-To: <20200706034127.1117504-1-laine@redhat.com> References: <20200706034127.1117504-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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" after making all virFirewall objects use g_autoptr(). Signed-off-by: Laine Stump Reviewed-by: J=C3=A1n Tomko --- src/network/bridge_driver_linux.c | 27 +++++++------------ src/nwfilter/nwfilter_ebiptables_driver.c | 32 +++++++---------------- src/util/virebtables.c | 16 ++---------- src/util/viriptables.c | 8 ++---- 4 files changed, 22 insertions(+), 61 deletions(-) diff --git a/src/network/bridge_driver_linux.c b/src/network/bridge_driver_= linux.c index f72f94f38d..5fc77785dc 100644 --- a/src/network/bridge_driver_linux.c +++ b/src/network/bridge_driver_linux.c @@ -839,7 +839,6 @@ int networkAddFirewallRules(virNetworkDefPtr def) size_t i; virNetworkIPDefPtr ipdef; g_autoptr(virFirewall) fw =3D virFirewallNew(); - int ret =3D -1; =20 if (virOnce(&createdOnce, networkSetupPrivateChains) < 0) return -1; @@ -869,11 +868,11 @@ int networkAddFirewallRules(virNetworkDefPtr def) _("zone %s requested for network %s " "but firewalld is not active"), def->bridgeZone, def->name); - goto cleanup; + return -1; } =20 if (virFirewallDInterfaceSetZone(def->bridge, def->bridgeZone) < 0) - goto cleanup; + return -1; =20 } else { =20 @@ -893,13 +892,13 @@ int networkAddFirewallRules(virNetworkDefPtr def) */ if (virFirewallDZoneExists("libvirt")) { if (virFirewallDInterfaceSetZone(def->bridge, "libvirt") <= 0) - goto cleanup; + return -1; } else { unsigned long version; int vresult =3D virFirewallDGetVersion(&version); =20 if (vresult < 0) - goto cleanup; + return -1; =20 /* Support for nftables backend was added in firewalld * 0.6.0. Support for rule priorities (required by the @@ -919,7 +918,7 @@ int networkAddFirewallRules(virNetworkDefPtr def) "version supporting rule priorities " "(0.7.0+) and/or rebuilding " "libvirt with --with-firewalld-zone")= ); - goto cleanup; + return -1; } } } @@ -933,7 +932,7 @@ int networkAddFirewallRules(virNetworkDefPtr def) (ipdef =3D virNetworkDefGetIPByIndex(def, AF_UNSPEC, i)); i++) { if (networkAddIPSpecificFirewallRules(fw, def, ipdef) < 0) - goto cleanup; + return -1; } =20 virFirewallStartRollback(fw, 0); @@ -942,19 +941,14 @@ int networkAddFirewallRules(virNetworkDefPtr def) (ipdef =3D virNetworkDefGetIPByIndex(def, AF_UNSPEC, i)); i++) { if (networkRemoveIPSpecificFirewallRules(fw, def, ipdef) < 0) - goto cleanup; + return -1; } networkRemoveGeneralFirewallRules(fw, def); =20 virFirewallStartTransaction(fw, VIR_FIREWALL_TRANSACTION_IGNORE_ERRORS= ); networkAddChecksumFirewallRules(fw, def); =20 - if (virFirewallApply(fw) < 0) - goto cleanup; - - ret =3D 0; - cleanup: - return ret; + return virFirewallApply(fw); } =20 /* Remove all rules for all ip addresses (and general rules) on a network = */ @@ -973,12 +967,9 @@ void networkRemoveFirewallRules(virNetworkDefPtr def) (ipdef =3D virNetworkDefGetIPByIndex(def, AF_UNSPEC, i)); i++) { if (networkRemoveIPSpecificFirewallRules(fw, def, ipdef) < 0) - goto cleanup; + return; } networkRemoveGeneralFirewallRules(fw, def); =20 virFirewallApply(fw); - - cleanup: - return; } diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfil= ter_ebiptables_driver.c index 2976521e6d..78a52408b2 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -2866,7 +2866,7 @@ ebtablesApplyBasicRules(const char *ifname, virMacAddrFormat(macaddr, macaddr_str); =20 if (ebiptablesAllTeardown(ifname) < 0) - goto error; + return -1; =20 virFirewallStartTransaction(fw, 0); =20 @@ -2899,7 +2899,6 @@ ebtablesApplyBasicRules(const char *ifname, =20 tear_down_tmpebchains: ebtablesCleanAll(ifname); - error: return -1; } =20 @@ -2937,7 +2936,7 @@ ebtablesApplyDHCPOnlyRules(const char *ifname, virMacAddrFormat(macaddr, macaddr_str); =20 if (ebiptablesAllTeardown(ifname) < 0) - goto error; + return -1; =20 virFirewallStartTransaction(fw, 0); =20 @@ -3016,7 +3015,6 @@ ebtablesApplyDHCPOnlyRules(const char *ifname, =20 tear_down_tmpebchains: ebtablesCleanAll(ifname); - error: return -1; } =20 @@ -3038,7 +3036,7 @@ ebtablesApplyDropAllRules(const char *ifname) g_autoptr(virFirewall) fw =3D virFirewallNew(); =20 if (ebiptablesAllTeardown(ifname) < 0) - goto error; + return -1; =20 virFirewallStartTransaction(fw, 0); =20 @@ -3068,7 +3066,6 @@ ebtablesApplyDropAllRules(const char *ifname) =20 tear_down_tmpebchains: ebtablesCleanAll(ifname); - error: return -1; } =20 @@ -3084,7 +3081,6 @@ static int ebtablesCleanAll(const char *ifname) { g_autoptr(virFirewall) fw =3D virFirewallNew(); - int ret =3D -1; =20 virFirewallStartTransaction(fw, VIR_FIREWALL_TRANSACTION_IGNORE_ERRORS= ); =20 @@ -3100,8 +3096,7 @@ ebtablesCleanAll(const char *ifname) ebtablesRemoveTmpRootChainFW(fw, true, ifname); ebtablesRemoveTmpRootChainFW(fw, false, ifname); =20 - ret =3D virFirewallApply(fw); - return ret; + return virFirewallApply(fw); } =20 =20 @@ -3578,21 +3573,18 @@ static int ebiptablesTearNewRules(const char *ifname) { g_autoptr(virFirewall) fw =3D virFirewallNew(); - int ret =3D -1; =20 virFirewallStartTransaction(fw, VIR_FIREWALL_TRANSACTION_IGNORE_ERRORS= ); =20 ebiptablesTearNewRulesFW(fw, ifname); =20 - ret =3D virFirewallApply(fw); - return ret; + return virFirewallApply(fw); } =20 static int ebiptablesTearOldRules(const char *ifname) { g_autoptr(virFirewall) fw =3D virFirewallNew(); - int ret =3D -1; =20 virFirewallStartTransaction(fw, VIR_FIREWALL_TRANSACTION_IGNORE_ERRORS= ); =20 @@ -3611,8 +3603,7 @@ ebiptablesTearOldRules(const char *ifname) ebtablesRemoveRootChainFW(fw, false, ifname); ebtablesRenameTmpSubAndRootChainsFW(fw, ifname); =20 - ret =3D virFirewallApply(fw); - return ret; + return virFirewallApply(fw); } =20 =20 @@ -3629,7 +3620,6 @@ static int ebiptablesAllTeardown(const char *ifname) { g_autoptr(virFirewall) fw =3D virFirewallNew(); - int ret =3D -1; =20 virFirewallStartTransaction(fw, VIR_FIREWALL_TRANSACTION_IGNORE_ERRORS= ); =20 @@ -3651,8 +3641,7 @@ ebiptablesAllTeardown(const char *ifname) ebtablesRemoveRootChainFW(fw, true, ifname); ebtablesRemoveRootChainFW(fw, false, ifname); =20 - ret =3D virFirewallApply(fw); - return ret; + return virFirewallApply(fw); } =20 =20 @@ -3738,7 +3727,6 @@ ebiptablesDriverProbeStateMatch(void) { unsigned long version; g_autoptr(virFirewall) fw =3D virFirewallNew(); - int ret =3D -1; =20 virFirewallStartTransaction(fw, 0); virFirewallAddRuleFull(fw, VIR_FIREWALL_LAYER_IPV4, @@ -3746,7 +3734,7 @@ ebiptablesDriverProbeStateMatch(void) "--version", NULL); =20 if (virFirewallApply(fw) < 0) - goto cleanup; + return -1; =20 /* * since version 1.4.16 '-m state --state ...' will be converted to @@ -3755,9 +3743,7 @@ ebiptablesDriverProbeStateMatch(void) if (version >=3D 1 * 1000000 + 4 * 1000 + 16) newMatchState =3D true; =20 - ret =3D 0; - cleanup: - return ret; + return 0; } =20 static int diff --git a/src/util/virebtables.c b/src/util/virebtables.c index 69483f35ec..610c399414 100644 --- a/src/util/virebtables.c +++ b/src/util/virebtables.c @@ -83,7 +83,6 @@ int ebtablesAddForwardPolicyReject(ebtablesContext *ctx) { g_autoptr(virFirewall) fw =3D virFirewallNew(); - int ret =3D -1; =20 virFirewallStartTransaction(fw, VIR_FIREWALL_TRANSACTION_IGNORE_ERRORS= ); virFirewallAddRule(fw, VIR_FIREWALL_LAYER_ETHERNET, @@ -98,12 +97,7 @@ ebtablesAddForwardPolicyReject(ebtablesContext *ctx) "-P", ctx->chain, "DROP", NULL); =20 - if (virFirewallApply(fw) < 0) - goto cleanup; - - ret =3D 0; - cleanup: - return ret; + return virFirewallApply(fw); } =20 =20 @@ -117,7 +111,6 @@ ebtablesForwardAllowIn(ebtablesContext *ctx, int action) { g_autoptr(virFirewall) fw =3D virFirewallNew(); - int ret =3D -1; =20 virFirewallStartTransaction(fw, 0); virFirewallAddRule(fw, VIR_FIREWALL_LAYER_ETHERNET, @@ -128,12 +121,7 @@ ebtablesForwardAllowIn(ebtablesContext *ctx, "--jump", "ACCEPT", NULL); =20 - if (virFirewallApply(fw) < 0) - goto cleanup; - - ret =3D 0; - cleanup: - return ret; + return virFirewallApply(fw); } =20 /** diff --git a/src/util/viriptables.c b/src/util/viriptables.c index b1ef3a2db6..b5dd2edbd3 100644 --- a/src/util/viriptables.c +++ b/src/util/viriptables.c @@ -129,7 +129,6 @@ int iptablesSetupPrivateChains(virFirewallLayer layer) { g_autoptr(virFirewall) fw =3D virFirewallNew(); - int ret =3D -1; iptablesGlobalChain filter_chains[] =3D { {"INPUT", "LIBVIRT_INP"}, {"OUTPUT", "LIBVIRT_OUT"}, @@ -160,12 +159,9 @@ iptablesSetupPrivateChains(virFirewallLayer layer) "--list-rules", NULL); =20 if (virFirewallApply(fw) < 0) - goto cleanup; - - ret =3D changed ? 1 : 0; + return -1; =20 - cleanup: - return ret; + return changed ? 1 : 0; } =20 =20 --=20 2.25.4