From nobody Sat Feb 7 05:35:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; 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 15337142129191009.6956320170817; Wed, 8 Aug 2018 00:43:32 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EF747308402D; Wed, 8 Aug 2018 07:43:30 +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 B3B7765954; Wed, 8 Aug 2018 07:43: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 4F8853FC9D; Wed, 8 Aug 2018 07:43:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787hNuM005509 for ; Wed, 8 Aug 2018 03:43:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 599D5608F2; Wed, 8 Aug 2018 07:43:23 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 51593608E0 for ; Wed, 8 Aug 2018 07:43:23 +0000 (UTC) Received: from mail-pl0-f49.google.com (mail-pl0-f49.google.com [209.85.160.49]) (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 58551307D853 for ; Wed, 8 Aug 2018 07:43:22 +0000 (UTC) Received: by mail-pl0-f49.google.com with SMTP id ba4-v6so647751plb.11 for ; Wed, 08 Aug 2018 00:43:22 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:21 -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=3rBn7F42VIgSEAsQ5noaxMLwsf2x6yeWQZ8PK6z/51o=; b=CBG7X8WR6T5+Gm/Z8ZzUT4uRcSge3dRARKl7sgJI3hdSOcyRz3T2hnP7/PgoAAalQA yR0e/0mirY9nNDM70vLL9huVQwMQVQKHBzCSUmBZLDBnhE3kBTACMErqm83AGzuIzpaW 551Jg2hgOwdeVjCgrZJ1WfeNEwk3cNxYqCk2v7WOeRIJec0rH2bz/GD61Se/o9EP0/5V 4DNhQInSUleztYDMt+lduHUcNNFPW85UH99hAZ4tH5dSyjXf3V/EJxpfhdDLkn2z00T8 NITtjQ71oCNr4F8jAGKaKyja8KDHSBA7O5ZvapaNZylaP4r9VTHXJo946NHo5nMeiAhW FJQg== 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=3rBn7F42VIgSEAsQ5noaxMLwsf2x6yeWQZ8PK6z/51o=; b=h54lqnjnoFOu4sUjj5THBolaiBJZ88eLz/UreZit3GipTWv7Ms6KYprOjX5mCAXFDZ eurBfrggVS3yggZftQxMq6ncGKkmWMMEx5PpJtiVHCTketFfTThNckvtmJ7eGGxYMh5S xr5dkDmUqy6pCIMHN2nCURruYTCwSKIbpl+7QQEph8vRQAPIlA4YDXbszpyWIUnDXoxN QZLqtOumNqZqEv7x76lP1uzDQv17LqbbOZHyhfbuSpa1FoZ1crYapGbPVIbpIvkB3gY1 TfTzgyCDu2Y2M8TqN9+XWZvVnlKC8FNZK2rRaL3v7SfVTKfFPluop+EGd3ZhV6+P+XgN 63kA== X-Gm-Message-State: AOUpUlER4BTNVv9p/GDZsnkuK+sOzeTU5UXdatPCL3pNp6C5Ww/k18Iq Yg68XHNtKtmc+MJvnkcP5PChmyFU X-Google-Smtp-Source: AA+uWPwZ4WbNqHxPfJDeAUETVyb7c+KPY2BsZMxmOXXernJYGCisA8wFegZY//g3tKMOHjlsJk6XFQ== X-Received: by 2002:a17:902:24c7:: with SMTP id l7-v6mr1517194plg.170.1533714201593; Wed, 08 Aug 2018 00:43:21 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:33 +0530 Message-Id: <1533501842-24503-7-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-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.48]); Wed, 08 Aug 2018 07:43:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 08 Aug 2018 07:43:22 +0000 (UTC) for IP:'209.85.160.49' DOMAIN:'mail-pl0-f49.google.com' HELO:'mail-pl0-f49.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.11 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.160.49 mail-pl0-f49.google.com 209.85.160.49 mail-pl0-f49.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 06/35] util: netdevbridge: use VIR_AUTOFREE instead of VIR_FREE for scalar 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 08 Aug 2018 07:43:31 +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_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virnetdevbridge.c | 46 ++++++++++++++++--------------------------= ---- 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c index e46ac35..fe3697b 100644 --- a/src/util/virnetdevbridge.c +++ b/src/util/virnetdevbridge.c @@ -126,8 +126,7 @@ static int virNetDevBridgeSet(const char *brname, int fd, /* control socket */ struct ifreq *ifr) /* pre-filled bridge= name */ { - char *path =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (virAsprintf(&path, SYSFS_NET_DIR "%s/bridge/%s", brname, paramname= ) < 0) return -1; @@ -138,7 +137,7 @@ static int virNetDevBridgeSet(const char *brname, if (virFileWriteStr(path, valuestr, 0) < 0) { virReportSystemError(errno, _("Unable to set bridge %s %s"), brname, = paramname); - goto cleanup; + return -1; } } else { unsigned long paramid; @@ -149,21 +148,18 @@ static int virNetDevBridgeSet(const char *brname, } else { virReportSystemError(EINVAL, _("Unable to set bridge %s %s"), brname, = paramname); - goto cleanup; + return -1; } unsigned long args[] =3D { paramid, value, 0, 0 }; ifr->ifr_data =3D (char*)&args; if (ioctl(fd, SIOCDEVPRIVATE, ifr) < 0) { virReportSystemError(errno, _("Unable to set bridge %s %s"), brname, = paramname); - goto cleanup; + return -1; } } =20 - ret =3D 0; - cleanup: - VIR_FREE(path); - return ret; + return 0; } =20 =20 @@ -171,16 +167,17 @@ static int virNetDevBridgeGet(const char *brname, const char *paramname, /* sysfs param name = */ unsigned long *value) /* current value */ { - char *path =3D NULL; int ret =3D -1; int fd =3D -1; struct ifreq ifr; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (virAsprintf(&path, SYSFS_NET_DIR "%s/bridge/%s", brname, paramname= ) < 0) return -1; =20 if (virFileExists(path)) { - char *valuestr; + VIR_AUTOFREE(char *) valuestr =3D NULL; + if (virFileReadAll(path, INT_BUFSIZE_BOUND(unsigned long), &valuestr) < 0) goto cleanup; @@ -189,10 +186,8 @@ static int virNetDevBridgeGet(const char *brname, virReportSystemError(EINVAL, _("Unable to get bridge %s %s"), brname, paramname); - VIR_FREE(valuestr); goto cleanup; } - VIR_FREE(valuestr); } else { struct __bridge_info info; unsigned long args[] =3D { BRCTL_GET_BRIDGE_INFO, (unsigned long)&= info, 0, 0 }; @@ -221,7 +216,6 @@ static int virNetDevBridgeGet(const char *brname, ret =3D 0; cleanup: VIR_FORCE_CLOSE(fd); - VIR_FREE(path); return ret; } #endif /* __linux__ */ @@ -233,9 +227,9 @@ virNetDevBridgePortSet(const char *brname, const char *paramname, unsigned long value) { - char *path =3D NULL; char valuestr[INT_BUFSIZE_BOUND(value)]; int ret =3D -1; + VIR_AUTOFREE(char *) path =3D NULL; =20 snprintf(valuestr, sizeof(valuestr), "%lu", value); =20 @@ -254,7 +248,6 @@ virNetDevBridgePortSet(const char *brname, brname, ifname, paramname, valuestr); } =20 - VIR_FREE(path); return ret; } =20 @@ -265,29 +258,24 @@ virNetDevBridgePortGet(const char *brname, const char *paramname, unsigned long *value) { - char *path =3D NULL; - char *valuestr =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) valuestr =3D NULL; =20 if (virAsprintf(&path, SYSFS_NET_DIR "%s/brif/%s/%s", brname, ifname, paramname) < 0) return -1; =20 if (virFileReadAll(path, INT_BUFSIZE_BOUND(unsigned long), &valuestr) = < 0) - goto cleanup; + return -1; =20 if (virStrToLong_ul(valuestr, NULL, 10, value) < 0) { virReportSystemError(EINVAL, _("Unable to get bridge %s port %s %s"), brname, ifname, paramname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(path); - VIR_FREE(valuestr); - return ret; + return 0; } =20 =20 @@ -430,12 +418,12 @@ virNetDevBridgeCreate(const char *brname) /* use a netlink RTM_NEWLINK message to create the bridge */ const char *type =3D "bridge"; int rc =3D -1; - struct nlmsghdr *resp =3D NULL; struct nlmsgerr *err; struct ifinfomsg ifinfo =3D { .ifi_family =3D AF_UNSPEC }; unsigned int recvbuflen; struct nl_msg *nl_msg; struct nlattr *linkinfo; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 nl_msg =3D nlmsg_alloc_simple(RTM_NEWLINK, NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL); @@ -495,7 +483,6 @@ virNetDevBridgeCreate(const char *brname) rc =3D 0; cleanup: nlmsg_free(nl_msg); - VIR_FREE(resp); return rc; =20 malformed_resp: @@ -1069,11 +1056,11 @@ virNetDevBridgeFDBAddDel(const virMacAddr *mac, con= st char *ifname, unsigned int flags, bool isAdd) { int ret =3D -1; - struct nlmsghdr *resp =3D NULL; struct nlmsgerr *err; unsigned int recvbuflen; struct nl_msg *nl_msg; struct ndmsg ndm =3D { .ndm_family =3D PF_BRIDGE, .ndm_state =3D NUD_N= OARP }; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 if (virNetDevGetIndex(ifname, &ndm.ndm_ifindex) < 0) return -1; @@ -1142,7 +1129,6 @@ virNetDevBridgeFDBAddDel(const virMacAddr *mac, const= char *ifname, ret =3D 0; cleanup: nlmsg_free(nl_msg); - VIR_FREE(resp); return ret; =20 malformed_resp: --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list