From nobody Tue May 13 11:31:18 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153263915893887.77305451696543; Thu, 26 Jul 2018 14:05:58 -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 826A722C; Thu, 26 Jul 2018 21:05:43 +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 3E0CE3001A77; Thu, 26 Jul 2018 21:05:43 +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 DAF1B1800B6C; Thu, 26 Jul 2018 21:05:42 +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 w6QL5dbZ024989 for ; Thu, 26 Jul 2018 17:05:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id D2824308BDB2; Thu, 26 Jul 2018 21:05:39 +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 C778F308BDB1 for ; Thu, 26 Jul 2018 21:05:34 +0000 (UTC) Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (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 63B7532B68D for ; Thu, 26 Jul 2018 21:05:33 +0000 (UTC) Received: by mail-pg1-f180.google.com with SMTP id r5-v6so1894657pgv.0 for ; Thu, 26 Jul 2018 14:05:33 -0700 (PDT) Received: from centos.localdomain ([42.106.3.93]) by smtp.gmail.com with ESMTPSA id z10-v6sm3279182pfh.83.2018.07.26.14.05.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jul 2018 14:05:32 -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=mvvRPvFjy7sb0wj/nKXUvGsgg4EJxzskGQkv68LEPMg=; b=eYZjtoyhfpaDJ6dOwJipufLn6wNqxRJpDwhktCPEdfCD/2Pjzkpz8fR1k1Al2jknHC V/NpnpJ6lMcEePxbeZ6AWoI1j0pqGZQE4V3MRYJ6MqbTbje75N87X11baKH+9T2uSlsB Wf2mWUGFWhMW1EQs13ZjgZ7O3j7kfMBpSARa3Ty9N+xXGWN17XPGS4kxgL1ydlRXkgp6 NySX7XKK8E5ddV/nTv4eHm6hUEiKOA+vvvn6eE8yvJsifEiXK+wJtKd6XZboepxLRQUn ArEozytpKn1XrSdft+sduJrhaSkLSQdOr1NmjFwh0OgqI9ePp5RQJqSuaHpXF61Anc+K CWPA== 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=mvvRPvFjy7sb0wj/nKXUvGsgg4EJxzskGQkv68LEPMg=; b=ZmyDYSbzRc7UJlsQh3+x/FXBsPVS1w/wRL3NPgk4jsEqlzXpco9g8M7ObvzVBQixzm FOeFv/oAseWFnyaxbj+2zcOdwUFIB3gTDkSDirjFdyUS19ANCcTXG7n+vMJQPsgYZ0Pb msXmFYNBNzQPf5VvNLEKIKwZ9dky9IlxEyULEH1AHTkDCegZA0fJz9mjHrI3x5RzPg+j wAzCJCl3PsUvxyPNdH6WTdkoBOEscOQEHEY7loHYnNgbgd6KXlFv6Lyr2B/I8B33EmKf jiYT0Rsjvh7oN3fp9ajtKk1LPykHZPgs3P15DMk+4/9p7EL/Tl36MpsKKvIsq492ELO9 ZgVw== X-Gm-Message-State: AOUpUlG+Hzwzkb6kD/oJ4hHP6F3KoKxKsEzkwZvF/4HW4OGL71pSN863 d89f1K8n5UPNUxaiC6sKI794FrbV X-Google-Smtp-Source: AAOMgpfY1TiBltGiSkOYKX/ZCIO7bZcPXpHyS89RQy+DLhHuuvd4IzMxeumN3ra5inBOyKJAGzYlgw== X-Received: by 2002:a62:14ce:: with SMTP id 197-v6mr3723714pfu.222.1532639132648; Thu, 26 Jul 2018 14:05:32 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Tue, 24 Jul 2018 21:22:29 +0530 Message-Id: <1532447562-24010-29-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532447562-24010-1-git-send-email-skrtbhtngr@gmail.com> References: <1532447562-24010-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, 26 Jul 2018 21:05:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 26 Jul 2018 21:05:33 +0000 (UTC) for IP:'209.85.215.180' DOMAIN:'mail-pg1-f180.google.com' HELO:'mail-pg1-f180.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.37 * (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, SPF_PASS) 209.85.215.180 mail-pg1-f180.google.com 209.85.215.180 mail-pg1-f180.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 28/41] util: scsi: 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.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 26 Jul 2018 21:05:56 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: 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/virscsi.c | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/src/util/virscsi.c b/src/util/virscsi.c index ba0a688..f97f6b5 100644 --- a/src/util/virscsi.c +++ b/src/util/virscsi.c @@ -189,7 +189,8 @@ virSCSIDeviceNew(const char *sysfs_prefix, bool readonly, bool shareable) { - virSCSIDevicePtr dev, ret =3D NULL; + VIR_AUTOPTR(virSCSIDevice) dev =3D NULL; + virSCSIDevicePtr ret =3D NULL; VIR_AUTOFREE(char *) sg =3D NULL; VIR_AUTOFREE(char *) vendor_path =3D NULL; VIR_AUTOFREE(char *) model_path =3D NULL; @@ -207,46 +208,43 @@ virSCSIDeviceNew(const char *sysfs_prefix, dev->shareable =3D shareable; =20 if (!(sg =3D virSCSIDeviceGetSgName(prefix, adapter, bus, target, unit= ))) - goto cleanup; + return NULL; =20 if (virSCSIDeviceGetAdapterId(adapter, &dev->adapter) < 0) - goto cleanup; + return NULL; =20 if (virAsprintf(&dev->name, "%d:%u:%u:%llu", dev->adapter, dev->bus, dev->target, dev->unit) < 0 || virAsprintf(&dev->sg_path, "%s/%s", sysfs_prefix ? sysfs_prefix : "/dev", sg) < 0) - goto cleanup; + return NULL; =20 if (!virFileExists(dev->sg_path)) { virReportSystemError(errno, _("SCSI device '%s': could not access %s"), dev->name, dev->sg_path); - goto cleanup; + return NULL; } =20 if (virAsprintf(&vendor_path, "%s/%s/vendor", prefix, dev->name) < 0 || virAsprintf(&model_path, "%s/%s/model", prefix, dev->name) < 0) - goto cleanup; + return NULL; =20 if (virFileReadAll(vendor_path, 1024, &vendor) < 0) - goto cleanup; + return NULL; =20 if (virFileReadAll(model_path, 1024, &model) < 0) - goto cleanup; + return NULL; =20 virTrimSpaces(vendor, NULL); virTrimSpaces(model, NULL); =20 if (virAsprintf(&dev->id, "%s:%s", vendor, model) < 0) - goto cleanup; + return NULL; =20 - ret =3D dev; - cleanup: - if (!ret) - virSCSIDeviceFree(dev); + VIR_STEAL_PTR(ret, dev); return ret; } =20 @@ -281,21 +279,17 @@ virSCSIDeviceSetUsedBy(virSCSIDevicePtr dev, const char *drvname, const char *domname) { - virUsedByInfoPtr copy; + VIR_AUTOPTR(virUsedByInfo) copy =3D NULL; if (VIR_ALLOC(copy) < 0) return -1; if (VIR_STRDUP(copy->drvname, drvname) < 0 || VIR_STRDUP(copy->domname, domname) < 0) - goto cleanup; + return -1; =20 if (VIR_APPEND_ELEMENT(dev->used_by, dev->n_used_by, copy) < 0) - goto cleanup; + return -1; =20 return 0; - - cleanup: - virSCSIDeviceUsedByInfoFree(copy); - return -1; } =20 bool @@ -442,7 +436,6 @@ virSCSIDeviceListDel(virSCSIDeviceListPtr list, const char *drvname, const char *domname) { - virSCSIDevicePtr tmp =3D NULL; size_t i; =20 for (i =3D 0; i < dev->n_used_by; i++) { @@ -452,8 +445,8 @@ virSCSIDeviceListDel(virSCSIDeviceListPtr list, virSCSIDeviceUsedByInfoFree(dev->used_by[i]); VIR_DELETE_ELEMENT(dev->used_by, i, dev->n_used_by); } else { + VIR_AUTOPTR(virSCSIDevice) tmp =3D NULL; tmp =3D virSCSIDeviceListSteal(list, dev); - virSCSIDeviceFree(tmp); } break; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list