From nobody Mon Feb 9 21:24:23 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 1533714270054694.0235655385119; Wed, 8 Aug 2018 00:44:30 -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 7EF78C015C20; Wed, 8 Aug 2018 07:44:27 +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 D751B6252D; Wed, 8 Aug 2018 07:44: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 92CF41800B6F; Wed, 8 Aug 2018 07:44:26 +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 w787iFvH005921 for ; Wed, 8 Aug 2018 03:44:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 718B765963; Wed, 8 Aug 2018 07:44:15 +0000 (UTC) Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5C9E16595B for ; Wed, 8 Aug 2018 07:44:08 +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 7414030B8F84 for ; Wed, 8 Aug 2018 07:44:07 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id z8-v6so685155pgu.8 for ; Wed, 08 Aug 2018 00:44:07 -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.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:44: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=hy7DDCMXZN+ZVPkT8xAhmQtcp8HnlHc1aOlW/voRLjc=; b=TXxau36F7BUylzkR5Nw2KP+lpl1PlqofrSjvDcvIylctbp05aEAPe7yY5YassICTrG soJxQ1AxvU454tF2wgOsCkOlaRuttaWiidw9f5wxH5pSwmsVa/CgjJXql9Ceg/GgTHoK BmwGAFiWdoBpuKWFDoirKwCFNo5zee4sPuGB9Th3YE+4tH4S5wXbG3adnp8wJbX4vRYX dzGet7t6He/gCos0GvLSdwpwo89hJQjxsltVfwh35OmcIwGVAxqcLZJKqDPa36IJBIVt 6vFv1Nez22zxz+Id0nj067cdzH/VvHn6du371XJJV+Rfj5IyFHD7/EVuRmx1WgqH4mGi Odqg== 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=hy7DDCMXZN+ZVPkT8xAhmQtcp8HnlHc1aOlW/voRLjc=; b=WK7J9J7BbWb63y5rrwHeW+VbMi7CYAUybfmTUCrpUjuZfZp8LOgZ9UwY0WdgSnXa2C 6kQkvXK27RgzQkk66d1Kloho0Q5wRA2mtBJDLdEbHfk/4sZtezX3e/3WmKZ50s+aloW7 UTIZozb/NVtS5Cd42N9sZWjOUVL9MkDo8w04Xfar/RFtjQGyNwgjFOnPUCnVLTUZBQDn /BA5eH3iT60UqYTm0urujyDgXrzSWbRZQ5FKCMtLVMpq5iJSMXZSUwLa12LjB2BEZuHc ljuK7y8HzD7bi7FGq7QML7fNrXJrDquUzYf/QdyOFmQwadI3GgS8+kKVaa0wMPT4sjOg XaKw== X-Gm-Message-State: AOUpUlEmIrGjKOA8O7ZsQa3sc//quA3+kziPXaf3SCxJrPbZPRkT/aLm kSdpUloUJPLjJVUkjtGjHHtiTWQS X-Google-Smtp-Source: AA+uWPzby5uRhn/pymJbhyjamDm4OQ4X1kDWdGMSsdrlBKYMBqLJPIpAP7SQY0PY+tpOwunkUUpscw== X-Received: by 2002:a63:f713:: with SMTP id x19-v6mr1453800pgh.233.1533714246704; Wed, 08 Aug 2018 00:44:06 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:54 +0530 Message-Id: <1533501842-24503-28-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.49]); Wed, 08 Aug 2018 07:44:07 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 08 Aug 2018 07:44:07 +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.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.215.196 mail-pg1-f196.google.com 209.85.215.196 mail-pg1-f196.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.49 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 27/35] util: numa: use VIR_AUTOFREE instead of VIR_FREE for scalar types X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 08 Aug 2018 07:44:28 +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/virnuma.c | 75 +++++++++++++++++++++-----------------------------= ---- 1 file changed, 29 insertions(+), 46 deletions(-) diff --git a/src/util/virnuma.c b/src/util/virnuma.c index 784db0a..6c6be1c 100644 --- a/src/util/virnuma.c +++ b/src/util/virnuma.c @@ -252,8 +252,8 @@ int virNumaGetNodeCPUs(int node, virBitmapPtr *cpus) { - unsigned long *mask =3D NULL; - unsigned long *allonesmask =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(); @@ -300,8 +300,6 @@ virNumaGetNodeCPUs(int node, ret =3D ncpus; =20 cleanup: - VIR_FREE(mask); - VIR_FREE(allonesmask); virBitmapFree(cpumap); =20 return ret; @@ -566,25 +564,24 @@ virNumaGetHugePageInfo(int node, unsigned long long *page_avail, unsigned long long *page_free) { - int ret =3D -1; - char *path =3D NULL; - char *buf =3D NULL; char *end; + VIR_AUTOFREE(char *) buf =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (page_avail) { if (virNumaGetHugePageInfoPath(&path, node, page_size, "nr_hugepages") < 0) - goto cleanup; + return -1; =20 if (virFileReadAll(path, 1024, &buf) < 0) - goto cleanup; + return -1; =20 if (virStrToLong_ull(buf, &end, 10, page_avail) < 0 || *end !=3D '\n') { virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to parse: %s"), buf); - goto cleanup; + return -1; } VIR_FREE(buf); VIR_FREE(path); @@ -593,25 +590,21 @@ virNumaGetHugePageInfo(int node, if (page_free) { if (virNumaGetHugePageInfoPath(&path, node, page_size, "free_hugepages") < 0) - goto cleanup; + return -1; =20 if (virFileReadAll(path, 1024, &buf) < 0) - goto cleanup; + return -1; =20 if (virStrToLong_ull(buf, &end, 10, page_free) < 0 || *end !=3D '\n') { virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to parse: %s"), buf); - goto cleanup; + return -1; } } =20 - ret =3D 0; - cleanup: - VIR_FREE(buf); - VIR_FREE(path); - return ret; + return 0; } =20 /** @@ -714,13 +707,13 @@ virNumaGetPages(int node, size_t *npages) { int ret =3D -1; - char *path =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(unsigned int *) tmp_size =3D NULL; + VIR_AUTOFREE(unsigned long long *) tmp_avail =3D NULL; + VIR_AUTOFREE(unsigned long long *) tmp_free =3D NULL; DIR *dir =3D NULL; int direrr =3D 0; struct dirent *entry; - unsigned int *tmp_size =3D NULL; - unsigned long long *tmp_avail =3D NULL; - unsigned long long *tmp_free =3D NULL; unsigned int ntmp =3D 0; size_t i; bool exchange; @@ -828,11 +821,7 @@ virNumaGetPages(int node, *npages =3D ntmp; ret =3D 0; cleanup: - VIR_FREE(tmp_free); - VIR_FREE(tmp_avail); - VIR_FREE(tmp_size); VIR_DIR_CLOSE(dir); - VIR_FREE(path); return ret; } =20 @@ -843,8 +832,8 @@ virNumaSetPagePoolSize(int node, unsigned long long page_count, bool add) { - int ret =3D -1; - char *nr_path =3D NULL, *nr_buf =3D NULL; + VIR_AUTOFREE(char *) nr_path =3D NULL; + VIR_AUTOFREE(char *) nr_buf =3D NULL; char *end; unsigned long long nr_count; =20 @@ -853,37 +842,35 @@ virNumaSetPagePoolSize(int node, * differently to huge pages. */ virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("system pages pool can't be modified")); - goto cleanup; + return -1; } =20 if (virNumaGetHugePageInfoPath(&nr_path, node, page_size, "nr_hugepage= s") < 0) - goto cleanup; + return -1; =20 /* Firstly check, if there's anything for us to do */ if (virFileReadAll(nr_path, 1024, &nr_buf) < 0) - goto cleanup; + return -1; =20 if (virStrToLong_ull(nr_buf, &end, 10, &nr_count) < 0 || *end !=3D '\n') { virReportError(VIR_ERR_OPERATION_FAILED, _("invalid number '%s' in '%s'"), nr_buf, nr_path); - goto cleanup; + return -1; } =20 if (add) { if (!page_count) { VIR_DEBUG("Nothing left to do: add =3D true page_count =3D 0"); - ret =3D 0; - goto cleanup; + return 0; } page_count +=3D nr_count; } else { if (nr_count =3D=3D page_count) { VIR_DEBUG("Nothing left to do: nr_count =3D page_count =3D %ll= u", page_count); - ret =3D 0; - goto cleanup; + return 0; } } =20 @@ -896,40 +883,36 @@ virNumaSetPagePoolSize(int node, */ VIR_FREE(nr_buf); if (virAsprintf(&nr_buf, "%llu", page_count) < 0) - goto cleanup; + return -1; =20 if (virFileWriteStr(nr_path, nr_buf, 0) < 0) { virReportSystemError(errno, _("Unable to write to: %s"), nr_path); - goto cleanup; + return -1; } =20 /* And now do the check. */ =20 VIR_FREE(nr_buf); if (virFileReadAll(nr_path, 1024, &nr_buf) < 0) - goto cleanup; + return -1; =20 if (virStrToLong_ull(nr_buf, &end, 10, &nr_count) < 0 || *end !=3D '\n') { virReportError(VIR_ERR_OPERATION_FAILED, _("invalid number '%s' in '%s'"), nr_buf, nr_path); - goto cleanup; + return -1; } =20 if (nr_count !=3D page_count) { virReportError(VIR_ERR_OPERATION_FAILED, _("Unable to allocate %llu pages. Allocated only %l= lu"), page_count, nr_count); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(nr_buf); - VIR_FREE(nr_path); - 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