From nobody Mon Feb 9 19:26:13 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533714259474506.56370216294727; Wed, 8 Aug 2018 00:44:19 -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 BC3A05F737; Wed, 8 Aug 2018 07:44:16 +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 85BD8381AA; Wed, 8 Aug 2018 07:44: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 B026F24F5C; Wed, 8 Aug 2018 07:44:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787iA4h005876 for ; Wed, 8 Aug 2018 03:44:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 45BD0308BDBA; Wed, 8 Aug 2018 07:44:10 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3BEEA308BDB6 for ; Wed, 8 Aug 2018 07:44:10 +0000 (UTC) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.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 4B51C307D85A for ; Wed, 8 Aug 2018 07:44:09 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id u24-v6so701257pfn.13 for ; Wed, 08 Aug 2018 00:44:09 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.44.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:44:08 -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=PyS2hndPCwJupUgY8nfMlWEj38wGiuTXbh1XZg2iG0U=; b=JOSBH8MH10oHWfqLTOTH7Ae3LLLOKjAfo19TSFX+t/qdDnD/B/blQY6zMAQ+CyeUsF yrmcs7yzyPJ5Pyrs0OMazXhStfQjrW4g9ewB6auYOKQiowU7DXaEGVJUto64QbRV6sIP PJoQ+Boemq6rNaVWZ2g5JUjJ5MD8d0mv7HN4PgNRdEpDgu0yspMVo9IOHCn6s/X0Z+mq y+BLahyOymhNTFl1CLDA6eYk4bgQGXZg8YAM33eC2n0pkEHQ3fHF61XulXCtrA8DgeTE LbhQRvCBYnjyFWJUteaVdYUSmAmnvlCeP09/cQaPxYxyD2eNnxjZnhgH7lQtEy8kI0DV kUpg== 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=PyS2hndPCwJupUgY8nfMlWEj38wGiuTXbh1XZg2iG0U=; b=Y6XUTpm8oTnLO89b39GsuTYOac7MSEkTrcFEa7FcVpn2T95qA/S8Z0da3IGqLR0Gfx odvtjB+XfrUUOPcWz9jQ3va+wv0I6j9DHLWUvgJkmoaW5XuTLTS2ciZvBbgRbvO/BmQB 01978NvtJKGz54DWBeQ2qRGlcC+N+TBPrpXb14Y3doVGD86JaoGlZEIGq9C31kfrF9JH NLJ594Bel5ujCsltWhZ/gZvOXnjdv2RESUmqMU2lDDbrdsB5Jd+m15WHAbjMbjsFa04u rfXSxlgXxAsJ1tLxIldEIJou7oG6eZQsln0XQFVE0lULm+m2qjYJ0fZTgO9xSCsgKwJF QGkA== X-Gm-Message-State: AOUpUlG65fa8pEZC07EK3kzQGDisIJaHoijcUhKVAshczn+1rqepbyyf f7AO1Xa7vfGW+ubOrmjzz9B5Kpn2 X-Google-Smtp-Source: AA+uWPyYW+siLaIctoyeGS+fC33L8bzIrc+wKNHpY1lRLRYw1zCiOMNWZQY8iu9dvLgiF+8m1f9D7w== X-Received: by 2002:a62:411a:: with SMTP id o26-v6mr1690568pfa.111.1533714248470; Wed, 08 Aug 2018 00:44:08 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:55 +0530 Message-Id: <1533501842-24503-29-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 08 Aug 2018 07:44:09 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 08 Aug 2018 07:44:09 +0000 (UTC) for IP:'209.85.210.196' DOMAIN:'mail-pf1-f196.google.com' HELO:'mail-pf1-f196.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (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.196 mail-pf1-f196.google.com 209.85.210.196 mail-pf1-f196.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 28/35] util: numa: 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.39]); Wed, 08 Aug 2018 07:44:18 +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/virnuma.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/src/util/virnuma.c b/src/util/virnuma.c index 6c6be1c..c1457be 100644 --- a/src/util/virnuma.c +++ b/src/util/virnuma.c @@ -57,8 +57,8 @@ char * virNumaGetAutoPlacementAdvice(unsigned short vcpus, unsigned long long balloon) { - virCommandPtr cmd =3D NULL; char *output =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNewArgList(NUMAD, "-w", NULL); virCommandAddArgFormat(cmd, "%d:%llu", vcpus, @@ -71,7 +71,6 @@ virNumaGetAutoPlacementAdvice(unsigned short vcpus, _("Failed to query numad for the " "advisory nodeset")); =20 - virCommandFree(cmd); return output; } #else /* !HAVE_NUMAD */ @@ -252,41 +251,38 @@ int virNumaGetNodeCPUs(int node, virBitmapPtr *cpus) { + VIR_AUTOPTR(virBitmap) cpumap =3D NULL; VIR_AUTOFREE(unsigned long *) mask =3D NULL; VIR_AUTOFREE(unsigned long *) allonesmask =3D NULL; - virBitmapPtr cpumap =3D NULL; int ncpus =3D 0; int max_n_cpus =3D virNumaGetMaxCPUs(); int mask_n_bytes =3D max_n_cpus / 8; size_t i; - int ret =3D -1; =20 *cpus =3D NULL; =20 if (VIR_ALLOC_N(mask, mask_n_bytes / sizeof(*mask)) < 0) - goto cleanup; + return -1; =20 if (VIR_ALLOC_N(allonesmask, mask_n_bytes / sizeof(*mask)) < 0) - goto cleanup; + return -1; =20 memset(allonesmask, 0xff, mask_n_bytes); =20 /* The first time this returns -1, ENOENT if node doesn't exist... */ if (numa_node_to_cpus(node, mask, mask_n_bytes) < 0) { VIR_WARN("NUMA topology for cell %d is not available, ignoring", n= ode); - ret =3D -2; - goto cleanup; + return -2; } =20 /* second, third... times it returns an all-1's mask */ if (memcmp(mask, allonesmask, mask_n_bytes) =3D=3D 0) { VIR_DEBUG("NUMA topology for cell %d is invalid, ignoring", node); - ret =3D -2; - goto cleanup; + return -2; } =20 if (!(cpumap =3D virBitmapNew(max_n_cpus))) - goto cleanup; + return -1; =20 for (i =3D 0; i < max_n_cpus; i++) { if (MASK_CPU_ISSET(mask, i)) { @@ -295,14 +291,8 @@ virNumaGetNodeCPUs(int node, } } =20 - *cpus =3D cpumap; - cpumap =3D NULL; - ret =3D ncpus; - - cleanup: - virBitmapFree(cpumap); - - return ret; + VIR_STEAL_PTR(*cpus, cpumap); + return ncpus; } # undef MASK_CPU_ISSET # undef n_bits --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list