From nobody Sat May 4 12:32:44 2024 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 1533817990562284.47794795792777; Thu, 9 Aug 2018 05:33:10 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 06DA1308214F; Thu, 9 Aug 2018 12:33:08 +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 C22FC2010CCC; Thu, 9 Aug 2018 12:33:07 +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 7565518037F1; Thu, 9 Aug 2018 12:33:07 +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 w79CWpKx000393 for ; Thu, 9 Aug 2018 08:32:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id C694D60C11; Thu, 9 Aug 2018 12:32:51 +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 BD55F60A9E for ; Thu, 9 Aug 2018 12:32:49 +0000 (UTC) Received: from mail-pl0-f54.google.com (mail-pl0-f54.google.com [209.85.160.54]) (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 529FC300174D for ; Thu, 9 Aug 2018 12:32:48 +0000 (UTC) Received: by mail-pl0-f54.google.com with SMTP id j8-v6so2494151pll.12 for ; Thu, 09 Aug 2018 05:32:48 -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.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 05:32:47 -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=IAFar5sqtQrMVCQwysqlH0F1aYxj1WLkhCIbAODATZs=; b=k9I1FIKFM59kD5N5mPA1vc3z+7EeUn7vb0ruONGgakjuSy61OF21DtmDIfl9t0lNkY 4ggdbGE9RQqrhFuiXojzSMcYxE+pQtqoa5+yuU0hRwZzrNx8evPthV8ADtjDr2Wj0nEA LHk7aV9UqIo/g/U4nMFaW4ZHid4pcfsX9+nXfmQyfrKJu5U1akFOhkP6OcliarIfm/rI 6Sbh4XTMsIAT/YAmt1nvz0iHc52Cz7/EXgZeXOEihYalCbuW8g0ufE7H4v1VhpoUfQ8+ lelCN0oc8cqK3wW5xyGd9oZVboMfrN5Ov32kBhFit8ERWBrzwfzOmeOMknlRDPlW/Tc3 Jz3A== 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=IAFar5sqtQrMVCQwysqlH0F1aYxj1WLkhCIbAODATZs=; b=hQUyA417oe136W/87sgWwP3fBweu0KOYHEIEzVIMASZiHqLOhNqsmmNIR/oG3kiO24 rUFWQU5WbS4JH9WR3CewPzkBJpmMWOMBYivksaRkRxTlLilwG1QEcYNxf/5euUwilo5e TVyJV9KHzYafKTX0Ke+sn9VZgmoEavwe6iOaS3sldncuakspCtTviA+kHXz5zFBTuxXt msMd+LjnLXjsHQhd3yzAK7x1yGW8lAX0E1glkluJ7/7xfxMTsHZPvVWx0NRivUk0Exvh OSj0KgWXwfoFQZlGYBBNMChYwerdBUXyRJYhu/G5pMrkQSbjrMBvGI3I2RsfkW9PC7E+ I2Iw== X-Gm-Message-State: AOUpUlFUs58SzXImiBOk7Yfxd/o41dKxrVhbZ4rbS1byIjxRJKGupGKX LE3J17NCqRg6Y4Xlin5mrENJKWzY X-Google-Smtp-Source: AA+uWPxIZt+rH2yI1irgeOUAlNqvXyFT2WZO1LHL95i5lUcIZr6tIaHHWffJAMMvYlpI7bdMBHdymw== X-Received: by 2002:a17:902:1703:: with SMTP id i3-v6mr1884002pli.263.1533817967559; Thu, 09 Aug 2018 05:32:47 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Thu, 9 Aug 2018 09:42:09 +0530 Message-Id: <1533787939-28634-2-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:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 09 Aug 2018 12:32:48 +0000 (UTC) for IP:'209.85.160.54' DOMAIN:'mail-pl0-f54.google.com' HELO:'mail-pl0-f54.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.160.54 mail-pl0-f54.google.com 209.85.160.54 mail-pl0-f54.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 01/11] util: iscsi: 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.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 09 Aug 2018 12:33:08 +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" Add another usage for VIR_AUTOFREE macro which was left in the commit ec3e878, thereby dropping a VIR_FREE call and and a cleanup section. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/viriscsi.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c index c805ffc..cf07968 100644 --- a/src/util/viriscsi.c +++ b/src/util/viriscsi.c @@ -208,9 +208,10 @@ static int virStorageBackendCreateIfaceIQN(const char *initiatoriqn, char **ifacename) { - int ret =3D -1, exitstatus =3D -1; + int exitstatus =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; + VIR_AUTOFREE(char *) iface_name =3D NULL; VIR_AUTOFREE(char *) temp_ifacename =3D NULL; - VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (virAsprintf(&temp_ifacename, "libvirt-iface-%08llx", @@ -233,7 +234,7 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriq= n, virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to run command '%s' to create new iscsi i= nterface"), ISCSIADM); - goto cleanup; + return -1; } virCommandFree(cmd); =20 @@ -252,26 +253,23 @@ virStorageBackendCreateIfaceIQN(const char *initiator= iqn, virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to run command '%s' to update iscsi inter= face with IQN '%s'"), ISCSIADM, initiatoriqn); - goto cleanup; + return -1; } =20 /* Check again to make sure the interface was created. */ - if (virStorageBackendIQNFound(initiatoriqn, ifacename) !=3D IQN_FOUND)= { + if (virStorageBackendIQNFound(initiatoriqn, &iface_name) !=3D IQN_FOUN= D) { VIR_DEBUG("Failed to find interface '%s' with IQN '%s' " "after attempting to create it", &temp_ifacename[0], initiatoriqn); - goto cleanup; + return -1; } else { VIR_DEBUG("Interface '%s' with IQN '%s' was created successfully", - *ifacename, initiatoriqn); + iface_name, initiatoriqn); } =20 - ret =3D 0; + VIR_STEAL_PTR(*ifacename, iface_name); =20 - cleanup: - if (ret !=3D 0) - VIR_FREE(*ifacename); - return ret; + return 0; } =20 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 12:32:44 2024 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 153381798028691.20828637531963; Thu, 9 Aug 2018 05:33:00 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E365B3001773; Thu, 9 Aug 2018 12:32:57 +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 135C52010CB5; Thu, 9 Aug 2018 12:32:57 +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 54F274A460; Thu, 9 Aug 2018 12:32:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w79CWsF0000403 for ; Thu, 9 Aug 2018 08:32:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id C24CDCB184; Thu, 9 Aug 2018 12:32:54 +0000 (UTC) Received: from mx1.redhat.com (ext-mx13.extmail.prod.ext.phx2.redhat.com [10.5.110.42]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BB2A1CDE07 for ; Thu, 9 Aug 2018 12:32:51 +0000 (UTC) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) (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 D4E233082144 for ; Thu, 9 Aug 2018 12:32:50 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id a11-v6so2692938pgw.6 for ; Thu, 09 Aug 2018 05:32:50 -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.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 05:32:49 -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=gmUAJdX5QR/JCkWqVyblnYbFfiGNlSZJhy89z9ruqls=; b=hTY0xRXHaT+0KFIfUIPIHDAVIMG211IvVpQWXMVaivIzzfjY7OWVqGE2OxHaObJLV5 bZg4qbQjHcrtS6uDCclQu0stau79EMcqcrjI+46G4RffIVU1CteRvjzqkzmSxIAfidEU qExyprp9V6vgQNzAG15YKGStzslAxa1rZMZQV2ehDoZ6Yk0zd6O6NzmtePuvHJi1qeME Px1BALJOa7tZdpxofQgvVIy83ScCIODtSfsvCzeCP0SdKLjrgiL2URErukyHG6n4P4Ef ams7jZ4oepTUjd32RGV16TyQLmQdxfDHSq13tpQ/65Fheki6ibo4dfyIH7YV3wKmK5Hu fmXg== 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=gmUAJdX5QR/JCkWqVyblnYbFfiGNlSZJhy89z9ruqls=; b=iFMdmuoeYIuikBSGcm6FLfTvkoMM4ybHAeS3p12LcktWo0zY/ExjsMvCrpCeVZlxmb mQJuyvHD/iL/zI2EISDT19XHNp8iIA0c8LMdg+NQDue4l/9OEN4UcedUmjb10s9tWWKE rnvQbFKOyTSgy+7HMX0XwTv2Jn3ieNTQ88S1vEsP9ZY0qxG3OI5WmkVh3JnCCr8pfhOI G82TMEy13BCWiF5H7FNAjBQdZXfguhFYXa4CHTCZbtsvTSVFo5ZrgO/6WiT0o9vsNe+L QOuXCix+WAUvqE8jHPVx8hGXHavALpzfAqofpw12jOmbzNv67jWoAt9qmKvcV0wAKXLD OpAQ== X-Gm-Message-State: AOUpUlFC2JoWkHkFs8fUWoXd373E+wTujORxC/M/7kMSI9Z4+YK8zM5F ARHuaQ1T2V97MYyCm9m3GV6+A21d X-Google-Smtp-Source: AA+uWPyheApl0EWw419V6JTumcS1l1q8doulNxhvcgl6JNl4ZAScd0qxh02YZeM660fazgQXrj4Ghg== X-Received: by 2002:a63:d613:: with SMTP id q19-v6mr1982190pgg.327.1533817970122; Thu, 09 Aug 2018 05:32:50 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Thu, 9 Aug 2018 09:42:10 +0530 Message-Id: <1533787939-28634-3-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.42]); Thu, 09 Aug 2018 12:32:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 09 Aug 2018 12:32:50 +0000 (UTC) for IP:'209.85.215.194' DOMAIN:'mail-pg1-f194.google.com' HELO:'mail-pg1-f194.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.215.194 mail-pg1-f194.google.com 209.85.215.194 mail-pg1-f194.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.42 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 02/11] util: netlink: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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.84 on 10.5.11.25 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:58 +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" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. This commit also typedefs virNlMsg to struct nl_msg type for use with the cleanup macros. When a variable of type virNlMsg * is declared using VIR_AUTOPTR, the function nlmsg_free will be run automatically on it when it goes out of scope. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virnetlink.c | 1 - src/util/virnetlink.h | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index 162efe6..ecf62c9 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -38,7 +38,6 @@ #include "virnetlink.h" #include "virnetdev.h" #include "virlog.h" -#include "viralloc.h" #include "virthread.h" #include "virmacaddr.h" #include "virerror.h" diff --git a/src/util/virnetlink.h b/src/util/virnetlink.h index 2a9de0a..8ebeab8 100644 --- a/src/util/virnetlink.h +++ b/src/util/virnetlink.h @@ -22,6 +22,7 @@ =20 # include "internal.h" # include "virmacaddr.h" +# include "viralloc.h" =20 # if defined(__linux__) && defined(HAVE_LIBNL) =20 @@ -44,6 +45,8 @@ struct nlmsghdr; =20 # endif /* __linux__ */ =20 +typedef struct nl_msg virNlMsg; + int virNetlinkStartup(void); void virNetlinkShutdown(void); =20 @@ -123,4 +126,6 @@ int virNetlinkEventAddClient(virNetlinkEventHandleCallb= ack handleCB, int virNetlinkEventRemoveClient(int watch, const virMacAddr *macaddr, unsigned int protocol); =20 +VIR_DEFINE_AUTOPTR_FUNC(virNlMsg, nlmsg_free) + #endif /* __VIR_NETLINK_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 12:32:44 2024 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 1533817990238768.0230782649958; Thu, 9 Aug 2018 05:33:10 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 1E0EA81E04; Thu, 9 Aug 2018 12:33:08 +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 E1B2D1001940; Thu, 9 Aug 2018 12:33:07 +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 95C8418037F0; Thu, 9 Aug 2018 12:33:07 +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 w79CWv51000414 for ; Thu, 9 Aug 2018 08:32:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id F2C8660C80; Thu, 9 Aug 2018 12:32:56 +0000 (UTC) Received: from mx1.redhat.com (ext-mx18.extmail.prod.ext.phx2.redhat.com [10.5.110.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DFF0A60C11 for ; Thu, 9 Aug 2018 12:32:54 +0000 (UTC) Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 2BA28307B974 for ; Thu, 9 Aug 2018 12:32:53 +0000 (UTC) Received: by mail-pf1-f169.google.com with SMTP id i26-v6so2776517pfo.12 for ; Thu, 09 Aug 2018 05:32:53 -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.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 05:32:51 -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=c7yGoGYvSNVtG4dYDZFfYgVTfk4ktPqvLfXNKwZuYHs=; b=brQRDcoDKn7k1knXuXNHNjhxy5RQTucKVtcP7LKqwYlnk5FwzkuCMwPrmLQjekk3mu fc9GTeWTye2PY0fr8EczxU7wFieFhwJheWrV2mufjfVNMH9AGIhnYFiKx5GBeTGVP1yY 4BzuCRnlChY1Yk/bEsuLTp1G/1Yh/untzsNQIFVg3Nq7n/1jWcI1JA6K8ml67tdzB/nq 4bcWcYZVmUZPpHwBfRbKL5IY7mp73mtcZrqEfukMX1a01trdhaxEoAd7u6995tJ/if3p HxoAgmqM9Mp2JixK2UzltQHGMB5x4nlKyJC/v5GiysNCnzc9gQV6xcQ+Li/CAP37jeSY zu5g== 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=c7yGoGYvSNVtG4dYDZFfYgVTfk4ktPqvLfXNKwZuYHs=; b=J3kSYdXLIRICH3CSY+MMsA1HkQDT6oO5HhkOfGKBSVIt9nzCAq9qZrYPZiUW8awZBJ 7AHtGYHbw1dDPJ+t344DzMvwyu+YlOca6g4nUcrZITX9U5xBIoJR3E4o0MwG+oTyiqEj RhkJEjmOZFvoo53i9iBZLl8omKIdiVeoS4OfBUpzqlbdWUFoHke7QRUMk7wSjDnLsmkC RMoqcWH1yYxA3AkZmO9PfBtc9NM1CBgRDBMSHNJEWqbUSX3Pd+OEXhOWCj3QRGot19bC cULZfYqZKxG+H4OW7ribwyiWHVBEetgDc+/RgpqThZfIQHxg6KT/g51dqUuZJpV+ZvGg hN9w== X-Gm-Message-State: AOUpUlFuVA70809wfdzYL62dyV+SYO856TB9RVJg5Ui1retsHqca7J8c A4Dh+BRSmHR/y+s2qb2LdazBbURt X-Google-Smtp-Source: AA+uWPzm7JOFEoYTyJd8Q95Biqd2kZ9AEMc8tQfrdjiFdpK2AILKdp40sCN4UibglmRyb6hhDyHkTA== X-Received: by 2002:a63:6441:: with SMTP id y62-v6mr2001321pgb.240.1533817971847; Thu, 09 Aug 2018 05:32:51 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Thu, 9 Aug 2018 09:42:11 +0530 Message-Id: <1533787939-28634-4-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.47]); Thu, 09 Aug 2018 12:32:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 09 Aug 2018 12:32:53 +0000 (UTC) for IP:'209.85.210.169' DOMAIN:'mail-pf1-f169.google.com' HELO:'mail-pf1-f169.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.169 mail-pf1-f169.google.com 209.85.210.169 mail-pf1-f169.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.47 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 03/11] util: netlink: 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 09 Aug 2018 12:33:08 +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 Reviewed-by: Erik Skultety --- src/util/virnetlink.c | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index ecf62c9..fcdc09d 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -342,10 +342,8 @@ virNetlinkDumpCommand(struct nl_msg *nl_msg, unsigned int protocol, unsigned int groups, void *opaque) { - int ret =3D -1; bool end =3D false; int len =3D 0; - struct nlmsghdr *resp =3D NULL; struct nlmsghdr *msg =3D NULL; =20 struct sockaddr_nl nladdr =3D { @@ -357,9 +355,11 @@ virNetlinkDumpCommand(struct nl_msg *nl_msg, =20 if (!(nlhandle =3D virNetlinkSendRequest(nl_msg, src_pid, nladdr, protocol, groups))) - goto cleanup; + return -1; =20 while (!end) { + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; + len =3D nl_recv(nlhandle, &nladdr, (unsigned char **)&resp, NULL); VIR_WARNINGS_NO_CAST_ALIGN for (msg =3D resp; NLMSG_OK(msg, len); msg =3D NLMSG_NEXT(msg, len= )) { @@ -368,19 +368,14 @@ virNetlinkDumpCommand(struct nl_msg *nl_msg, end =3D true; =20 if (virNetlinkGetErrorCode(msg, len) < 0) - goto cleanup; + return -1; =20 if (callback(msg, opaque) < 0) - goto cleanup; + return -1; } - VIR_FREE(resp); } =20 - ret =3D 0; - - cleanup: - VIR_FREE(resp); - return ret; + return 0; } =20 /** @@ -408,7 +403,6 @@ virNetlinkDumpLink(const char *ifname, int ifindex, uint32_t src_pid, uint32_t dst_pid) { int rc =3D -1; - struct nlmsghdr *resp =3D NULL; struct nlmsgerr *err; struct ifinfomsg ifinfo =3D { .ifi_family =3D AF_UNSPEC, @@ -416,6 +410,9 @@ virNetlinkDumpLink(const char *ifname, int ifindex, }; unsigned int recvbuflen; struct nl_msg *nl_msg; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; + + *nlData =3D NULL; =20 if (ifname && ifindex <=3D 0 && virNetDevGetIndex(ifname, &ifindex) < = 0) return -1; @@ -483,12 +480,12 @@ virNetlinkDumpLink(const char *ifname, int ifindex, default: goto malformed_resp; } + + VIR_STEAL_PTR(*nlData, resp); rc =3D 0; + cleanup: nlmsg_free(nl_msg); - if (rc < 0) - VIR_FREE(resp); - *nlData =3D resp; return rc; =20 malformed_resp: @@ -522,11 +519,11 @@ int virNetlinkDelLink(const char *ifname, virNetlinkDelLinkFallback fallback) { 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; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 nl_msg =3D nlmsg_alloc_simple(RTM_DELLINK, NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL); @@ -577,7 +574,6 @@ virNetlinkDelLink(const char *ifname, virNetlinkDelLink= Fallback fallback) rc =3D 0; cleanup: nlmsg_free(nl_msg); - VIR_FREE(resp); return rc; =20 malformed_resp: @@ -610,13 +606,15 @@ int virNetlinkGetNeighbor(void **nlData, uint32_t src_pid, uint32_t dst_pid) { int rc =3D -1; - struct nlmsghdr *resp =3D NULL; struct nlmsgerr *err; struct ndmsg ndinfo =3D { .ndm_family =3D AF_UNSPEC, }; unsigned int recvbuflen; struct nl_msg *nl_msg; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; + + *nlData =3D NULL; =20 nl_msg =3D nlmsg_alloc_simple(RTM_GETNEIGH, NLM_F_DUMP | NLM_F_REQUEST= ); if (!nl_msg) { @@ -654,13 +652,12 @@ virNetlinkGetNeighbor(void **nlData, uint32_t src_pid= , uint32_t dst_pid) default: goto malformed_resp; } + + VIR_STEAL_PTR(*nlData, resp); rc =3D recvbuflen; =20 cleanup: nlmsg_free(nl_msg); - if (rc < 0) - VIR_FREE(resp); - *nlData =3D resp; return rc; =20 malformed_resp: @@ -766,12 +763,12 @@ virNetlinkEventCallback(int watch, void *opaque) { virNetlinkEventSrvPrivatePtr srv =3D opaque; - struct nlmsghdr *msg; struct sockaddr_nl peer; struct ucred *creds =3D NULL; size_t i; int length; bool handled =3D false; + VIR_AUTOFREE(struct nlmsghdr *) msg =3D NULL; =20 length =3D nl_recv(srv->netlinknh, &peer, (unsigned char **)&msg, &creds); @@ -801,7 +798,7 @@ virNetlinkEventCallback(int watch, =20 if (!handled) VIR_DEBUG("event not handled."); - VIR_FREE(msg); + virNetlinkEventServerUnlock(srv); } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 12:32:44 2024 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 From nobody Sat May 4 12:32:44 2024 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 1533817994729241.9687353838483; Thu, 9 Aug 2018 05:33:14 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 264263001C24; Thu, 9 Aug 2018 12:33:12 +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 E4CA63001A5F; Thu, 9 Aug 2018 12:33: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 9286118037F7; Thu, 9 Aug 2018 12:33:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w79CWw8b000420 for ; Thu, 9 Aug 2018 08:32:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3215BCAE67; Thu, 9 Aug 2018 12:32:58 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2BB2DCBA4E for ; Thu, 9 Aug 2018 12:32:58 +0000 (UTC) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) (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 14E714902D for ; Thu, 9 Aug 2018 12:32:57 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id x5-v6so2689228pgp.7 for ; Thu, 09 Aug 2018 05:32:57 -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.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 05:32:55 -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=nwcemGngK5e7DSyknKRjDcPMudWuXb4kQXdLt85Nu8RBP/TAs1xpMbkviTnBVv2BoE DiPckTcOK4TERb7Cnoanq0wd/RaT6/sbaYL/PTestPCFkhdFisShNKpmqdrNct4lFXZ/ KZsIG0pxqiZr1lyjR3d80Dm/gbzXdSr1aV+3pUhig794SqkOxqYxn32jApe4yIcDIWkB 4XqwZSzn42cUDV3I6t9xOfU/syguv++I+0zLqDOHuyVp8WKbSc2sxIDEB2p/I2L9NmfJ FYhoQ/6DcJg9kuTh4XlRsAioW8BD6GkUEl0rBrf51iDgU9BLdAA+MoqfiBcrV9pgXuwQ 8WyQ== 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=KbozsnhAKgYFyzwbWhTI7e6/8hAxh2ruoAFuFfxxNGWoQEq1tcGQ+uuCnaFiErzP6T +6RkSHlhWpvLQwKo8Bw1c9tFeY8izCDRH8Nj3qY5d2zQxway9+TtoUV5+zvyQFszd+mP ZET/1Gx2+6aTTU4f0Hbz0LfFFcW0uvaMLNadJ4I9OZ+5OHU4RjDJO7ptI9A03RhvsNdH ghgbCVljV1Sk9Og9dKL/JXW3vtlMPXgv3stufi4x4xJn6Sj5aPP/9OVcokwSD/IbA6Pi 2Bm1HVJvNAZABDlnoN7JWPYNSLj6RIZlpgXFH4ABYd8bkZMeDhOAVXNDKWUft9vFC9KJ wsPw== X-Gm-Message-State: AOUpUlHgoyadsai3+X3Ith35cnk+qOAzx9jilGSG4poAU0gcKk3S9ELv k/f027YgDAUCKC/xrcd7DXrURs7t X-Google-Smtp-Source: AA+uWPw2YTQkXMsANBIZcNBrDarMW8V6lkB+/BfSlZ4k1+Cg2AsJMzz+AnzcaQHdNqAvt9a+GI/eUQ== X-Received: by 2002:a63:6b86:: with SMTP id g128-v6mr2057159pgc.344.1533817976145; Thu, 09 Aug 2018 05:32:56 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Thu, 9 Aug 2018 09:42:13 +0530 Message-Id: <1533787939-28634-6-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.38]); Thu, 09 Aug 2018 12:32:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 09 Aug 2018 12:32:57 +0000 (UTC) for IP:'209.85.215.196' DOMAIN:'mail-pg1-f196.google.com' HELO:'mail-pg1-f196.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.215.196 mail-pg1-f196.google.com 209.85.215.196 mail-pg1-f196.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 05/11] 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.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 09 Aug 2018 12:33:12 +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 Reviewed-by: Erik Skultety --- 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 From nobody Sat May 4 12:32:44 2024 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 1533818001430646.5946630349652; Thu, 9 Aug 2018 05:33:21 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 6C3E8307D870; Thu, 9 Aug 2018 12:33:18 +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 300FC67141; Thu, 9 Aug 2018 12:33:18 +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 DC9A318037FC; Thu, 9 Aug 2018 12:33:17 +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 w79CX0uq000441 for ; Thu, 9 Aug 2018 08:33:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8900F60A9E; Thu, 9 Aug 2018 12:33:00 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7DB1C60C4C for ; Thu, 9 Aug 2018 12:33:00 +0000 (UTC) Received: from mail-pl0-f44.google.com (mail-pl0-f44.google.com [209.85.160.44]) (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 35D7D13A9A for ; Thu, 9 Aug 2018 12:32:59 +0000 (UTC) Received: by mail-pl0-f44.google.com with SMTP id d5-v6so2513313pll.4 for ; Thu, 09 Aug 2018 05:32:59 -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.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 05:32:57 -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=velbeesQ6GSKKAMIFvxPnSBhuabGcrN7cK8rGDYQSyg=; b=ZJY30uQvdS2/nQaiqw2wbiIjO6hNOJ3niU7kmRxhu1wpWdryIlCug30fOBs8HkIvTX sLXfZGPIqOczqP5wFMnYt0gjiqGketq6gFqGxsAcJaDMhRKvkI1BlzADR3hxy3wIlsf+ BgCtwVNyPOpeQ3HdnN5DGP5nFmyMyeHcjqhX3MCQPeEyduxsnhXObxZTknFuhMqdaz1h lE+59qG4n5eGXygoPdOZFjwQcss722up6pal40V8+Wq6gaTeO3TcgKa3j58kMp05WK6X /V8l5SpB3CggpykkKknH3Z2ewU3nmMyUgpnrCpHUJ7c3elqUhrBQfghRudGeWugcBpXf 60uQ== 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=velbeesQ6GSKKAMIFvxPnSBhuabGcrN7cK8rGDYQSyg=; b=PpLCMFpvkGcP6pYHwvxnX8moFKTIU2Dzw1UJ/R8lIPCfO+r3f642mwTMLmuQTfs66o spXhtLi0yXKMWpIMn4YHc0rp7dzg4SGH6d+Lnnr6MfCR1IRRa8Fqopx96uL/g1Wk5iQR oIB+PwFWKvYotpq+oyPyZ5rjJ7ne9EPcythcasNxH0yvzuXU941JPPsnP3GLZBziihgP N0Sx0dyjuF36oIzo2H5Xf6pQqjiu+KciLDDpSWsiM8j0qKQa8VCMrZZn/FfcII7XDLgz 4VExvqkcSr+dZluGUulsO5ZrEBDz2h8+3KQYit7K4Y6ok5ew2KN1nfW74C6QGIZ/yTzD /dPw== X-Gm-Message-State: AOUpUlE7ftVi77BAhkVthz3gyzRxqUCscwsHdYb+Jt90N2gQQ2zknmvh ZUhoMB25CSbzp5dE/Tb+UHdVOHLt X-Google-Smtp-Source: AA+uWPzO1nebEProTOoqijUN00qD0M+4fyYRgX6f/D2xXMbXJHipa84n6PR4vL1n4G0DFcnzLSlj9A== X-Received: by 2002:a17:902:b401:: with SMTP id x1-v6mr1936103plr.236.1533817978355; Thu, 09 Aug 2018 05:32:58 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Thu, 9 Aug 2018 09:42:14 +0530 Message-Id: <1533787939-28634-7-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.29]); Thu, 09 Aug 2018 12:32:59 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 09 Aug 2018 12:32:59 +0000 (UTC) for IP:'209.85.160.44' DOMAIN:'mail-pl0-f44.google.com' HELO:'mail-pl0-f44.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.160.44 mail-pl0-f44.google.com 209.85.160.44 mail-pl0-f44.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 06/11] util: netdevbridge: 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 09 Aug 2018 12:33:19 +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/virnetdevbridge.c | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c index fe3697b..089da78 100644 --- a/src/util/virnetdevbridge.c +++ b/src/util/virnetdevbridge.c @@ -417,12 +417,11 @@ virNetDevBridgeCreate(const char *brname) { /* use a netlink RTM_NEWLINK message to create the bridge */ const char *type =3D "bridge"; - int rc =3D -1; struct nlmsgerr *err; struct ifinfomsg ifinfo =3D { .ifi_family =3D AF_UNSPEC }; unsigned int recvbuflen; - struct nl_msg *nl_msg; struct nlattr *linkinfo; + VIR_AUTOPTR(virNlMsg) nl_msg =3D NULL; VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 nl_msg =3D nlmsg_alloc_simple(RTM_NEWLINK, @@ -444,7 +443,7 @@ virNetDevBridgeCreate(const char *brname) =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) @@ -462,15 +461,14 @@ virNetDevBridgeCreate(const char *brname) /* fallback to ioctl if netlink doesn't support creating * bridges */ - rc =3D virNetDevBridgeCreateWithIoctl(brname); - goto cleanup; + return virNetDevBridgeCreateWithIoctl(brname); } # endif =20 virReportSystemError(-err->error, _("error creating bridge interface %s"), brname); - goto cleanup; + return -1; } break; =20 @@ -480,19 +478,16 @@ virNetDevBridgeCreate(const char *brname) 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; buffer_too_small: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("allocated netlink buffer is too small")); - goto cleanup; + return -1; } =20 =20 @@ -1055,11 +1050,10 @@ static int virNetDevBridgeFDBAddDel(const virMacAddr *mac, const char *ifname, unsigned int flags, bool isAdd) { - int ret =3D -1; 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_AUTOPTR(virNlMsg) nl_msg =3D NULL; VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 if (virNetDevGetIndex(ifname, &ndm.ndm_ifindex) < 0) @@ -1103,7 +1097,7 @@ virNetDevBridgeFDBAddDel(const virMacAddr *mac, const= char *ifname, =20 if (virNetlinkCommand(nl_msg, &resp, &recvbuflen, 0, 0, NETLINK_ROUTE, 0) < 0) { - goto cleanup; + return -1; } if (recvbuflen < NLMSG_LENGTH(0) || resp =3D=3D NULL) goto malformed_resp; @@ -1116,7 +1110,7 @@ virNetDevBridgeFDBAddDel(const virMacAddr *mac, const= char *ifname, if (err->error) { virReportSystemError(-err->error, _("error adding fdb entry for %s"), ifnam= e); - goto cleanup; + return -1; } break; case NLMSG_DONE: @@ -1126,20 +1120,17 @@ virNetDevBridgeFDBAddDel(const virMacAddr *mac, con= st char *ifname, goto malformed_resp; } =20 - ret =3D 0; - cleanup: - nlmsg_free(nl_msg); - return ret; + 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 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 12:32:45 2024 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 1533818004401232.74574064667684; Thu, 9 Aug 2018 05:33:24 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7C94C80F7B; Thu, 9 Aug 2018 12:33:22 +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 3E26E2010D0C; Thu, 9 Aug 2018 12:33:22 +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 DDDFC18052E9; Thu, 9 Aug 2018 12:33:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w79CX4cA000457 for ; Thu, 9 Aug 2018 08:33:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2BBDE2010CC9; Thu, 9 Aug 2018 12:33:04 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1EA6E2010CC7 for ; Thu, 9 Aug 2018 12:33:04 +0000 (UTC) Received: from mail-pl0-f65.google.com (mail-pl0-f65.google.com [209.85.160.65]) (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 E9FAB80F7B for ; Thu, 9 Aug 2018 12:33:01 +0000 (UTC) Received: by mail-pl0-f65.google.com with SMTP id g6-v6so2500871plq.9 for ; Thu, 09 Aug 2018 05:33:01 -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.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 05:33:00 -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=IvOUKvCCL7Cdbs+GzFK5U2PS0yAn9SPfd+gTQBttqMk=; b=K8V1cXZrUUhyMMBtnYwgZ0F6NvYk37Y0jNCQNiYpUGP2H/k1QNPZhjnrTtRoYzeI7D TTzaxKYQq2akExbID2RIN8P6L+IKg8XJs7q2Vi+BNFF7pV5dXqzTiXee9YDJG+UDSuz6 xAdGnrVNBkv5Pev9e57+VI68RCYVnDJSgB792r8zl/Mzo3uSLOLAmVukMIAMywi6JTwg yDMcnDzfcOWMu7bH1AsbGgBSamS5YDfKV2vnMD0P0cDUZhcCdDlbRMuCpd23tQrhNQya 8CVwTPSJPtJukv2QvJHxYAh58l4WWMaNs5IFEhXNd2itIreNksbKBG6k8Q1Fcvqu8bGI gsgg== 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=IvOUKvCCL7Cdbs+GzFK5U2PS0yAn9SPfd+gTQBttqMk=; b=YLcr7udu5DNVsIvAWvNwYJHt+DR2bZgtBG5ylwF+EaWb/p75ZByTLBepCAJbA8hPlN /qCxpiYCec4SubgHnABLyVAAw3YaC6E154BRB88k5aBzX9YY+UsRU5vfCHXF3xUHEe63 THeXXirBOiixb6QBZc3EA2OGu463A0UdhZvHlzb8TBmJ2kb2gYl78kR+fZtnb0Ed/93g oej5uaXbxkDiLYwf5S0R6/YUvQKoMtqppbTaQ8rjZHbw0SwiuPNPcXrmtoN5N2pBtcxL AnYJwpsIp6gzwT366+5Hw9nmw400Jfr0+BilCTX4CUwTsna9fqnK2NPXcr54BV515fDE NW0g== X-Gm-Message-State: AOUpUlE1FTnxSKBF9O7jqk9DS8uOgzOFVXP9SYhrG+fgD/wwPlIyj1/+ RlsyNdTzVv5ry8Cg0TjA7VV46QI9 X-Google-Smtp-Source: AA+uWPzmCV40zHRbJIEWhsoIDs76O6c3WdOg0fYdHgqZi3qCKWXvsxKvaETdM1XfeWGnPjHZLAtcHw== X-Received: by 2002:a17:902:7803:: with SMTP id p3-v6mr1888754pll.119.1533817981054; Thu, 09 Aug 2018 05:33:01 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Thu, 9 Aug 2018 09:42:15 +0530 Message-Id: <1533787939-28634-8-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.27]); Thu, 09 Aug 2018 12:33:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 09 Aug 2018 12:33:02 +0000 (UTC) for IP:'209.85.160.65' DOMAIN:'mail-pl0-f65.google.com' HELO:'mail-pl0-f65.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.160.65 mail-pl0-f65.google.com 209.85.160.65 mail-pl0-f65.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 07/11] util: netdev: 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.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 09 Aug 2018 12:33:23 +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/virnetdev.c | 343 +++++++++++++++++++----------------------------= ---- 1 file changed, 125 insertions(+), 218 deletions(-) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 8eac419..edb7393 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -535,18 +535,17 @@ int virNetDevSetMTUFromDevice(const char *ifname, */ int virNetDevSetNamespace(const char *ifname, pid_t pidInNs) { - int ret =3D -1; - char *pid =3D NULL; - char *phy =3D NULL; - char *phy_path =3D NULL; int len; + VIR_AUTOFREE(char *) pid =3D NULL; + VIR_AUTOFREE(char *) phy =3D NULL; + VIR_AUTOFREE(char *) phy_path =3D NULL; =20 if (virAsprintf(&pid, "%lld", (long long) pidInNs) =3D=3D -1) return -1; =20 /* The 802.11 wireless devices only move together with their PHY. */ if (virNetDevSysfsFile(&phy_path, ifname, "phy80211/name") < 0) - goto cleanup; + return -1; =20 if ((len =3D virFileReadAllQuiet(phy_path, 1024, &phy)) <=3D 0) { /* Not a wireless device. */ @@ -556,7 +555,7 @@ int virNetDevSetNamespace(const char *ifname, pid_t pid= InNs) =20 argv[5] =3D pid; if (virRun(argv, NULL) < 0) - goto cleanup; + return -1; =20 } else { const char *argv[] =3D { @@ -569,15 +568,10 @@ int virNetDevSetNamespace(const char *ifname, pid_t p= idInNs) argv[2] =3D phy; argv[5] =3D pid; if (virRun(argv, NULL) < 0) - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(phy_path); - VIR_FREE(phy); - VIR_FREE(pid); - return ret; + return 0; } =20 #if defined(SIOCSIFNAME) && defined(HAVE_STRUCT_IFREQ) @@ -969,25 +963,21 @@ int virNetDevGetIndex(const char *ifname ATTRIBUTE_UN= USED, int virNetDevGetMaster(const char *ifname, char **master) { - int ret =3D -1; - void *nlData =3D NULL; struct nlattr *tb[IFLA_MAX + 1] =3D {NULL, }; + VIR_AUTOFREE(void *) nlData =3D NULL; =20 *master =3D NULL; =20 if (virNetlinkDumpLink(ifname, -1, &nlData, tb, 0, 0) < 0) - goto cleanup; + return -1; =20 if (tb[IFLA_MASTER]) { if (!(*master =3D virNetDevGetName(*(int *)RTA_DATA(tb[IFLA_MASTER= ])))) - goto cleanup; + return -1; } =20 VIR_DEBUG("IFLA_MASTER for %s is %s", ifname, *master ? *master : "(no= ne)"); - ret =3D 0; - cleanup: - VIR_FREE(nlData); - return ret; + return 0; } =20 =20 @@ -1168,39 +1158,33 @@ virNetDevSysfsDeviceFile(char **pf_sysfs_device_lin= k, const char *ifname, static bool virNetDevIsPCIDevice(const char *devpath) { - char *subsys_link =3D NULL; - char *abs_path =3D NULL; char *subsys =3D NULL; - bool ret =3D false; + VIR_AUTOFREE(char *) subsys_link =3D NULL; + VIR_AUTOFREE(char *) abs_path =3D NULL; =20 if (virAsprintf(&subsys_link, "%s/subsystem", devpath) < 0) return false; =20 if (!virFileExists(subsys_link)) - goto cleanup; + return false; =20 if (virFileResolveLink(subsys_link, &abs_path) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to resolve device subsystem symlink %s"), subsys_link); - goto cleanup; + return false; } =20 subsys =3D last_component(abs_path); - ret =3D STRPREFIX(subsys, "pci"); - - cleanup: - VIR_FREE(subsys_link); - VIR_FREE(abs_path); - return ret; + return STRPREFIX(subsys, "pci"); } =20 static virPCIDevicePtr virNetDevGetPCIDevice(const char *devName) { - char *vfSysfsDevicePath =3D NULL; virPCIDeviceAddressPtr vfPCIAddr =3D NULL; virPCIDevicePtr vfPCIDevice =3D NULL; + VIR_AUTOFREE(char *) vfSysfsDevicePath =3D NULL; =20 if (virNetDevSysfsFile(&vfSysfsDevicePath, devName, "device") < 0) goto cleanup; @@ -1216,7 +1200,6 @@ virNetDevGetPCIDevice(const char *devName) vfPCIAddr->slot, vfPCIAddr->function); =20 cleanup: - VIR_FREE(vfSysfsDevicePath); VIR_FREE(vfPCIAddr); =20 return vfPCIDevice; @@ -1241,25 +1224,20 @@ int virNetDevGetPhysPortID(const char *ifname, char **physPortID) { - int ret =3D -1; - char *physPortIDFile =3D NULL; + VIR_AUTOFREE(char *) physPortIDFile =3D NULL; =20 *physPortID =3D NULL; =20 if (virNetDevSysfsFile(&physPortIDFile, ifname, "phys_port_id") < 0) - goto cleanup; + return -1; =20 /* a failure to read just means the driver doesn't support - * phys_port_id, so set success now and ignore the return from - * virFileReadAllQuiet(). + * phys_port_id, so ignore the return from virFileReadAllQuiet() + * and return success. */ - ret =3D 0; - ignore_value(virFileReadAllQuiet(physPortIDFile, 1024, physPortID)); =20 - cleanup: - VIR_FREE(physPortIDFile); - return ret; + return 0; } =20 =20 @@ -1280,67 +1258,61 @@ virNetDevGetVirtualFunctions(const char *pfname, size_t *n_vfname, unsigned int *max_vfs) { - int ret =3D -1; size_t i; - char *pf_sysfs_device_link =3D NULL; - char *pci_sysfs_device_link =3D NULL; - char *pciConfigAddr =3D NULL; - char *pfPhysPortID =3D NULL; + VIR_AUTOFREE(char *) pf_sysfs_device_link =3D NULL; + VIR_AUTOFREE(char *) pci_sysfs_device_link =3D NULL; + VIR_AUTOFREE(char *) pciConfigAddr =3D NULL; + VIR_AUTOFREE(char *) pfPhysPortID =3D NULL; + VIR_AUTOFREE(char **) tmpVfname =3D NULL; + VIR_AUTOFREE(virPCIDeviceAddressPtr *) tmpVirtFns =3D NULL; =20 *virt_fns =3D NULL; *n_vfname =3D 0; *max_vfs =3D 0; =20 if (virNetDevGetPhysPortID(pfname, &pfPhysPortID) < 0) - goto cleanup; + return -1; =20 if (virNetDevSysfsFile(&pf_sysfs_device_link, pfname, "device") < 0) - goto cleanup; + return -1; =20 - if (virPCIGetVirtualFunctions(pf_sysfs_device_link, virt_fns, - n_vfname, max_vfs) < 0) - goto cleanup; + if (virPCIGetVirtualFunctions(pf_sysfs_device_link, &tmpVirtFns, + n_vfname, max_vfs) < 0) { + return -1; + } =20 - if (VIR_ALLOC_N(*vfname, *n_vfname) < 0) - goto cleanup; + if (VIR_ALLOC_N(tmpVfname, *n_vfname) < 0) + return -1; =20 for (i =3D 0; i < *n_vfname; i++) { - if (virPCIGetAddrString((*virt_fns)[i]->domain, - (*virt_fns)[i]->bus, - (*virt_fns)[i]->slot, - (*virt_fns)[i]->function, + if (virPCIGetAddrString(tmpVirtFns[i]->domain, + tmpVirtFns[i]->bus, + tmpVirtFns[i]->slot, + tmpVirtFns[i]->function, &pciConfigAddr) < 0) { virReportSystemError(ENOSYS, "%s", _("Failed to get PCI Config Address Strin= g")); - goto cleanup; + return -1; } if (virPCIGetSysfsFile(pciConfigAddr, &pci_sysfs_device_link) < 0)= { virReportSystemError(ENOSYS, "%s", _("Failed to get PCI SYSFS file")); - goto cleanup; + return -1; } =20 if (virPCIGetNetName(pci_sysfs_device_link, 0, - pfPhysPortID, &((*vfname)[i])) < 0) { - goto cleanup; + pfPhysPortID, &tmpVfname[i]) < 0) { + return -1; } =20 - if (!(*vfname)[i]) + if (!tmpVfname[i]) VIR_INFO("VF does not have an interface name"); } =20 - ret =3D 0; + VIR_STEAL_PTR(*vfname, tmpVfname); + VIR_STEAL_PTR(*virt_fns, tmpVirtFns); =20 - cleanup: - if (ret < 0) { - VIR_FREE(*vfname); - VIR_FREE(*virt_fns); - } - VIR_FREE(pfPhysPortID); - VIR_FREE(pf_sysfs_device_link); - VIR_FREE(pci_sysfs_device_link); - VIR_FREE(pciConfigAddr); - return ret; + return 0; } =20 /** @@ -1355,17 +1327,12 @@ virNetDevGetVirtualFunctions(const char *pfname, int virNetDevIsVirtualFunction(const char *ifname) { - char *if_sysfs_device_link =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) if_sysfs_device_link =3D NULL; =20 if (virNetDevSysfsFile(&if_sysfs_device_link, ifname, "device") < 0) - return ret; + return -1; =20 - ret =3D virPCIIsVirtualFunction(if_sysfs_device_link); - - VIR_FREE(if_sysfs_device_link); - - return ret; + return virPCIIsVirtualFunction(if_sysfs_device_link); } =20 /** @@ -1383,25 +1350,19 @@ int virNetDevGetVirtualFunctionIndex(const char *pfname, const char *vfname, int *vf_index) { - char *pf_sysfs_device_link =3D NULL, *vf_sysfs_device_link =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) pf_sysfs_device_link =3D NULL; + VIR_AUTOFREE(char *) vf_sysfs_device_link =3D NULL; =20 if (virNetDevSysfsFile(&pf_sysfs_device_link, pfname, "device") < 0) - return ret; + return -1; =20 - if (virNetDevSysfsFile(&vf_sysfs_device_link, vfname, "device") < 0) { - VIR_FREE(pf_sysfs_device_link); - return ret; - } + if (virNetDevSysfsFile(&vf_sysfs_device_link, vfname, "device") < 0) + return -1; =20 - ret =3D virPCIGetVirtualFunctionIndex(pf_sysfs_device_link, + return virPCIGetVirtualFunctionIndex(pf_sysfs_device_link, vf_sysfs_device_link, vf_index); =20 - VIR_FREE(pf_sysfs_device_link); - VIR_FREE(vf_sysfs_device_link); - - return ret; } =20 /** @@ -1417,19 +1378,18 @@ virNetDevGetVirtualFunctionIndex(const char *pfname= , const char *vfname, int virNetDevGetPhysicalFunction(const char *ifname, char **pfname) { - char *physfn_sysfs_path =3D NULL; - char *vfPhysPortID =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) physfn_sysfs_path =3D NULL; + VIR_AUTOFREE(char *) vfPhysPortID =3D NULL; =20 if (virNetDevGetPhysPortID(ifname, &vfPhysPortID) < 0) - goto cleanup; + return -1; =20 if (virNetDevSysfsDeviceFile(&physfn_sysfs_path, ifname, "physfn") < 0) - goto cleanup; + return -1; =20 if (virPCIGetNetName(physfn_sysfs_path, 0, vfPhysPortID, pfname) < 0) { - goto cleanup; + return -1; } =20 if (!*pfname) { @@ -1439,14 +1399,10 @@ virNetDevGetPhysicalFunction(const char *ifname, ch= ar **pfname) virReportError(VIR_ERR_INTERNAL_ERROR, _("The PF device for VF %s has no network device na= me"), ifname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(vfPhysPortID); - VIR_FREE(physfn_sysfs_path); - return ret; + return 0; } =20 =20 @@ -1470,26 +1426,25 @@ virNetDevGetPhysicalFunction(const char *ifname, ch= ar **pfname) int virNetDevPFGetVF(const char *pfname, int vf, char **vfname) { - char *virtfnName =3D NULL; - char *virtfnSysfsPath =3D NULL; - char *pfPhysPortID =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) virtfnName =3D NULL; + VIR_AUTOFREE(char *) virtfnSysfsPath =3D NULL; + VIR_AUTOFREE(char *) pfPhysPortID =3D NULL; =20 /* a VF may have multiple "ports", each one having its own netdev, * and each netdev having a different phys_port_id. Be sure we get * the VF netdev with a phys_port_id matchine that of pfname */ if (virNetDevGetPhysPortID(pfname, &pfPhysPortID) < 0) - goto cleanup; + return -1; =20 if (virAsprintf(&virtfnName, "virtfn%d", vf) < 0) - goto cleanup; + return -1; =20 /* this provides the path to the VF's directory in sysfs, * e.g. "/sys/class/net/enp2s0f0/virtfn3" */ if (virNetDevSysfsDeviceFile(&virtfnSysfsPath, pfname, virtfnName) < 0) - goto cleanup; + return -1; =20 /* and this gets the netdev name associated with it, which is a * directory entry in [virtfnSysfsPath]/net, @@ -1498,14 +1453,7 @@ virNetDevPFGetVF(const char *pfname, int vf, char **= vfname) * isn't bound to a netdev driver, it won't have a netdev name, * and vfname will be NULL). */ - ret =3D virPCIGetNetName(virtfnSysfsPath, 0, pfPhysPortID, vfname); - - cleanup: - VIR_FREE(virtfnName); - VIR_FREE(virtfnSysfsPath); - VIR_FREE(pfPhysPortID); - - return ret; + return virPCIGetNetName(virtfnSysfsPath, 0, pfPhysPortID, vfname); } =20 =20 @@ -1522,30 +1470,24 @@ int virNetDevGetVirtualFunctionInfo(const char *vfname, char **pfname, int *vf) { - char *pf_sysfs_path =3D NULL, *vf_sysfs_path =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) pf_sysfs_path =3D NULL; + VIR_AUTOFREE(char *) vf_sysfs_path =3D NULL; + VIR_AUTOFREE(char *) tmpPfname =3D NULL; =20 *pfname =3D NULL; =20 - if (virNetDevGetPhysicalFunction(vfname, pfname) < 0) - return ret; + if (virNetDevGetPhysicalFunction(vfname, &tmpPfname) < 0) + return -1; =20 - if (virNetDevSysfsFile(&pf_sysfs_path, *pfname, "device") < 0) - goto cleanup; + if (virNetDevSysfsFile(&pf_sysfs_path, tmpPfname, "device") < 0) + return -1; =20 if (virNetDevSysfsFile(&vf_sysfs_path, vfname, "device") < 0) - goto cleanup; + return -1; =20 - ret =3D virPCIGetVirtualFunctionIndex(pf_sysfs_path, vf_sysfs_path, vf= ); + VIR_STEAL_PTR(*pfname, tmpPfname); =20 - cleanup: - if (ret < 0) - VIR_FREE(*pfname); - - VIR_FREE(vf_sysfs_path); - VIR_FREE(pf_sysfs_path); - - return ret; + return virPCIGetVirtualFunctionIndex(pf_sysfs_path, vf_sysfs_path, vf); } =20 #else /* !__linux__ */ @@ -1657,7 +1599,6 @@ virNetDevSetVfConfig(const char *ifname, int vf, { int rc =3D -1; char macstr[VIR_MAC_STRING_BUFLEN]; - struct nlmsghdr *resp =3D NULL; struct nlmsgerr *err; unsigned int recvbuflen =3D 0; struct nl_msg *nl_msg; @@ -1666,6 +1607,7 @@ virNetDevSetVfConfig(const char *ifname, int vf, .ifi_family =3D AF_UNSPEC, .ifi_index =3D -1, }; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 if (!macaddr && vlanid < 0) return -1; @@ -1769,7 +1711,6 @@ virNetDevSetVfConfig(const char *ifname, int vf, vlanid, rc < 0 ? "Fail" : "Success"); =20 nlmsg_free(nl_msg); - VIR_FREE(resp); return rc; =20 malformed_resp: @@ -1843,19 +1784,15 @@ virNetDevGetVfConfig(const char *ifname, int vf, vi= rMacAddrPtr mac, int *vlanid) { int rc =3D -1; - void *nlData =3D NULL; struct nlattr *tb[IFLA_MAX + 1] =3D {NULL, }; int ifindex =3D -1; + VIR_AUTOFREE(void *) nlData =3D NULL; =20 rc =3D virNetlinkDumpLink(ifname, ifindex, &nlData, tb, 0, 0); if (rc < 0) - goto cleanup; + return rc; =20 - rc =3D virNetDevParseVfConfig(tb, vf, mac, vlanid); - - cleanup: - VIR_FREE(nlData); - return rc; + return virNetDevParseVfConfig(tb, vf, mac, vlanid); } =20 =20 @@ -1914,14 +1851,14 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, { int ret =3D -1; const char *pfDevName =3D NULL; - char *pfDevOrig =3D NULL; - char *vfDevOrig =3D NULL; virMacAddr oldMAC; char MACStr[VIR_MAC_STRING_BUFLEN]; int oldVlanTag =3D -1; - char *filePath =3D NULL; - char *fileStr =3D NULL; virJSONValuePtr configJSON =3D NULL; + VIR_AUTOFREE(char *) pfDevOrig =3D NULL; + VIR_AUTOFREE(char *) vfDevOrig =3D NULL; + VIR_AUTOFREE(char *) filePath =3D NULL; + VIR_AUTOFREE(char *) fileStr =3D NULL; =20 if (vf >=3D 0) { /* linkdev is the PF */ @@ -2030,10 +1967,6 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, =20 ret =3D 0; cleanup: - VIR_FREE(pfDevOrig); - VIR_FREE(vfDevOrig); - VIR_FREE(filePath); - VIR_FREE(fileStr); virJSONValueFree(configJSON); return ret; } @@ -2069,14 +2002,14 @@ virNetDevReadNetConfig(const char *linkdev, int vf, { int ret =3D -1; const char *pfDevName =3D NULL; - char *pfDevOrig =3D NULL; - char *vfDevOrig =3D NULL; - char *filePath =3D NULL; - char *fileStr =3D NULL; virJSONValuePtr configJSON =3D NULL; const char *MACStr =3D NULL; const char *adminMACStr =3D NULL; int vlanTag =3D -1; + VIR_AUTOFREE(char *) pfDevOrig =3D NULL; + VIR_AUTOFREE(char *) vfDevOrig =3D NULL; + VIR_AUTOFREE(char *) filePath =3D NULL; + VIR_AUTOFREE(char *) fileStr =3D NULL; =20 *adminMAC =3D NULL; *vlan =3D NULL; @@ -2245,10 +2178,6 @@ virNetDevReadNetConfig(const char *linkdev, int vf, VIR_FREE(*vlan); } =20 - VIR_FREE(pfDevOrig); - VIR_FREE(vfDevOrig); - VIR_FREE(filePath); - VIR_FREE(fileStr); virJSONValueFree(configJSON); return ret; } @@ -2282,10 +2211,10 @@ virNetDevSetNetConfig(const char *linkdev, int vf, int ret =3D -1; char MACStr[VIR_MAC_STRING_BUFLEN]; const char *pfDevName =3D NULL; - char *pfDevOrig =3D NULL; - char *vfDevOrig =3D NULL; int vlanTag =3D -1; virPCIDevicePtr vfPCIDevice =3D NULL; + VIR_AUTOFREE(char *) pfDevOrig =3D NULL; + VIR_AUTOFREE(char *) vfDevOrig =3D NULL; =20 if (vf >=3D 0) { /* linkdev is the PF */ @@ -2462,8 +2391,6 @@ virNetDevSetNetConfig(const char *linkdev, int vf, =20 ret =3D 0; cleanup: - VIR_FREE(pfDevOrig); - VIR_FREE(vfDevOrig); virPCIDeviceFree(vfPCIDevice); return ret; } @@ -2543,28 +2470,27 @@ int virNetDevGetLinkInfo(const char *ifname, virNetDevIfLinkPtr lnk) { - int ret =3D -1; - char *path =3D NULL; - char *buf =3D NULL; char *tmp; int tmp_state; unsigned int tmp_speed; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; =20 if (virNetDevSysfsFile(&path, ifname, "operstate") < 0) - goto cleanup; + return -1; =20 if (virFileReadAll(path, 1024, &buf) < 0) { virReportSystemError(errno, _("unable to read: %s"), path); - goto cleanup; + return -1; } =20 if (!(tmp =3D strchr(buf, '\n'))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse: %s"), buf); - goto cleanup; + return -1; } =20 *tmp =3D '\0'; @@ -2575,7 +2501,7 @@ virNetDevGetLinkInfo(const char *ifname, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse: %s"), buf); - goto cleanup; + return -1; } =20 lnk->state =3D tmp_state; @@ -2586,26 +2512,24 @@ virNetDevGetLinkInfo(const char *ifname, * speed if that's the case. */ if (lnk->state !=3D VIR_NETDEV_IF_STATE_UP) { lnk->speed =3D 0; - ret =3D 0; - goto cleanup; + return 0; } =20 VIR_FREE(path); VIR_FREE(buf); =20 if (virNetDevSysfsFile(&path, ifname, "speed") < 0) - goto cleanup; + return -1; =20 if (virFileReadAllQuiet(path, 1024, &buf) < 0) { /* Some devices doesn't report speed, in which case we get EINVAL = */ - if (errno =3D=3D EINVAL) { - ret =3D 0; - goto cleanup; - } + if (errno =3D=3D EINVAL) + return 0; + virReportSystemError(errno, _("unable to read: %s"), path); - goto cleanup; + return -1; } =20 if (virStrToLong_ui(buf, &tmp, 10, &tmp_speed) < 0 || @@ -2613,16 +2537,12 @@ virNetDevGetLinkInfo(const char *ifname, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse: %s"), buf); - goto cleanup; + return -1; } =20 lnk->speed =3D tmp_speed; =20 - ret =3D 0; - cleanup: - VIR_FREE(buf); - VIR_FREE(path); - return ret; + return 0; } =20 #else @@ -2830,45 +2750,41 @@ static int virNetDevGetMcastList(const char *ifname, virNetDevMcastListPtr mcast) { char *cur =3D NULL; - char *buf =3D NULL; char *next =3D NULL; - int ret =3D -1, len; + int len; VIR_AUTOPTR(virNetDevMcastEntry) entry =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; =20 mcast->entries =3D NULL; mcast->nentries =3D 0; =20 /* Read entire multicast table into memory */ if ((len =3D virFileReadAll(PROC_NET_DEV_MCAST, MAX_MCAST_SIZE, &buf))= <=3D 0) - goto cleanup; + return -1; =20 cur =3D buf; while (cur) { if (!entry && VIR_ALLOC(entry) < 0) - goto cleanup; + return -1; =20 next =3D strchr(cur, '\n'); if (next) next++; if (virNetDevParseMcast(cur, entry)) - goto cleanup; + return -1; =20 /* Only return global multicast MAC addresses for * specified interface */ if (entry->global && STREQ(ifname, entry->name)) { if (VIR_APPEND_ELEMENT(mcast->entries, mcast->nentries, entry)) - goto cleanup; + return -1; } else { memset(entry, 0, sizeof(virNetDevMcastEntry)); } cur =3D next && ((next - buf) < len) ? next : NULL; } =20 - ret =3D 0; - cleanup: - VIR_FREE(buf); - - return ret; + return 0; } =20 =20 @@ -3005,13 +2921,11 @@ static int virNetDevRDMAFeature(const char *ifname, virBitmapPtr *out) { - char *eth_devpath =3D NULL; - char *ib_devpath =3D NULL; - char *eth_res_buf =3D NULL; - char *ib_res_buf =3D NULL; DIR *dirp =3D NULL; struct dirent *dp; int ret =3D -1; + VIR_AUTOFREE(char *) eth_devpath =3D NULL; + VIR_AUTOFREE(char *) eth_res_buf =3D NULL; =20 if (!virFileExists(SYSFS_INFINIBAND_DIR)) return 0; @@ -3027,6 +2941,9 @@ virNetDevRDMAFeature(const char *ifname, goto cleanup; =20 while (virDirRead(dirp, &dp, SYSFS_INFINIBAND_DIR) > 0) { + VIR_AUTOFREE(char *) ib_devpath =3D NULL; + VIR_AUTOFREE(char *) ib_res_buf =3D NULL; + if (virAsprintf(&ib_devpath, SYSFS_INFINIBAND_DIR "%s/device/resou= rce", dp->d_name) < 0) continue; @@ -3035,17 +2952,11 @@ virNetDevRDMAFeature(const char *ifname, ignore_value(virBitmapSetBit(*out, VIR_NET_DEV_FEAT_RDMA)); break; } - VIR_FREE(ib_devpath); - VIR_FREE(ib_res_buf); } ret =3D 0; =20 cleanup: VIR_DIR_CLOSE(dirp); - VIR_FREE(eth_devpath); - VIR_FREE(ib_devpath); - VIR_FREE(eth_res_buf); - VIR_FREE(ib_res_buf); return ret; } =20 @@ -3204,11 +3115,11 @@ static uint32_t virNetDevGetFamilyId(const char *family_name) { struct nl_msg *nl_msg =3D NULL; - struct nlmsghdr *resp =3D NULL; struct genlmsghdr* gmsgh =3D NULL; struct nlattr *tb[CTRL_ATTR_MAX + 1] =3D {NULL, }; unsigned int recvbuflen; uint32_t family_id =3D 0; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 if (!(nl_msg =3D nlmsg_alloc_simple(GENL_ID_CTRL, NLM_F_REQUEST | NLM_F_ACK))) { @@ -3244,7 +3155,6 @@ virNetDevGetFamilyId(const char *family_name) =20 cleanup: nlmsg_free(nl_msg); - VIR_FREE(resp); return family_id; } =20 @@ -3264,16 +3174,16 @@ virNetDevSwitchdevFeature(const char *ifname, virBitmapPtr *out) { struct nl_msg *nl_msg =3D NULL; - struct nlmsghdr *resp =3D NULL; unsigned int recvbuflen; struct nlattr *tb[DEVLINK_ATTR_MAX + 1] =3D {NULL, }; virPCIDevicePtr pci_device_ptr =3D NULL; struct genlmsghdr* gmsgh =3D NULL; const char *pci_name; - char *pfname =3D NULL; int is_vf =3D -1; int ret =3D -1; uint32_t family_id; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; + VIR_AUTOFREE(char *) pfname =3D NULL; =20 if ((family_id =3D virNetDevGetFamilyId(DEVLINK_GENL_NAME)) <=3D 0) return ret; @@ -3332,8 +3242,6 @@ virNetDevSwitchdevFeature(const char *ifname, cleanup: nlmsg_free(nl_msg); virPCIDeviceFree(pci_device_ptr); - VIR_FREE(resp); - VIR_FREE(pfname); return ret; } # else @@ -3374,7 +3282,7 @@ virNetDevGetEthtoolGFeatures(virBitmapPtr bitmap, int fd, struct ifreq *ifr) { - struct ethtool_gfeatures *g_cmd; + VIR_AUTOFREE(struct ethtool_gfeatures *) g_cmd =3D NULL; =20 if (VIR_ALLOC_VAR(g_cmd, struct ethtool_get_features_block, GFEATURES_SIZE) <= 0) @@ -3384,7 +3292,6 @@ virNetDevGetEthtoolGFeatures(virBitmapPtr bitmap, g_cmd->size =3D GFEATURES_SIZE; if (virNetDevGFeatureAvailable(fd, ifr, g_cmd)) ignore_value(virBitmapSetBit(bitmap, VIR_NET_DEV_FEAT_TXUDPTNL)); - VIR_FREE(g_cmd); return 0; } # else --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 12:32:45 2024 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 153381799868917.90351098070903; Thu, 9 Aug 2018 05:33:18 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BD2043084041; Thu, 9 Aug 2018 12:33:16 +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 83FE3308BDB3; Thu, 9 Aug 2018 12:33:16 +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 3CB7C18037F9; Thu, 9 Aug 2018 12:33:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w79CX94w000474 for ; Thu, 9 Aug 2018 08:33:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0F117191BE; Thu, 9 Aug 2018 12:33:09 +0000 (UTC) Received: from mx1.redhat.com (ext-mx13.extmail.prod.ext.phx2.redhat.com [10.5.110.42]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 06AAB19030 for ; Thu, 9 Aug 2018 12:33:06 +0000 (UTC) Received: from mail-pl0-f54.google.com (mail-pl0-f54.google.com [209.85.160.54]) (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 EDF7C3082146 for ; Thu, 9 Aug 2018 12:33:03 +0000 (UTC) Received: by mail-pl0-f54.google.com with SMTP id ba4-v6so2496918plb.11 for ; Thu, 09 Aug 2018 05:33:03 -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.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 05:33:02 -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=xvQA3DeH8XlqjtXPwfJwdCwUn82Mkpywuvk7Ho57DBg=; b=LQpH7IAnQEIqKk214bUpKyxT90I9V26DmIUq0Ad4Q9+zQkmFFXUSkbh5mUrbhhQV1E b5mnT3y3vGiPHBQknKqSqXslEGHncY9RzuxvZR8o9HuvNWySz7aQJmPQeqoZEedwfHM9 ta96KLPQ4MK8JzDg9J8FZeIFxepnImVDYANKoyRSDMv7ksQActYF0zDXiKAA6ZbgbHk4 NDlCyrHqr9iUTrEDBCImoWNbimDfLy2WAXwM6l/bORjM4I4Qx1tuOntoDtpfce8C6a52 BA4sNpoVL1E/5A3oEEfR8G4F+Snaig5GdwKJzX3XzuISlZjWrtRG8jO33ptoBFlwP/3+ 9QSw== 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=xvQA3DeH8XlqjtXPwfJwdCwUn82Mkpywuvk7Ho57DBg=; b=As7iuWCrNYUV6mtH7RywOHd+5WC3Ay2FXDxaM7hM/B+i4PIT06mzJSuLUqmqvpKhKH 6QaP52PcrSm5MBJXzgCCScU2lc5C2TU3CnYDj5QvEjmftmkgVwMsOPrGPQxfUMK0ENOM RQi+usCuBnj1DmnoDqT9se8OCN40aJvjxcxI/K3Au1v5GEOaWMIg9MS8+nqZ3WX7qFNO zw1qmHHerSxvpYSja40OMPA0Aj+w52yuI6VkMeq9JiAcXim8VfSVVixk4dt8TF1yZiYC R3hIzBsuFq4rDkDMIafp7zUM8RP0V2WLlSycWaeRlEAIfooYYPdsd2sYyDtkFgTBte72 UaHA== X-Gm-Message-State: AOUpUlE8ZIIH+Jy/E2JsPzj1cvmM7wOMaJ1AUQTVCj5x4FDRck5v9Kdw E82UL0OaKhaMBb+C5GsMQXHB39Jk X-Google-Smtp-Source: AA+uWPwBg+tayfWSLUkvu+6v1XpUmbEQ00Mxcny7mj8X7hKp5ZM+wVN1ghMmziOXbAClhDZKxeu5Zw== X-Received: by 2002:a17:902:32a4:: with SMTP id z33-v6mr1968004plb.226.1533817983012; Thu, 09 Aug 2018 05:33:03 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Thu, 9 Aug 2018 09:42:16 +0530 Message-Id: <1533787939-28634-9-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.42]); Thu, 09 Aug 2018 12:33:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 09 Aug 2018 12:33:04 +0000 (UTC) for IP:'209.85.160.54' DOMAIN:'mail-pl0-f54.google.com' HELO:'mail-pl0-f54.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.160.54 mail-pl0-f54.google.com 209.85.160.54 mail-pl0-f54.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.42 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 08/11] util: netdev: 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.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 09 Aug 2018 12:33:17 +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/virnetdev.c | 249 +++++++++++++++++++++--------------------------= ---- 1 file changed, 103 insertions(+), 146 deletions(-) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index edb7393..d5aa94c 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -1182,27 +1182,21 @@ virNetDevIsPCIDevice(const char *devpath) static virPCIDevicePtr virNetDevGetPCIDevice(const char *devName) { - virPCIDeviceAddressPtr vfPCIAddr =3D NULL; - virPCIDevicePtr vfPCIDevice =3D NULL; + VIR_AUTOPTR(virPCIDeviceAddress) vfPCIAddr =3D NULL; VIR_AUTOFREE(char *) vfSysfsDevicePath =3D NULL; =20 if (virNetDevSysfsFile(&vfSysfsDevicePath, devName, "device") < 0) - goto cleanup; + return NULL; =20 if (!virNetDevIsPCIDevice(vfSysfsDevicePath)) - goto cleanup; + return NULL; =20 vfPCIAddr =3D virPCIGetDeviceAddressFromSysfsLink(vfSysfsDevicePath); if (!vfPCIAddr) - goto cleanup; + return NULL; =20 - vfPCIDevice =3D virPCIDeviceNew(vfPCIAddr->domain, vfPCIAddr->bus, - vfPCIAddr->slot, vfPCIAddr->function); - - cleanup: - VIR_FREE(vfPCIAddr); - - return vfPCIDevice; + return virPCIDeviceNew(vfPCIAddr->domain, vfPCIAddr->bus, + vfPCIAddr->slot, vfPCIAddr->function); } =20 =20 @@ -1601,12 +1595,12 @@ virNetDevSetVfConfig(const char *ifname, int vf, char macstr[VIR_MAC_STRING_BUFLEN]; struct nlmsgerr *err; unsigned int recvbuflen =3D 0; - struct nl_msg *nl_msg; struct nlattr *vfinfolist, *vfinfo; struct ifinfomsg ifinfo =3D { .ifi_family =3D AF_UNSPEC, .ifi_index =3D -1, }; + VIR_AUTOPTR(virNlMsg) nl_msg =3D NULL; VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 if (!macaddr && vlanid < 0) @@ -1710,7 +1704,6 @@ virNetDevSetVfConfig(const char *ifname, int vf, macaddr ? virMacAddrFormat(macaddr, macstr) : "(unchanged)", vlanid, rc < 0 ? "Fail" : "Success"); =20 - nlmsg_free(nl_msg); return rc; =20 malformed_resp: @@ -1849,12 +1842,11 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, const char *stateDir, bool saveVlan) { - int ret =3D -1; const char *pfDevName =3D NULL; virMacAddr oldMAC; char MACStr[VIR_MAC_STRING_BUFLEN]; int oldVlanTag =3D -1; - virJSONValuePtr configJSON =3D NULL; + VIR_AUTOPTR(virJSONValue) configJSON =3D NULL; VIR_AUTOFREE(char *) pfDevOrig =3D NULL; VIR_AUTOFREE(char *) vfDevOrig =3D NULL; VIR_AUTOFREE(char *) filePath =3D NULL; @@ -1866,7 +1858,7 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, =20 /* linkdev should get the VF's netdev name (or NULL if none) */ if (virNetDevPFGetVF(pfDevName, vf, &vfDevOrig) < 0) - goto cleanup; + return -1; =20 linkdev =3D vfDevOrig; saveVlan =3D true; @@ -1878,12 +1870,12 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, */ =20 if (virNetDevGetPhysicalFunction(linkdev, &pfDevOrig) < 0) - goto cleanup; + return -1; =20 pfDevName =3D pfDevOrig; =20 if (virNetDevGetVirtualFunctionIndex(pfDevName, linkdev, &vf) < 0) - goto cleanup; + return -1; } =20 if (pfDevName) { @@ -1901,7 +1893,7 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, * explicitly enable the PF in the host system network config. */ if (virNetDevGetOnline(pfDevName, &pfIsOnline) < 0) - goto cleanup; + return -1; =20 if (!pfIsOnline) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1910,12 +1902,12 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, "change host network config to put the " "PF online."), vf, pfDevName); - goto cleanup; + return -1; } } =20 if (!(configJSON =3D virJSONValueNewObject())) - goto cleanup; + return -1; =20 /* if there is a PF, it's now in pfDevName, and linkdev is either * the VF's name, or NULL (if the VF isn't bound to a net driver @@ -1924,11 +1916,11 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, =20 if (pfDevName && saveVlan) { if (virAsprintf(&filePath, "%s/%s_vf%d", stateDir, pfDevName, vf) = < 0) - goto cleanup; + return -1; =20 /* get admin MAC and vlan tag */ if (virNetDevGetVfConfig(pfDevName, vf, &oldMAC, &oldVlanTag) < 0) - goto cleanup; + return -1; =20 if (virJSONValueObjectAppendString(configJSON, VIR_NETDEV_KEYNAME_ADMIN_MAC, @@ -1936,39 +1928,36 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, virJSONValueObjectAppendNumberInt(configJSON, VIR_NETDEV_KEYNAME_VLAN_TAG, oldVlanTag) < 0) { - goto cleanup; + return -1; } =20 } else { if (virAsprintf(&filePath, "%s/%s", stateDir, linkdev) < 0) - goto cleanup; + return -1; } =20 if (linkdev) { if (virNetDevGetMAC(linkdev, &oldMAC) < 0) - goto cleanup; + return -1; =20 /* for interfaces with no pfDevName (i.e. not a VF, this will * be the only value in the file. */ if (virJSONValueObjectAppendString(configJSON, VIR_NETDEV_KEYNAME_= MAC, virMacAddrFormat(&oldMAC, MACSt= r)) < 0) - goto cleanup; + return -1; } =20 if (!(fileStr =3D virJSONValueToString(configJSON, true))) - goto cleanup; + return -1; =20 if (virFileWriteStr(filePath, fileStr, O_CREAT|O_TRUNC|O_WRONLY) < 0) { virReportSystemError(errno, _("Unable to preserve mac/vlan tag " "for device =3D %s, vf =3D %d"), lin= kdev, vf); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virJSONValueFree(configJSON); - return ret; + return 0; } =20 =20 @@ -2000,12 +1989,14 @@ virNetDevReadNetConfig(const char *linkdev, int vf, virNetDevVlanPtr *vlan, virMacAddrPtr *MAC) { - int ret =3D -1; const char *pfDevName =3D NULL; - virJSONValuePtr configJSON =3D NULL; const char *MACStr =3D NULL; const char *adminMACStr =3D NULL; int vlanTag =3D -1; + VIR_AUTOPTR(virMacAddr) tmpAdminMAC =3D NULL; + VIR_AUTOPTR(virNetDevVlan) tmpVlan =3D NULL; + VIR_AUTOPTR(virMacAddr) tmpMAC =3D NULL; + VIR_AUTOPTR(virJSONValue) configJSON =3D NULL; VIR_AUTOFREE(char *) pfDevOrig =3D NULL; VIR_AUTOFREE(char *) vfDevOrig =3D NULL; VIR_AUTOFREE(char *) filePath =3D NULL; @@ -2021,7 +2012,7 @@ virNetDevReadNetConfig(const char *linkdev, int vf, =20 /* linkdev should get the VF's netdev name (or NULL if none) */ if (virNetDevPFGetVF(pfDevName, vf, &vfDevOrig) < 0) - goto cleanup; + return -1; =20 linkdev =3D vfDevOrig; =20 @@ -2032,12 +2023,12 @@ virNetDevReadNetConfig(const char *linkdev, int vf, */ =20 if (virNetDevGetPhysicalFunction(linkdev, &pfDevOrig) < 0) - goto cleanup; + return -1; =20 pfDevName =3D pfDevOrig; =20 if (virNetDevGetVirtualFunctionIndex(pfDevName, linkdev, &vf) < 0) - goto cleanup; + return -1; } =20 /* if there is a PF, it's now in pfDevName, and linkdev is either @@ -2047,7 +2038,7 @@ virNetDevReadNetConfig(const char *linkdev, int vf, =20 if (pfDevName) { if (virAsprintf(&filePath, "%s/%s_vf%d", stateDir, pfDevName, vf) = < 0) - goto cleanup; + return -1; =20 if (linkdev && !virFileExists(filePath)) { /* the device may have been stored in a file named for the @@ -2062,19 +2053,18 @@ virNetDevReadNetConfig(const char *linkdev, int vf, =20 if (!pfDevName) { if (virAsprintf(&filePath, "%s/%s", stateDir, linkdev) < 0) - goto cleanup; + return -1; } =20 if (!virFileExists(filePath)) { /* having no file to read is not necessarily an error, so we * just return success, but with MAC, adminMAC, and vlan set to NU= LL */ - ret =3D 0; - goto cleanup; + return 0; } =20 if (virFileReadAll(filePath, 128, &fileStr) < 0) - goto cleanup; + return -1; =20 if (strchr("0123456789abcdefABCDEF", fileStr[0])) { const char *vlanStr =3D NULL; @@ -2096,7 +2086,7 @@ virNetDevReadNetConfig(const char *linkdev, int vf, virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse vlan tag '%s' from file '%s= '"), vlanStr, filePath); - goto cleanup; + return -1; } } else { /* if there is only one line, it is MAC */ @@ -2112,7 +2102,7 @@ virNetDevReadNetConfig(const char *linkdev, int vf, _("invalid json in net device saved " "config file '%s': '%.60s'"), filePath, fileStr); - goto cleanup; + return -1; } =20 MACStr =3D virJSONValueObjectGetString(configJSON, @@ -2129,57 +2119,52 @@ virNetDevReadNetConfig(const char *linkdev, int vf, "has unexpected contents, missing both " "'MAC' and 'adminMAC': '%.60s'"), filePath, fileStr); - goto cleanup; + return -1; } } =20 if (MACStr) { - if (VIR_ALLOC(*MAC) < 0) - goto cleanup; + if (VIR_ALLOC(tmpMAC) < 0) + return -1; =20 - if (virMacAddrParse(MACStr, *MAC) < 0) { + if (virMacAddrParse(MACStr, tmpMAC) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse MAC address '%s' from file '%s'= "), MACStr, filePath); - goto cleanup; + return -1; } } =20 if (adminMACStr) { - if (VIR_ALLOC(*adminMAC) < 0) - goto cleanup; + if (VIR_ALLOC(tmpAdminMAC) < 0) + return -1; =20 - if (virMacAddrParse(adminMACStr, *adminMAC) < 0) { + if (virMacAddrParse(adminMACStr, tmpAdminMAC) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse MAC address '%s' from file '%s'= "), adminMACStr, filePath); - goto cleanup; + return -1; } } =20 if (vlanTag !=3D -1) { /* construct a simple virNetDevVlan object with a single tag */ - if (VIR_ALLOC(*vlan) < 0) - goto cleanup; - if (VIR_ALLOC((*vlan)->tag) < 0) - goto cleanup; - (*vlan)->nTags =3D 1; - (*vlan)->tag[0] =3D vlanTag; + if (VIR_ALLOC(tmpVlan) < 0) + return -1; + if (VIR_ALLOC(tmpVlan->tag) < 0) + return -1; + tmpVlan->nTags =3D 1; + tmpVlan->tag[0] =3D vlanTag; } =20 /* we won't need the file again */ ignore_value(unlink(filePath)); =20 - ret =3D 0; - cleanup: - if (ret < 0) { - VIR_FREE(*adminMAC); - VIR_FREE(*MAC); - VIR_FREE(*vlan); - } + VIR_STEAL_PTR(*adminMAC, tmpAdminMAC); + VIR_STEAL_PTR(*MAC, tmpMAC); + VIR_STEAL_PTR(*vlan, tmpVlan); =20 - virJSONValueFree(configJSON); - return ret; + return 0; } =20 =20 @@ -2208,11 +2193,10 @@ virNetDevSetNetConfig(const char *linkdev, int vf, const virMacAddr *MAC, bool setVlan) { - int ret =3D -1; char MACStr[VIR_MAC_STRING_BUFLEN]; const char *pfDevName =3D NULL; int vlanTag =3D -1; - virPCIDevicePtr vfPCIDevice =3D NULL; + VIR_AUTOPTR(virPCIDevice) vfPCIDevice =3D NULL; VIR_AUTOFREE(char *) pfDevOrig =3D NULL; VIR_AUTOFREE(char *) vfDevOrig =3D NULL; =20 @@ -2222,7 +2206,7 @@ virNetDevSetNetConfig(const char *linkdev, int vf, =20 /* linkdev should get the VF's netdev name (or NULL if none) */ if (virNetDevPFGetVF(pfDevName, vf, &vfDevOrig) < 0) - goto cleanup; + return -1; =20 linkdev =3D vfDevOrig; =20 @@ -2233,12 +2217,12 @@ virNetDevSetNetConfig(const char *linkdev, int vf, */ =20 if (virNetDevGetPhysicalFunction(linkdev, &pfDevOrig) < 0) - goto cleanup; + return -1; =20 pfDevName =3D pfDevOrig; =20 if (virNetDevGetVirtualFunctionIndex(pfDevName, linkdev, &vf) < 0) - goto cleanup; + return -1; } =20 =20 @@ -2250,14 +2234,14 @@ virNetDevSetNetConfig(const char *linkdev, int vf, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("admin MAC can only be set for SR-IOV VFs, bu= t " "%s is not a VF"), linkdev); - goto cleanup; + return -1; } =20 if (vlan) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("vlan can only be set for SR-IOV VFs, but " "%s is not a VF"), linkdev); - goto cleanup; + return -1; } =20 } else { @@ -2266,14 +2250,14 @@ virNetDevSetNetConfig(const char *linkdev, int vf, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("vlan trunking is not supported " "by SR-IOV network devices")); - goto cleanup; + return -1; } =20 if (!setVlan) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("vlan tag set for interface %s but " "caller requested it not be set")); - goto cleanup; + return -1; } =20 vlanTag =3D vlan->tag[0]; @@ -2291,7 +2275,7 @@ virNetDevSetNetConfig(const char *linkdev, int vf, _("VF %d of PF '%s' is not bound to a net drive= r, " "so its MAC address cannot be set to %s"), vf, pfDevName, virMacAddrFormat(MAC, MACStr)); - goto cleanup; + return -1; } =20 setMACrc =3D virNetDevSetMACInternal(linkdev, MAC, !!pfDevOrig); @@ -2302,7 +2286,7 @@ virNetDevSetNetConfig(const char *linkdev, int vf, /* if pfDevOrig =3D=3D NULL, this isn't a VF, so we've failed = */ if (!pfDevOrig || (errno !=3D EADDRNOTAVAIL && errno !=3D EPERM)) - goto cleanup; + return -1; =20 /* Otherwise this is a VF, and virNetDevSetMAC failed with * EADDRNOTAVAIL/EPERM, which could be due to the @@ -2316,18 +2300,18 @@ virNetDevSetNetConfig(const char *linkdev, int vf, =20 if (virNetDevSetVfConfig(pfDevName, vf, MAC, vlanTag, &allowRetry) < 0) { - goto cleanup; + return -1; } =20 /* admin MAC is set, now we need to construct a virPCIDevice * object so we can call virPCIDeviceRebind() */ if (!(vfPCIDevice =3D virNetDevGetPCIDevice(linkdev))) - goto cleanup; + return -1; =20 /* Rebind the device. This should set the proper MAC address */ if (virPCIDeviceRebind(vfPCIDevice) < 0) - goto cleanup; + return -1; =20 /* Wait until virNetDevGetIndex for the VF netdev returns succ= ess. * This indicates that the device is ready to be used. If we d= on't @@ -2379,20 +2363,17 @@ virNetDevSetNetConfig(const char *linkdev, int vf, * with the "locally administered" bit set. */ if (!allowRetry) - goto cleanup; + return -1; =20 allowRetry =3D false; if (virNetDevSetVfConfig(pfDevName, vf, &altZeroMAC, vlanTag, &allowRetry) < = 0) { - goto cleanup; + return -1; } } } =20 - ret =3D 0; - cleanup: - virPCIDeviceFree(vfPCIDevice); - return ret; + return 0; } =20 =20 @@ -2863,30 +2844,29 @@ virNetDevRxFilterFree(virNetDevRxFilterPtr filter) int virNetDevGetRxFilter(const char *ifname, virNetDevRxFilterPtr *filter) { - int ret =3D -1; bool receive =3D false; - virNetDevRxFilterPtr fil =3D virNetDevRxFilterNew(); + VIR_AUTOPTR(virNetDevRxFilter) fil =3D virNetDevRxFilterNew(); =20 if (!fil) - goto cleanup; + return -1; =20 if (virNetDevGetMAC(ifname, &fil->mac)) - goto cleanup; + return -1; =20 if (virNetDevGetMulticastTable(ifname, fil)) - goto cleanup; + return -1; =20 if (virNetDevGetPromiscuous(ifname, &fil->promiscuous)) - goto cleanup; + return -1; =20 if (virNetDevGetRcvAllMulti(ifname, &receive)) - goto cleanup; + return -1; =20 if (receive) { fil->multicast.mode =3D VIR_NETDEV_RX_FILTER_MODE_ALL; } else { if (virNetDevGetRcvMulti(ifname, &receive)) - goto cleanup; + return -1; =20 if (receive) fil->multicast.mode =3D VIR_NETDEV_RX_FILTER_MODE_NORMAL; @@ -2894,15 +2874,9 @@ int virNetDevGetRxFilter(const char *ifname, fil->multicast.mode =3D VIR_NETDEV_RX_FILTER_MODE_NONE; } =20 - ret =3D 0; - cleanup: - if (ret < 0) { - virNetDevRxFilterFree(fil); - fil =3D NULL; - } + VIR_STEAL_PTR(*filter, fil); =20 - *filter =3D fil; - return ret; + return 0; } =20 #if defined(SIOCETHTOOL) && defined(HAVE_STRUCT_IFREQ) @@ -3114,21 +3088,20 @@ virNetDevPutExtraHeader(struct nlmsghdr *nlh, static uint32_t virNetDevGetFamilyId(const char *family_name) { - struct nl_msg *nl_msg =3D NULL; struct genlmsghdr* gmsgh =3D NULL; struct nlattr *tb[CTRL_ATTR_MAX + 1] =3D {NULL, }; unsigned int recvbuflen; - uint32_t family_id =3D 0; + VIR_AUTOPTR(virNlMsg) nl_msg =3D NULL; VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 if (!(nl_msg =3D nlmsg_alloc_simple(GENL_ID_CTRL, NLM_F_REQUEST | NLM_F_ACK))) { virReportOOMError(); - goto cleanup; + return 0; } =20 if (!(gmsgh =3D virNetDevPutExtraHeader(nlmsg_hdr(nl_msg), sizeof(stru= ct genlmsghdr)))) - goto cleanup; + return 0; =20 gmsgh->cmd =3D CTRL_CMD_GETFAMILY; gmsgh->version =3D DEVLINK_GENL_VERSION; @@ -3136,26 +3109,22 @@ virNetDevGetFamilyId(const char *family_name) if (nla_put_string(nl_msg, CTRL_ATTR_FAMILY_NAME, family_name) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("allocated netlink buffer is too small")); - goto cleanup; + return 0; } =20 if (virNetlinkCommand(nl_msg, &resp, &recvbuflen, 0, 0, NETLINK_GENERI= C, 0) < 0) - goto cleanup; + return 0; =20 if (nlmsg_parse(resp, sizeof(struct nlmsghdr), tb, CTRL_ATTR_MAX, NULL= ) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed netlink response message")); - goto cleanup; + return 0; } =20 if (tb[CTRL_ATTR_FAMILY_ID] =3D=3D NULL) - goto cleanup; + return 0; =20 - family_id =3D *(uint32_t *)RTA_DATA(tb[CTRL_ATTR_FAMILY_ID]); - - cleanup: - nlmsg_free(nl_msg); - return family_id; + return *(uint32_t *)RTA_DATA(tb[CTRL_ATTR_FAMILY_ID]); } =20 =20 @@ -3173,43 +3142,40 @@ static int virNetDevSwitchdevFeature(const char *ifname, virBitmapPtr *out) { - struct nl_msg *nl_msg =3D NULL; unsigned int recvbuflen; struct nlattr *tb[DEVLINK_ATTR_MAX + 1] =3D {NULL, }; - virPCIDevicePtr pci_device_ptr =3D NULL; struct genlmsghdr* gmsgh =3D NULL; const char *pci_name; int is_vf =3D -1; - int ret =3D -1; uint32_t family_id; + VIR_AUTOPTR(virNlMsg) nl_msg =3D NULL; + VIR_AUTOPTR(virPCIDevice) pci_device_ptr =3D NULL; VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; VIR_AUTOFREE(char *) pfname =3D NULL; =20 if ((family_id =3D virNetDevGetFamilyId(DEVLINK_GENL_NAME)) <=3D 0) - return ret; + return -1; =20 if ((is_vf =3D virNetDevIsVirtualFunction(ifname)) < 0) - return ret; + return -1; =20 if (is_vf =3D=3D 1 && virNetDevGetPhysicalFunction(ifname, &pfname) < = 0) - goto cleanup; + return -1; =20 pci_device_ptr =3D pfname ? virNetDevGetPCIDevice(pfname) : virNetDevGetPCIDevice(ifname); /* No PCI device, then no feature bit to check/add */ - if (pci_device_ptr =3D=3D NULL) { - ret =3D 0; - goto cleanup; - } + if (pci_device_ptr =3D=3D NULL) + return 0; =20 if (!(nl_msg =3D nlmsg_alloc_simple(family_id, NLM_F_REQUEST | NLM_F_ACK))) { virReportOOMError(); - goto cleanup; + return -1; } =20 if (!(gmsgh =3D virNetDevPutExtraHeader(nlmsg_hdr(nl_msg), sizeof(stru= ct genlmsghdr)))) - goto cleanup; + return -1; =20 gmsgh->cmd =3D DEVLINK_CMD_ESWITCH_GET; gmsgh->version =3D DEVLINK_GENL_VERSION; @@ -3220,16 +3186,16 @@ virNetDevSwitchdevFeature(const char *ifname, nla_put(nl_msg, DEVLINK_ATTR_DEV_NAME, strlen(pci_name)+1, pci_nam= e) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("allocated netlink buffer is too small")); - goto cleanup; + return -1; } =20 if (virNetlinkCommand(nl_msg, &resp, &recvbuflen, 0, 0, NETLINK_GENERI= C, 0) < 0) - goto cleanup; + return -1; =20 if (nlmsg_parse(resp, sizeof(struct genlmsghdr), tb, DEVLINK_ATTR_MAX,= NULL) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed netlink response message")); - goto cleanup; + return -1; } =20 if (tb[DEVLINK_ATTR_ESWITCH_MODE] && @@ -3237,12 +3203,7 @@ virNetDevSwitchdevFeature(const char *ifname, ignore_value(virBitmapSetBit(*out, VIR_NET_DEV_FEAT_SWITCHDEV)); } =20 - ret =3D 0; - - cleanup: - nlmsg_free(nl_msg); - virPCIDeviceFree(pci_device_ptr); - return ret; + return 0; } # else static int @@ -3497,8 +3458,7 @@ int virNetDevSetCoalesce(const char *ifname, int virNetDevRunEthernetScript(const char *ifname, const char *script) { - virCommandPtr cmd; - int ret; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 /* Not a bug! Previously we did accept script=3D"" as a NO-OP. */ if (STREQ(script, "")) @@ -3512,8 +3472,5 @@ virNetDevRunEthernetScript(const char *ifname, const = char *script) #endif virCommandAddEnvPassCommon(cmd); =20 - ret =3D virCommandRun(cmd, NULL); - - virCommandFree(cmd); - return ret; + return virCommandRun(cmd, NULL); } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 12:32:45 2024 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 153381800309857.78445154604128; Thu, 9 Aug 2018 05:33:23 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 781A7369BC; Thu, 9 Aug 2018 12:33:20 +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 45A96CDE07; Thu, 9 Aug 2018 12:33:20 +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 EA8814A46C; Thu, 9 Aug 2018 12:33:19 +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 w79CXBIm000492 for ; Thu, 9 Aug 2018 08:33:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id E54205E1D6; Thu, 9 Aug 2018 12:33:11 +0000 (UTC) Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D76F65E1CF for ; Thu, 9 Aug 2018 12:33:07 +0000 (UTC) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.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 0E1B63082267 for ; Thu, 9 Aug 2018 12:33:06 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id f1-v6so2678633pgq.12 for ; Thu, 09 Aug 2018 05:33:06 -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.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 05:33:04 -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=h3IOao5c6H0XIAQvLPL3ON5AeL9M47iAv3jvzKkdQPs=; b=GTSYkWUyN/rws1r4+3tCELAh7e8fgh8kCMLJrb/ykC1vlcO76+keT0Wl99V+2ePYb7 lc0ntM0XPw6hVoCL1dQPwV5VzQUW5bzNv8Dfv6wGn8Nh8h/cibJyYOX3cOY81Dhrf0EM 6SHn4B+HQIk7eBw6UJBqaHsdGm3RrJz15hzMLql7qWv+6r4ErkrTdt9rpbuJmGDF7Amw EJnzeK7XLGGmYauJl9WhorVMMCJofrWhjXN7Ccp36oAJnXfH7djfYTFdsLGVZX+Z4RG1 AEgsqFnof7IgeivolTVLm/p7TJ3djtH42hjYrskje6Yv0vbBg7eVAZcM+0ary7hq2Q5y xNeg== 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=h3IOao5c6H0XIAQvLPL3ON5AeL9M47iAv3jvzKkdQPs=; b=cvw9UzcN2oesUj81hQlI2kBNymrFgdWHVETlYeaLIaT9fJlZ1zQOz0yvwGtFeH7Owu hTf7QhtOz4v+Ozug4r4Qj1Bao6SvHkGO4NgQ3d/1znSdXzcsJcb55EN7jsxguuxKuHBY gMZTUo1S4SJeW5f2/62FGTh4Hutmdl4XxBI0nCiUzFbRU6zdUo3JErQKCIVxWSlg1+et xK6aLVSouyILVZ+XAnCyqXGnru+z6Dccsf4zXV8fwdvRfUcikifF+CVhQN8aBp4jBjT1 3hbh3ekaByNJ85AY0+DPvUpa5rUuyjC4A6QAjxjVkSezmbjAuqPU0NnDbsE867qQXmJQ mgYA== X-Gm-Message-State: AOUpUlFSD/7RBBk01hN74bgRzdInNEGx1wJl1hQFebAOM93evGvajEgj WY0L7fpyYiZ0D05A1ytHFrqni2tS X-Google-Smtp-Source: AA+uWPxs14wM8W20FzTQqK1gZEzYxFaQdakIoSDu8W1swmcyhQFRJpXTjrWKhKvS6e/cgP6nezr6vA== X-Received: by 2002:a63:f414:: with SMTP id g20-v6mr1980847pgi.407.1533817985155; Thu, 09 Aug 2018 05:33:05 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Thu, 9 Aug 2018 09:42:17 +0530 Message-Id: <1533787939-28634-10-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.45]); Thu, 09 Aug 2018 12:33:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 09 Aug 2018 12:33:06 +0000 (UTC) for IP:'209.85.215.193' DOMAIN:'mail-pg1-f193.google.com' HELO:'mail-pg1-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.215.193 mail-pg1-f193.google.com 209.85.215.193 mail-pg1-f193.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.45 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 09/11] util: netdevip: 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.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 09 Aug 2018 12:33:21 +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/virnetdevip.c | 130 +++++++++++++++++++--------------------------= ---- 1 file changed, 51 insertions(+), 79 deletions(-) diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c index c6d6175..4a38a54 100644 --- a/src/util/virnetdevip.c +++ b/src/util/virnetdevip.c @@ -168,10 +168,9 @@ virNetDevIPAddrAdd(const char *ifname, virSocketAddr *peer, unsigned int prefix) { - virSocketAddr *broadcast =3D NULL; - int ret =3D -1; - struct nl_msg *nlmsg =3D NULL; unsigned int recvbuflen; + VIR_AUTOPTR(virNlMsg) nlmsg =3D NULL; + VIR_AUTOPTR(virSocketAddr) broadcast =3D NULL; VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; VIR_AUTOFREE(char *) ipStr =3D NULL; VIR_AUTOFREE(char *) peerStr =3D NULL; @@ -186,13 +185,13 @@ virNetDevIPAddrAdd(const char *ifname, !(peer && VIR_SOCKET_ADDR_VALID(peer))) { /* compute a broadcast address if this is IPv4 */ if (VIR_ALLOC(broadcast) < 0) - goto cleanup; + return -1; =20 if (virSocketAddrBroadcastByPrefix(addr, prefix, broadcast) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to determine broadcast address for '%s/%d= '"), - ipStr, prefix); - goto cleanup; + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to determine broadcast address for '%= s/%d'"), + ipStr, prefix); + return -1; } bcastStr =3D virSocketAddrFormat(broadcast); } @@ -206,11 +205,11 @@ virNetDevIPAddrAdd(const char *ifname, if (!(nlmsg =3D virNetDevCreateNetlinkAddressMessage(RTM_NEWADDR, ifna= me, addr, prefix, broadcast, peer))) - goto cleanup; + return -1; =20 if (virNetlinkCommand(nlmsg, &resp, &recvbuflen, 0, 0, NETLINK_ROUTE, 0) < 0) - goto cleanup; + return -1; =20 =20 if (virNetlinkGetErrorCode(resp, recvbuflen) < 0) { @@ -220,14 +219,10 @@ virNetDevIPAddrAdd(const char *ifname, peerStr ? " peer " : "", peerStr ? peerStr : "", bcastStr ? " bcast " : "", bcastStr ? bcastStr : "", ifname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - nlmsg_free(nlmsg); - VIR_FREE(broadcast); - return ret; + return 0; } =20 =20 @@ -246,30 +241,26 @@ virNetDevIPAddrDel(const char *ifname, virSocketAddr *addr, unsigned int prefix) { - int ret =3D -1; - struct nl_msg *nlmsg =3D NULL; unsigned int recvbuflen; + VIR_AUTOPTR(virNlMsg) nlmsg =3D NULL; VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 if (!(nlmsg =3D virNetDevCreateNetlinkAddressMessage(RTM_DELADDR, ifna= me, addr, prefix, NULL, NULL))) - goto cleanup; + return -1; =20 if (virNetlinkCommand(nlmsg, &resp, &recvbuflen, 0, 0, NETLINK_ROUTE, 0) < 0) - goto cleanup; + return -1; =20 if (virNetlinkGetErrorCode(resp, recvbuflen) < 0) { virReportError(VIR_ERR_SYSTEM_ERROR, _("Error removing IP address from %s"), ifname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - nlmsg_free(nlmsg); - return ret; + return 0; } =20 =20 @@ -292,8 +283,6 @@ virNetDevIPRouteAdd(const char *ifname, virSocketAddrPtr gateway, unsigned int metric) { - int ret =3D -1; - struct nl_msg *nlmsg =3D NULL; struct nlmsghdr *resp =3D NULL; unsigned int recvbuflen; unsigned int ifindex; @@ -304,6 +293,7 @@ virNetDevIPRouteAdd(const char *ifname, int errCode; virSocketAddr defaultAddr; virSocketAddrPtr actualAddr; + VIR_AUTOPTR(virNlMsg) nlmsg =3D NULL; VIR_AUTOFREE(char *) toStr =3D NULL; VIR_AUTOFREE(char *) viaStr =3D NULL; =20 @@ -315,10 +305,10 @@ virNetDevIPRouteAdd(const char *ifname, int family =3D VIR_SOCKET_ADDR_FAMILY(gateway); if (family =3D=3D AF_INET) { if (virSocketAddrParseIPv4(&defaultAddr, VIR_SOCKET_ADDR_IPV4_= ALL) < 0) - goto cleanup; + return -1; } else { if (virSocketAddrParseIPv6(&defaultAddr, VIR_SOCKET_ADDR_IPV6_= ALL) < 0) - goto cleanup; + return -1; } =20 actualAddr =3D &defaultAddr; @@ -330,17 +320,17 @@ virNetDevIPRouteAdd(const char *ifname, =20 if (virNetDevGetIPAddressBinary(actualAddr, &addrData, &addrDataLen) <= 0 || virNetDevGetIPAddressBinary(gateway, &gatewayData, &addrDataLen) <= 0) - goto cleanup; + return -1; =20 /* Get the interface index */ if ((ifindex =3D if_nametoindex(ifname)) =3D=3D 0) - goto cleanup; + return -1; =20 if (!(nlmsg =3D nlmsg_alloc_simple(RTM_NEWROUTE, NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL))) { virReportOOMError(); - goto cleanup; + return -1; } =20 memset(&rtmsg, 0, sizeof(rtmsg)); @@ -369,22 +359,19 @@ virNetDevIPRouteAdd(const char *ifname, =20 if (virNetlinkCommand(nlmsg, &resp, &recvbuflen, 0, 0, NETLINK_ROUTE, 0) < 0) - goto cleanup; + return -1; =20 if ((errCode =3D virNetlinkGetErrorCode(resp, recvbuflen)) < 0) { virReportSystemError(errCode, _("Error adding route to %s"), ifnam= e); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - nlmsg_free(nlmsg); - return ret; + return 0; =20 buffer_too_small: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("allocated netlink buffer is too small")); - goto cleanup; + return -1; } =20 =20 @@ -443,12 +430,11 @@ virNetDevIPParseDadStatus(struct nlmsghdr *nlh, int l= en, int virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, size_t count) { - struct nl_msg *nlmsg =3D NULL; struct ifaddrmsg ifa; unsigned int recvbuflen; - int ret =3D -1; bool dad =3D true; time_t max_time =3D time(NULL) + VIR_DAD_WAIT_TIMEOUT; + VIR_AUTOPTR(virNlMsg) nlmsg =3D NULL; =20 if (!(nlmsg =3D nlmsg_alloc_simple(RTM_GETADDR, NLM_F_REQUEST | NLM_F_DUMP))) { @@ -462,7 +448,7 @@ virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, size_= t count) if (nlmsg_append(nlmsg, &ifa, sizeof(ifa), NLMSG_ALIGNTO) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("allocated netlink buffer is too small")); - goto cleanup; + return -1; } =20 /* Periodically query netlink until DAD finishes on all known addresse= s. */ @@ -471,12 +457,12 @@ virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, siz= e_t count) =20 if (virNetlinkCommand(nlmsg, &resp, &recvbuflen, 0, 0, NETLINK_ROUTE, 0) < 0) - goto cleanup; + return -1; =20 if (virNetlinkGetErrorCode(resp, recvbuflen) < 0) { virReportError(VIR_ERR_SYSTEM_ERROR, "%s", _("error reading DAD state information")); - goto cleanup; + return -1; } =20 /* Parse response. */ @@ -490,21 +476,19 @@ virNetDevIPWaitDadFinish(virSocketAddrPtr *addrs, siz= e_t count) _("Duplicate Address Detection " "not finished in %d seconds"), VIR_DAD_WAIT_TIMEO= UT); } else { - ret =3D 0; + return 0; } =20 - cleanup: - nlmsg_free(nlmsg); - return ret; + return -1; } =20 static int virNetDevIPGetAcceptRA(const char *ifname) { + char *suffix; + int accept_ra =3D -1; VIR_AUTOFREE(char *) path =3D NULL; VIR_AUTOFREE(char *) buf =3D NULL; - char *suffix; - int accept_ra =3D -1; =20 if (virAsprintf(&path, "/proc/sys/net/ipv6/conf/%s/accept_ra", ifname ? ifname : "all") < 0) @@ -553,6 +537,7 @@ virNetDevIPCheckIPv6ForwardingCallback(const struct nlm= sghdr *resp, /* Should never happen: netlink message would be broken */ if (ifname) { VIR_AUTOFREE(char *) ifname2 =3D virNetDevGetName(oif); + VIR_WARN("Single route has unexpected 2nd interface " "- '%s' and '%s'", ifname, ifname2); break; @@ -588,7 +573,6 @@ virNetDevIPCheckIPv6ForwardingCallback(const struct nlm= sghdr *resp, bool virNetDevIPCheckIPv6Forwarding(void) { - struct nl_msg *nlmsg =3D NULL; bool valid =3D false; struct rtgenmsg genmsg; size_t i; @@ -597,6 +581,7 @@ virNetDevIPCheckIPv6Forwarding(void) .devices =3D NULL, .ndevices =3D 0 }; + VIR_AUTOPTR(virNlMsg) nlmsg =3D NULL; =20 =20 /* Prepare the request message */ @@ -650,7 +635,6 @@ virNetDevIPCheckIPv6Forwarding(void) } =20 cleanup: - nlmsg_free(nlmsg); for (i =3D 0; i < data.ndevices; i++) VIR_FREE(data.devices[i]); return valid; @@ -665,24 +649,23 @@ virNetDevIPAddrAdd(const char *ifname, virSocketAddr *peer, unsigned int prefix) { - virCommandPtr cmd =3D NULL; virSocketAddr broadcast; - int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) addrstr =3D NULL; VIR_AUTOFREE(char *) bcaststr =3D NULL; VIR_AUTOFREE(char *) peerstr =3D NULL; =20 if (!(addrstr =3D virSocketAddrFormat(addr))) - goto cleanup; + return -1; =20 if (peer && VIR_SOCKET_ADDR_VALID(peer) && !(peerstr =3D virSocketAddr= Format(peer))) - goto cleanup; + return -1; =20 /* format up a broadcast address if this is IPv4 */ if (!peerstr && ((VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_INET)) && ((virSocketAddrBroadcastByPrefix(addr, prefix, &broadcast) < 0) || !(bcaststr =3D virSocketAddrFormat(&broadcast))))) { - goto cleanup; + return -1; } =20 # ifdef IFCONFIG_PATH @@ -710,12 +693,9 @@ virNetDevIPAddrAdd(const char *ifname, # endif =20 if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 =20 @@ -724,12 +704,11 @@ virNetDevIPAddrDel(const char *ifname, virSocketAddr *addr, unsigned int prefix) { - virCommandPtr cmd =3D NULL; - int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) addrstr =3D NULL; =20 if (!(addrstr =3D virSocketAddrFormat(addr))) - goto cleanup; + return -1; # ifdef IFCONFIG_PATH cmd =3D virCommandNew(IFCONFIG_PATH); virCommandAddArg(cmd, ifname); @@ -747,12 +726,9 @@ virNetDevIPAddrDel(const char *ifname, # endif =20 if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 =20 @@ -763,15 +739,14 @@ virNetDevIPRouteAdd(const char *ifname, virSocketAddrPtr gateway, unsigned int metric) { - virCommandPtr cmd =3D NULL; - int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) addrstr =3D NULL; VIR_AUTOFREE(char *) gatewaystr =3D NULL; =20 if (!(addrstr =3D virSocketAddrFormat(addr))) - goto cleanup; + return -1; if (!(gatewaystr =3D virSocketAddrFormat(gateway))) - goto cleanup; + return -1; cmd =3D virCommandNew(IP_PATH); virCommandAddArgList(cmd, "route", "add", NULL); virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix); @@ -780,12 +755,9 @@ virNetDevIPRouteAdd(const char *ifname, virCommandAddArgFormat(cmd, "%u", metric); =20 if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 12:32:45 2024 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 From nobody Sat May 4 12:32:45 2024 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 1533818012741355.0315455500753; Thu, 9 Aug 2018 05:33: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 79F0481115; Thu, 9 Aug 2018 12:33:30 +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 3D2A95E1BA; Thu, 9 Aug 2018 12:33: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 E5361181A386; Thu, 9 Aug 2018 12:33:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w79CXEgS000516 for ; Thu, 9 Aug 2018 08:33:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 32014CAE67; Thu, 9 Aug 2018 12:33:14 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2BF57CB184 for ; Thu, 9 Aug 2018 12:33:11 +0000 (UTC) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.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 AB75080F7B for ; Thu, 9 Aug 2018 12:33:10 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id a14-v6so2682134pgv.10 for ; Thu, 09 Aug 2018 05:33:10 -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.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 05:33:09 -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=+QkN2z4KJU24VG9TfQLduifw+1QwS/ggd0iWflP32Ks=; b=KWYRabPJJmVxsYbECZCFjuHZjirNw4fn4b0TmIN9W0sT2NblqMq9YoPHZa48FL15Ee T9+jkeH9icT1kG5ZGVQUFrOD30XhB1tutz4KpwdAL2CdlJipGNxZ0e2inRDekxy6aj6j FAWTB4JUwEi8nKb7vc5U738GwUrLLCrfeF9u6k9yVdmMImTUEF2RPWamBY1PuLsFuo5F UjFERtFRpErpCR7Ycv2JKymDd5aNI9PNXw8bdSVXMCh+EFaH+ZX1Gk5vK2IRO3bOErTz 9sWAPGyYQXD9qmQuPNBYBwPkdS0YxtJfXtGHgw7CZiH7hznHcPWTThi6kiWaYFQonI1k fKvQ== 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=+QkN2z4KJU24VG9TfQLduifw+1QwS/ggd0iWflP32Ks=; b=rrb4ZR/qUdebEXRX8DOGgezoE13x/L+Sotyr7hzl3oJYwnq9CyZyMtLgpF1aw3nIV9 oWYTtMXrDDbrbu5za4YxNmjSMPtHVoPEuXyJikauFGioK/ePxkEXleTRATmaVQZLPVJI R2sEEP8qXf7CiPaHmWhN7dTjWE34xc0ttWxchQTx+FzWLT5ifgL3HSX83hDeM2B8qY0k kTk1+yfbXqMOFsKkIrxfz1AFZ4v/LM/xFn3o1j4kGtYoW5PueHk6/ypPwKRb9YxKR2oy xTqAWljCo47AUIdl0aijMflBmviGtUFHjiVMeDhpDgDKjsMUy1mQ/fJ6BXPlsbLRhHhw Jnhw== X-Gm-Message-State: AOUpUlEhjWcbgajol6pNurgDdAsFJFSdR/LRWsv3BpulpE4MAIGgokKR cVSFeEBwPRCrOwG9DIgThyjkggbg X-Google-Smtp-Source: AA+uWPxZktwthUj30QfqPQ3EEKeNhzoujuVZqwuulnuHaEaucGRBK3ZqUYSAnjUflQm5HH5L/rOMZA== X-Received: by 2002:aa7:8713:: with SMTP id b19-v6mr2180987pfo.151.1533817989910; Thu, 09 Aug 2018 05:33:09 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Thu, 9 Aug 2018 09:42:19 +0530 Message-Id: <1533787939-28634-12-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.27]); Thu, 09 Aug 2018 12:33:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 09 Aug 2018 12:33:10 +0000 (UTC) for IP:'209.85.215.193' DOMAIN:'mail-pg1-f193.google.com' HELO:'mail-pg1-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.215.193 mail-pg1-f193.google.com 209.85.215.193 mail-pg1-f193.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 11/11] util: qemu: 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 09 Aug 2018 12:33: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_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 --- src/util/virqemu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/virqemu.c b/src/util/virqemu.c index bc78853..1cd2b93 100644 --- a/src/util/virqemu.c +++ b/src/util/virqemu.c @@ -281,6 +281,7 @@ virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr sr= cdef) cleanup: virBufferFreeAndReset(&buf); return ret; + } =20 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list