From nobody Wed Jul 16 12:28:20 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 15338179966941007.8798019934243; Thu, 9 Aug 2018 05:33:16 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 78A383082A40; Thu, 9 Aug 2018 12:33:14 +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 457B919030; Thu, 9 Aug 2018 12:33:14 +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 EB6ED4A465; Thu, 9 Aug 2018 12:33:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w79CWxhs000431 for ; Thu, 9 Aug 2018 08:32:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 254C5308332C; Thu, 9 Aug 2018 12:32:59 +0000 (UTC) Received: from mx1.redhat.com (ext-mx17.extmail.prod.ext.phx2.redhat.com [10.5.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1AB0A30001EF for ; Thu, 9 Aug 2018 12:32:55 +0000 (UTC) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) (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 77C7E300174F for ; Thu, 9 Aug 2018 12:32:54 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id a26-v6so2793796pfo.4 for ; Thu, 09 Aug 2018 05:32:54 -0700 (PDT) Received: from centos.localdomain ([49.33.163.55]) by smtp.gmail.com with ESMTPSA id j15-v6sm8649810pfn.52.2018.08.09.05.32.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 05:32:53 -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=ZUgES3xwcvbugH2YIRQSR8jQN+TaNaIRpzwQO/nWrTM=; b=bjjI+spDOM59hNns10lWuujjDKSFwJ6QmJ3iZDVjHAaYEzaFQQOOYvKSWwoYwhw7Bh qz1UBtH+FmEB4Tr9HnjmhSmig00AAmyWcpuUa34muGPV78hcToVjzqpTtELjSLmVbesY AuH2g2hvypRss/5ctdRquSPOcKrkuUS9uaVup6oPV35Lv/1gIx0HsURyBds8izIKHAY4 LSFXbyB6E3rR8DUg7NvNzreiCYONUMUzdxihZJwdsuwyIy50NGyoufFmlWfQFqipvjSn YjiJUvSAPX9zmdubnN5lp3iI7m2iHhzHQoFMvAexlegYfg1fC6LFfAKbws5lo8gk+Wss RtdA== 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=ZUgES3xwcvbugH2YIRQSR8jQN+TaNaIRpzwQO/nWrTM=; b=rDwKJBULiMwa/ZemYAjSg6RZSr82jnw3+JLBCoGL9zPZ9a9LQEbELi1a8C76/U6N1P GeqsMLsivnv7t5LuruQ5O+Mk5iU+4uLhMVbhd5uqkWvwyIT/RG2aKWZ9tlEDx6d1qXmO G1BfQA2/EzA50fhZoPAY286nVkqs3vbsviWGOFrcdhDZkPMlVEq5bkEL08Yo+fYH6BPJ Aiks4ve7kp920cFM8ObKwkeweOl4pY2fCzG38TPFCYerTPOuKGyuI5XU5UvFO/caH1MF PoowrdWDuRDB94m53iSNUjjZfrv1s3j+DGByvUlUxNll3eG8Zh2S5DjvW6giFLJg4Wtz 3nBw== X-Gm-Message-State: AOUpUlERDgi2kmIOn6Zp4sFp5RYw145lMAuIk8W/PQDKMPTgg8KRKqhX k5XsDpzPTvcJ9izB2wpXUO8E1sY8 X-Google-Smtp-Source: AA+uWPwf7+7V+ufj7liYRyBb/o/rGsS62wUq2Q594fcqOqpc0Z/1v1IWS8NSG45ll4hvW7eRX/rrEA== X-Received: by 2002:a63:2359:: with SMTP id u25-v6mr2046407pgm.220.1533817973707; Thu, 09 Aug 2018 05:32:53 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Thu, 9 Aug 2018 09:42:12 +0530 Message-Id: <1533787939-28634-5-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.46]); Thu, 09 Aug 2018 12:32:54 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 09 Aug 2018 12:32:54 +0000 (UTC) for IP:'209.85.210.193' DOMAIN:'mail-pf1-f193.google.com' HELO:'mail-pf1-f193.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.973 (DATE_IN_PAST_06_12, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.210.193 mail-pf1-f193.google.com 209.85.210.193 mail-pf1-f193.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 04/11] util: netlink: 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 09 Aug 2018 12:33:15 +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/virnetlink.c | 72 ++++++++++++++++++++---------------------------= ---- 1 file changed, 28 insertions(+), 44 deletions(-) diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index fcdc09d..66e80e2 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -297,15 +297,16 @@ int virNetlinkCommand(struct nl_msg *nl_msg, uint32_t src_pid, uint32_t dst_pid, unsigned int protocol, unsigned int groups) { - int ret =3D -1; struct sockaddr_nl nladdr =3D { .nl_family =3D AF_NETLINK, .nl_pid =3D dst_pid, .nl_groups =3D 0, }; struct pollfd fds[1]; - VIR_AUTOPTR(virNetlinkHandle) nlhandle =3D NULL; int len =3D 0; + VIR_AUTOPTR(virNetlinkHandle) nlhandle =3D NULL; + + *respbuflen =3D 0; =20 memset(fds, 0, sizeof(fds)); =20 @@ -324,15 +325,12 @@ int virNetlinkCommand(struct nl_msg *nl_msg, goto cleanup; } =20 - ret =3D 0; *respbuflen =3D len; - cleanup: - if (ret < 0) { - *resp =3D NULL; - *respbuflen =3D 0; - } + return 0; =20 - return ret; + cleanup: + *resp =3D NULL; + return -1; } =20 int @@ -409,7 +407,7 @@ virNetlinkDumpLink(const char *ifname, int ifindex, .ifi_index =3D ifindex }; unsigned int recvbuflen; - struct nl_msg *nl_msg; + VIR_AUTOPTR(virNlMsg) nl_msg =3D NULL; VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 *nlData =3D NULL; @@ -450,7 +448,7 @@ virNetlinkDumpLink(const char *ifname, int ifindex, =20 if (virNetlinkCommand(nl_msg, &resp, &recvbuflen, src_pid, dst_pid, NETLINK_ROUTE, 0) < 0) - goto cleanup; + return -1; =20 if (recvbuflen < NLMSG_LENGTH(0) || resp =3D=3D NULL) goto malformed_resp; @@ -465,7 +463,7 @@ virNetlinkDumpLink(const char *ifname, int ifindex, virReportSystemError(-err->error, _("error dumping %s (%d) interface"), ifname, ifindex); - goto cleanup; + return -1; } break; =20 @@ -482,21 +480,17 @@ virNetlinkDumpLink(const char *ifname, int ifindex, } =20 VIR_STEAL_PTR(*nlData, resp); - rc =3D 0; - - cleanup: - nlmsg_free(nl_msg); - return rc; + return 0; =20 malformed_resp: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed netlink response message")); - goto cleanup; + return rc; =20 buffer_too_small: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("allocated netlink buffer is too small")); - goto cleanup; + return rc; } =20 =20 @@ -518,11 +512,10 @@ virNetlinkDumpLink(const char *ifname, int ifindex, int virNetlinkDelLink(const char *ifname, virNetlinkDelLinkFallback fallback) { - int rc =3D -1; struct nlmsgerr *err; struct ifinfomsg ifinfo =3D { .ifi_family =3D AF_UNSPEC }; unsigned int recvbuflen; - struct nl_msg *nl_msg; + VIR_AUTOPTR(virNlMsg) nl_msg =3D NULL; VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 nl_msg =3D nlmsg_alloc_simple(RTM_DELLINK, @@ -540,7 +533,7 @@ virNetlinkDelLink(const char *ifname, virNetlinkDelLink= Fallback fallback) =20 if (virNetlinkCommand(nl_msg, &resp, &recvbuflen, 0, 0, NETLINK_ROUTE, 0) < 0) { - goto cleanup; + return -1; } =20 if (recvbuflen < NLMSG_LENGTH(0) || resp =3D=3D NULL) @@ -552,15 +545,14 @@ virNetlinkDelLink(const char *ifname, virNetlinkDelLi= nkFallback fallback) if (resp->nlmsg_len < NLMSG_LENGTH(sizeof(*err))) goto malformed_resp; =20 - if (-err->error =3D=3D EOPNOTSUPP && fallback) { - rc =3D fallback(ifname); - goto cleanup; - } + if (-err->error =3D=3D EOPNOTSUPP && fallback) + return fallback(ifname); + if (err->error) { virReportSystemError(-err->error, _("error destroying network device %s"), ifname); - goto cleanup; + return -1; } break; =20 @@ -571,20 +563,17 @@ virNetlinkDelLink(const char *ifname, virNetlinkDelLi= nkFallback fallback) goto malformed_resp; } =20 - rc =3D 0; - cleanup: - nlmsg_free(nl_msg); - return rc; + return 0; =20 malformed_resp: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed netlink response message")); - goto cleanup; + return -1; =20 buffer_too_small: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("allocated netlink buffer is too small")); - goto cleanup; + return -1; } =20 /** @@ -605,13 +594,12 @@ virNetlinkDelLink(const char *ifname, virNetlinkDelLi= nkFallback fallback) int virNetlinkGetNeighbor(void **nlData, uint32_t src_pid, uint32_t dst_pid) { - int rc =3D -1; struct nlmsgerr *err; struct ndmsg ndinfo =3D { .ndm_family =3D AF_UNSPEC, }; unsigned int recvbuflen; - struct nl_msg *nl_msg; + VIR_AUTOPTR(virNlMsg) nl_msg =3D NULL; VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 *nlData =3D NULL; @@ -628,7 +616,7 @@ virNetlinkGetNeighbor(void **nlData, uint32_t src_pid, = uint32_t dst_pid) =20 if (virNetlinkCommand(nl_msg, &resp, &recvbuflen, src_pid, dst_pid, NETLINK_ROUTE, 0) < 0) - goto cleanup; + return -1; =20 if (recvbuflen < NLMSG_LENGTH(0) || resp =3D=3D NULL) goto malformed_resp; @@ -642,7 +630,7 @@ virNetlinkGetNeighbor(void **nlData, uint32_t src_pid, = uint32_t dst_pid) if (err->error) { virReportSystemError(-err->error, "%s", _("error dumping")); - goto cleanup; + return -1; } break; =20 @@ -654,21 +642,17 @@ virNetlinkGetNeighbor(void **nlData, uint32_t src_pid= , uint32_t dst_pid) } =20 VIR_STEAL_PTR(*nlData, resp); - rc =3D recvbuflen; - - cleanup: - nlmsg_free(nl_msg); - return rc; + return recvbuflen; =20 malformed_resp: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed netlink response message")); - goto cleanup; + return -1; =20 buffer_too_small: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("allocated netlink buffer is too small")); - goto cleanup; + return -1; } =20 int --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list