From nobody Wed Jul 16 12:29:38 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533818008894615.4164142157397; Thu, 9 Aug 2018 05:33:28 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 535BF8CC1; Thu, 9 Aug 2018 12:33:26 +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 1B8DE6F812; Thu, 9 Aug 2018 12:33:26 +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 C60D74A46C; Thu, 9 Aug 2018 12:33:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w79CXBb6000487 for ; Thu, 9 Aug 2018 08:33:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id B5CB21001F57; Thu, 9 Aug 2018 12:33:11 +0000 (UTC) Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ACE1D1001947 for ; Thu, 9 Aug 2018 12:33:09 +0000 (UTC) Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4D77431524D9 for ; Thu, 9 Aug 2018 12:33:08 +0000 (UTC) Received: by mail-pf1-f179.google.com with SMTP id a26-v6so2794078pfo.4 for ; Thu, 09 Aug 2018 05:33:08 -0700 (PDT) Received: from centos.localdomain ([49.33.163.55]) by smtp.gmail.com with ESMTPSA id j15-v6sm8649810pfn.52.2018.08.09.05.33.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 05:33:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=+1fwe/Egh7uDfHJYH1E2ldfWsiyIfQ9Pr9nbuUQKUZY=; b=MA0DM3YGlT4zrFg7FJTFVEt62mgCm88ClUWkaL45bt2RSw1/EygyTlZGCpVyf3QRKd OXFUnqV+bMVNg+31Z62DB0nSds9100Yn3WcaP+2OCIuJmdsWXUNHzfMYw69YUxejHIBM IyNQOESa3D7OF2+84MKMxAbrRjuoVLo5dKK4DDazTguiF6MjWL45YZiucMreojJsjY5q ml8WRH5xkrZ9f9UTbyWTlHDBir5W0UKp4lSuy/Gis0xZmfPGN5jJ2q+ty6kycupfRaNC aFFfGj2KdueJ8EsHyZphBRp1QSAHWZRSY7oIZNwHhTFGvlWD0q4QDum/j7qGrUoBSZM7 6myQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=+1fwe/Egh7uDfHJYH1E2ldfWsiyIfQ9Pr9nbuUQKUZY=; b=IG5sLOlTyzChGdqtlV8ZzCFVhX94GlWf26kLXncS5ZtsoKf3jPa9IBCDMTjBFYeE+X jIXdwJ0wqKr9vJV1VHYdrbHUlPDobXfEvNpO/wTZdPMvHUd6ukTmWp6qzO6lfXKB+EWp HSRmxEDQHzb/OVpo1NEDoMJDVkRUbUW69ftTv4g4Gqgrv2DefzjmWF253wzzbjoha4la DPUF+y8TqQdm2HMOIku+XikMIhRnnF6UruL9ek9BHDKO1FXjEgvmyimu/6aHbpjQGgwW xE/ZANEp0KcHe0mCH1ZoOMQ2ZVXKAPZkhXl9qhdiBKZmBJHZ9RAsKYPOVEhCEXhkFPA3 c44A== X-Gm-Message-State: AOUpUlF3+qDCsrbO1E3XiLZVdgtWQawEXSAlHblpTSTiS/OCgq3QbX/T 0yhdNS1ykgQRtrF1VN5ieRbyr0mJ X-Google-Smtp-Source: AA+uWPwXO981+xsvAN69dq7ulYkfNUnWCH2BnNNMFCxSY941NwjwCzdR7uyTz1lCfMBw5Rno8ZK5ow== X-Received: by 2002:a63:ba54:: with SMTP id l20-v6mr2021517pgu.145.1533817987527; Thu, 09 Aug 2018 05:33:07 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Thu, 9 Aug 2018 09:42:18 +0530 Message-Id: <1533787939-28634-11-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533787939-28634-1-git-send-email-skrtbhtngr@gmail.com> References: <1533787939-28634-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 09 Aug 2018 12:33:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 09 Aug 2018 12:33:08 +0000 (UTC) for IP:'209.85.210.179' DOMAIN:'mail-pf1-f179.google.com' HELO:'mail-pf1-f179.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.993 (DATE_IN_PAST_06_12, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.210.179 mail-pf1-f179.google.com 209.85.210.179 mail-pf1-f179.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.41 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 10/11] util: netdevopenvswitch: use VIR_AUTOPTR for aggregate types X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 09 Aug 2018 12:33:27 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virnetdevopenvswitch.c | 80 ++++++++++++++-----------------------= ---- 1 file changed, 27 insertions(+), 53 deletions(-) diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitc= h.c index 9a9435f..a5de541 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -144,11 +144,10 @@ int virNetDevOpenvswitchAddPort(const char *brname, c= onst char *ifname, virNetDevVPortProfilePtr ovsport, virNetDevVlanPtr virtVlan) { - int ret =3D -1; - virCommandPtr cmd =3D NULL; char macaddrstr[VIR_MAC_STRING_BUFLEN]; char ifuuidstr[VIR_UUID_STRING_BUFLEN]; char vmuuidstr[VIR_UUID_STRING_BUFLEN]; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) attachedmac_ex_id =3D NULL; VIR_AUTOFREE(char *) ifaceid_ex_id =3D NULL; VIR_AUTOFREE(char *) profile_ex_id =3D NULL; @@ -160,17 +159,17 @@ int virNetDevOpenvswitchAddPort(const char *brname, c= onst char *ifname, =20 if (virAsprintf(&attachedmac_ex_id, "external-ids:attached-mac=3D\"%s\= "", macaddrstr) < 0) - goto cleanup; + return -1; if (virAsprintf(&ifaceid_ex_id, "external-ids:iface-id=3D\"%s\"", ifuuidstr) < 0) - goto cleanup; + return -1; if (virAsprintf(&vmid_ex_id, "external-ids:vm-id=3D\"%s\"", vmuuidstr) < 0) - goto cleanup; + return -1; if (ovsport->profileID[0] !=3D '\0') { if (virAsprintf(&profile_ex_id, "external-ids:port-profile=3D\"%s\= "", ovsport->profileID) < 0) - goto cleanup; + return -1; } =20 cmd =3D virCommandNew(OVSVSCTL); @@ -179,7 +178,7 @@ int virNetDevOpenvswitchAddPort(const char *brname, con= st char *ifname, ifname, "--", "add-port", brname, ifname, NULL); =20 if (virNetDevOpenvswitchConstructVlans(cmd, virtVlan) < 0) - goto cleanup; + return -1; =20 if (ovsport->profileID[0] =3D=3D '\0') { virCommandAddArgList(cmd, @@ -204,13 +203,10 @@ int virNetDevOpenvswitchAddPort(const char *brname, c= onst char *ifname, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to add port %s to OVS bridge %s"), ifname, brname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 /** @@ -223,8 +219,7 @@ int virNetDevOpenvswitchAddPort(const char *brname, con= st char *ifname, */ int virNetDevOpenvswitchRemovePort(const char *brname ATTRIBUTE_UNUSED, co= nst char *ifname) { - int ret =3D -1; - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNew(OVSVSCTL); virNetDevOpenvswitchAddTimeout(cmd); @@ -233,13 +228,10 @@ int virNetDevOpenvswitchRemovePort(const char *brname= ATTRIBUTE_UNUSED, const ch if (virCommandRun(cmd, NULL) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to delete port %s from OVS"), ifname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 /** @@ -253,9 +245,8 @@ int virNetDevOpenvswitchRemovePort(const char *brname A= TTRIBUTE_UNUSED, const ch */ int virNetDevOpenvswitchGetMigrateData(char **migrate, const char *ifname) { - virCommandPtr cmd =3D NULL; size_t len; - int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNew(OVSVSCTL); virNetDevOpenvswitchAddTimeout(cmd); @@ -269,7 +260,7 @@ int virNetDevOpenvswitchGetMigrateData(char **migrate, = const char *ifname) virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to run command to get OVS port data for " "interface %s"), ifname); - goto cleanup; + return -1; } =20 /* Wipeout the newline, if it exists */ @@ -277,10 +268,7 @@ int virNetDevOpenvswitchGetMigrateData(char **migrate,= const char *ifname) if (len > 0) (*migrate)[len - 1] =3D '\0'; =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 /** @@ -294,8 +282,7 @@ int virNetDevOpenvswitchGetMigrateData(char **migrate, = const char *ifname) */ int virNetDevOpenvswitchSetMigrateData(char *migrate, const char *ifname) { - virCommandPtr cmd =3D NULL; - int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (!migrate) { VIR_DEBUG("No OVS port data for interface %s", ifname); @@ -312,13 +299,10 @@ int virNetDevOpenvswitchSetMigrateData(char *migrate,= const char *ifname) virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to run command to set OVS port data for " "interface %s"), ifname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 /** @@ -334,10 +318,9 @@ int virNetDevOpenvswitchInterfaceStats(const char *ifname, virDomainInterfaceStatsPtr stats) { - virCommandPtr cmd =3D NULL; char *tmp; bool gotStats =3D false; - int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) output =3D NULL; =20 /* Just ensure the interface exists in ovs */ @@ -350,7 +333,7 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname, /* no ovs-vsctl or interface 'ifname' doesn't exists in ovs */ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Interface not found")); - goto cleanup; + return -1; } =20 #define GET_STAT(name, member) \ @@ -369,7 +352,7 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname, *tmp !=3D '\n') { \ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \ _("Fail to parse ovs-vsctl output")); \ - goto cleanup; \ + return -1; \ } \ gotStats =3D true; \ } \ @@ -389,14 +372,10 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname, if (!gotStats) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Interface doesn't have any statistics")); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 =20 @@ -467,12 +446,12 @@ int virNetDevOpenvswitchGetVhostuserIfname(const char *path, char **ifname) { - virCommandPtr cmd =3D NULL; char *tmpIfname =3D NULL; char **tokens =3D NULL; size_t ntokens =3D 0; int status; int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 /* Openvswitch vhostuser path are hardcoded to * //openvswitch/ @@ -503,7 +482,6 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path, =20 cleanup: virStringListFreeCount(tokens, ntokens); - virCommandFree(cmd); return ret; } =20 @@ -519,8 +497,7 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path, int virNetDevOpenvswitchUpdateVlan(const char *ifname, virNetDevVlanPtr virtVlan) { - int ret =3D -1; - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNew(OVSVSCTL); virNetDevOpenvswitchAddTimeout(cmd); @@ -531,16 +508,13 @@ int virNetDevOpenvswitchUpdateVlan(const char *ifname, "--", "--if-exists", "set", "Port", ifname, NULL); =20 if (virNetDevOpenvswitchConstructVlans(cmd, virtVlan) < 0) - goto cleanup; + return -1; =20 if (virCommandRun(cmd, NULL) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to set vlan configuration on port %s"), i= fname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list