From nobody Tue May 13 11:18:10 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 1532639132304316.7400742265427; Thu, 26 Jul 2018 14:05:32 -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 8682C308403D; Thu, 26 Jul 2018 21:05:25 +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 4545F60C9A; Thu, 26 Jul 2018 21:05:25 +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 D217F3F7CB; Thu, 26 Jul 2018 21:05:24 +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 w6QL58Wl024776 for ; Thu, 26 Jul 2018 17:05:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 94C5B10E4D01; Thu, 26 Jul 2018 21:05:08 +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 8AE4610E4D00 for ; Thu, 26 Jul 2018 21:05:06 +0000 (UTC) Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (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 67BAB8CD3 for ; Thu, 26 Jul 2018 21:05:04 +0000 (UTC) Received: by mail-pg1-f170.google.com with SMTP id v13-v6so1877714pgr.10 for ; Thu, 26 Jul 2018 14:05:04 -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.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jul 2018 14:05: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=Ua6whswXA7n3C4wMPUomNRgl1JyQhr784YL5wBCwOfA=; b=XfOtD3X3eGBgXq+Ah32bz74Cg9XlLgw/D7EPf5VJa0UlrJGjmohwN5zVduNoi94mAf 7ttRgzN6lrtdu9C8aXXwxJ7vWcC07qBsbLk4l1Ry7OQz++5jxGVKY5Do0CdvyW4sxyXR yupI/JuyWTJn18TD2N+fcJhErt3pNc6yznExvGLRXpavwK/WXHX9fxsynLerWgzxRiah 29o8HbjXdhBu0iQiQXeEWrtLU2p9gZdZtTwqgip3zbskKvzOHalSuSEDo1M8w53Qv58B R+N0s1PltKPvOkVYfUxfM1xTExF11pCpDJqlzR9/YSgVjono6KayHSDg3AELzsEiv9+h VRRQ== 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=Ua6whswXA7n3C4wMPUomNRgl1JyQhr784YL5wBCwOfA=; b=MmGEdWPC4dwAaUf6z1PTJYDirUlLUX7fNH7ScQslZKChNxPJy1BixrjgmDLgPcBnWE ZeFNRHUKaGhugOd8pv9ve3qpICfvKRc3Mf+lYMv3TORJbwSf0IZrTTlQ//OeQq19giPJ 5F20V6EjYkz3jqI4bg4vofaMs7wfi6DIrLpRu8CarHCyIFMbA1EKjOMkLpx05vZWmpDV fBrIB+1QJG9WZ6yxCEDnzMB4aVdJnp4jA8+zR24+eHLjX0F75PLhidIIeV8XkWk9YPSU btTWdbNK8ImyElfYRWrY4tDWMldzt9sNFyaW6h1pUPXddgo3gvF5x8cLvwpztRzao/WM s7DA== X-Gm-Message-State: AOUpUlGC4V4zSqek5MYKVl5c3Ewlg01jPVC/GA4DfSPnqfDaUcNxIrGg QXzLAzHpeLKssKyBfbx0OMJmuP57 X-Google-Smtp-Source: AAOMgpcWJv3qEilcFzFd96kRqbRwynokPFmcFBAChmZVCryqHggfaes2akRpw2tSqIug04FWpa36Qg== X-Received: by 2002:a63:704f:: with SMTP id a15-v6mr3359528pgn.443.1532639103458; Thu, 26 Jul 2018 14:05:03 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Tue, 24 Jul 2018 21:22:14 +0530 Message-Id: <1532447562-24010-14-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:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 26 Jul 2018 21:05:04 +0000 (UTC) for IP:'209.85.215.170' DOMAIN:'mail-pg1-f170.google.com' HELO:'mail-pg1-f170.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.170 mail-pg1-f170.google.com 209.85.215.170 mail-pg1-f170.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 13/41] util: mdev: 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.40]); Thu, 26 Jul 2018 21:05:26 +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/virmdev.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/util/virmdev.c b/src/util/virmdev.c index 81fb847..4050835 100644 --- a/src/util/virmdev.c +++ b/src/util/virmdev.c @@ -137,20 +137,20 @@ virMediatedDevicePtr virMediatedDeviceNew(const char *uuidstr, virMediatedDeviceModelType model) { virMediatedDevicePtr ret =3D NULL; - virMediatedDevicePtr dev =3D NULL; + VIR_AUTOPTR(virMediatedDevice) dev =3D NULL; VIR_AUTOFREE(char *) sysfspath =3D NULL; =20 if (!(sysfspath =3D virMediatedDeviceGetSysfsPath(uuidstr))) - goto cleanup; + return NULL; =20 if (!virFileExists(sysfspath)) { virReportError(VIR_ERR_DEVICE_MISSING, _("mediated device '%s' not found"), uuidstr); - goto cleanup; + return NULL; } =20 if (VIR_ALLOC(dev) < 0) - goto cleanup; + return NULL; =20 VIR_STEAL_PTR(dev->path, sysfspath); =20 @@ -158,13 +158,11 @@ virMediatedDeviceNew(const char *uuidstr, virMediated= DeviceModelType model) * supported mediated device's API. */ if (virMediatedDeviceCheckModel(dev, model)) - goto cleanup; + return NULL; =20 dev->model =3D model; VIR_STEAL_PTR(ret, dev); =20 - cleanup: - virMediatedDeviceFree(dev); return ret; } =20 @@ -372,8 +370,7 @@ void virMediatedDeviceListDel(virMediatedDeviceListPtr list, virMediatedDevicePtr dev) { - virMediatedDevicePtr ret =3D virMediatedDeviceListSteal(list, dev); - virMediatedDeviceFree(ret); + VIR_AUTOPTR(virMediatedDevice) ret =3D virMediatedDeviceListSteal(list= , dev); } =20 =20 @@ -494,23 +491,22 @@ int virMediatedDeviceTypeReadAttrs(const char *sysfspath, virMediatedDeviceTypePtr *type) { - int ret =3D -1; - virMediatedDeviceTypePtr tmp =3D NULL; + VIR_AUTOPTR(virMediatedDeviceType) tmp =3D NULL; =20 #define MDEV_GET_SYSFS_ATTR(attr, dst, cb, optional) \ do { \ int rc; \ if ((rc =3D cb(dst, "%s/%s", sysfspath, attr)) < 0) { \ if (rc !=3D -2 || !optional) \ - goto cleanup; \ + return -1; \ } \ } while (0) =20 if (VIR_ALLOC(tmp) < 0) - goto cleanup; + return -1; =20 if (VIR_STRDUP(tmp->id, last_component(sysfspath)) < 0) - goto cleanup; + return -1; =20 /* @name sysfs attribute is optional, so getting ENOENT is fine */ MDEV_GET_SYSFS_ATTR("name", &tmp->name, virFileReadValueString, true); @@ -522,8 +518,6 @@ virMediatedDeviceTypeReadAttrs(const char *sysfspath, #undef MDEV_GET_SYSFS_ATTR =20 VIR_STEAL_PTR(*type, tmp); - ret =3D 0; - cleanup: - virMediatedDeviceTypeFree(tmp); - 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