From nobody Tue May 13 11:08:59 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 1532639121136786.1825822997157; Thu, 26 Jul 2018 14:05:21 -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 F00E18110C; Thu, 26 Jul 2018 21:05:13 +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 A773E308BDB3; Thu, 26 Jul 2018 21:05:13 +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 48F6318037F3; Thu, 26 Jul 2018 21:05:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6QL59oO024782 for ; Thu, 26 Jul 2018 17:05:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id C2DD860C80; Thu, 26 Jul 2018 21:05:09 +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 B5A4260C8C for ; Thu, 26 Jul 2018 21:05:03 +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 672B630E6844 for ; Thu, 26 Jul 2018 21:05:02 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id z8-v6so1882228pgu.8 for ; Thu, 26 Jul 2018 14:05:02 -0700 (PDT) Received: from centos.localdomain ([42.106.3.93]) by smtp.gmail.com with ESMTPSA id z10-v6sm3279182pfh.83.2018.07.26.14.04.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jul 2018 14:05:01 -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=XpARbo5wsw7gdKn8xfTDEQkGF3bpRdcZemYtN9CadCA=; b=QvM0H8dxS7Q8ZsVtcp5vVD69xcUn4t8ysQ9/1V2DB5J76WhmvP4oVudWagAMyPdRJR ROqh+xWopNmJgMgSAcjfERUClbLSdHva7AiBgYdCWsmmExsiCXnO+ouIk+cUB3zUxSuC UhYF+0o6ApYHHzxZd2H0e3aI1avgsr5XNDJmojnNZmA0sv0IGR8fJgar4nyYkjXtJtN5 1lgEYHgmBZw6niK9Aew/lkvGESFtSnebYDXboCSAktjHt4hI2TxouiL1a1MCQezytVC3 ouBGDJgAjgOnU30XDkxD81pMavhWIZ0C6LXM384f8AaNfVwAZBzMHb8sZuBsuszMJugm MS/Q== 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=XpARbo5wsw7gdKn8xfTDEQkGF3bpRdcZemYtN9CadCA=; b=dQ36FJB0+VDyy2yDo8q61MejzQGDbo6weVnkoV2SdOdqR1b2Wju9dzssqwfnwuNzGk IGBT3vn7jzdJ5ZUS4ieqEMF/ZJgMWJO9ksnWw4MbivJTqv5dt+Og7n7jmWfeFSrzp84p PujFbFUZ1K1sh5xTkn/0+spiN0tL62oQk/kVXRqDQ/wWVzNKcToMeymeaBJWh2Iyp9bB zK2XbuSfGiXecHOm72sTRVrjhiX1r9+J51B4zX0/UD5TELPDiqHXa9DJancPWtoAjgi1 ryfvKfm24+osVyNqqU4deOunf+uy4VKM9RdeHv70HnPVeAzwwXpNe2rygq4XzLLXGiM6 Px6w== X-Gm-Message-State: AOUpUlE5+fPPPqUszJ3Kd2AAAeS1UF5K4mUc/ZEC303EHBxg/v4SmrJz uXlb2b/96MOFKY9Nz6mvtmN2TO77 X-Google-Smtp-Source: AAOMgpcLWCTsmxvswvM9LN6ZJ1L/c8Q7kV06PtDy2njFM977PRKUwCiSNTjsUhgAj0zdDrCD7cEtJg== X-Received: by 2002:a63:e60c:: with SMTP id g12-v6mr3432605pgh.308.1532639101615; Thu, 26 Jul 2018 14:05:01 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Tue, 24 Jul 2018 21:22:13 +0530 Message-Id: <1532447562-24010-13-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.46]); Thu, 26 Jul 2018 21:05:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 26 Jul 2018 21:05:02 +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: 1.389 * (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_SORBS_WEB, 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.46 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 12/41] util: mdev: 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.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 26 Jul 2018 21:05:19 +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_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/virmdev.c | 53 +++++++++++++++++++-------------------------------= --- 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/src/util/virmdev.c b/src/util/virmdev.c index d7bcb1d..81fb847 100644 --- a/src/util/virmdev.c +++ b/src/util/virmdev.c @@ -72,24 +72,23 @@ static int virMediatedDeviceGetSysfsDeviceAPI(virMediatedDevicePtr dev, char **device_api) { - int ret =3D -1; - char *buf =3D NULL; - char *file =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; + VIR_AUTOFREE(char *) file =3D NULL; char *tmp =3D NULL; =20 if (virAsprintf(&file, "%s/mdev_type/device_api", dev->path) < 0) - goto cleanup; + return -1; =20 /* TODO - make this a generic method to access sysfs files for various * kinds of devices */ if (!virFileExists(file)) { virReportSystemError(errno, _("failed to read '%s'"), file); - goto cleanup; + return -1; } =20 if (virFileReadAll(file, 1024, &buf) < 0) - goto cleanup; + return -1; =20 if ((tmp =3D strchr(buf, '\n'))) *tmp =3D '\0'; @@ -97,11 +96,7 @@ virMediatedDeviceGetSysfsDeviceAPI(virMediatedDevicePtr = dev, *device_api =3D buf; buf =3D NULL; =20 - ret =3D 0; - cleanup: - VIR_FREE(file); - VIR_FREE(buf); - return ret; + return 0; } =20 =20 @@ -109,8 +104,7 @@ static int virMediatedDeviceCheckModel(virMediatedDevicePtr dev, virMediatedDeviceModelType model) { - int ret =3D -1; - char *dev_api =3D NULL; + VIR_AUTOFREE(char *) dev_api =3D NULL; int actual_model; =20 if (virMediatedDeviceGetSysfsDeviceAPI(dev, &dev_api) < 0) @@ -123,7 +117,7 @@ virMediatedDeviceCheckModel(virMediatedDevicePtr dev, virReportError(VIR_ERR_INTERNAL_ERROR, _("device API '%s' not supported yet"), dev_api); - goto cleanup; + return -1; } =20 if (actual_model !=3D model) { @@ -132,13 +126,10 @@ virMediatedDeviceCheckModel(virMediatedDevicePtr dev, "device only supports '%s'"), virMediatedDeviceModelTypeToString(model), dev->path, dev_api); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(dev_api); - return ret; + return 0; } =20 =20 @@ -147,7 +138,7 @@ virMediatedDeviceNew(const char *uuidstr, virMediatedDe= viceModelType model) { virMediatedDevicePtr ret =3D NULL; virMediatedDevicePtr dev =3D NULL; - char *sysfspath =3D NULL; + VIR_AUTOFREE(char *) sysfspath =3D NULL; =20 if (!(sysfspath =3D virMediatedDeviceGetSysfsPath(uuidstr))) goto cleanup; @@ -173,7 +164,6 @@ virMediatedDeviceNew(const char *uuidstr, virMediatedDe= viceModelType model) VIR_STEAL_PTR(ret, dev); =20 cleanup: - VIR_FREE(sysfspath); virMediatedDeviceFree(dev); return ret; } @@ -218,34 +208,30 @@ virMediatedDeviceGetPath(virMediatedDevicePtr dev) char * virMediatedDeviceGetIOMMUGroupDev(const char *uuidstr) { - char *result_path =3D NULL; - char *iommu_path =3D NULL; + VIR_AUTOFREE(char *) result_path =3D NULL; + VIR_AUTOFREE(char *) iommu_path =3D NULL; + VIR_AUTOFREE(char *) dev_path =3D virMediatedDeviceGetSysfsPath(uuidst= r); char *vfio_path =3D NULL; - char *dev_path =3D virMediatedDeviceGetSysfsPath(uuidstr); =20 if (!dev_path) return NULL; =20 if (virAsprintf(&iommu_path, "%s/iommu_group", dev_path) < 0) - goto cleanup; + return NULL; =20 if (!virFileExists(iommu_path)) { virReportSystemError(errno, _("failed to access '%s'"), iommu_path= ); - goto cleanup; + return NULL; } =20 if (virFileResolveLink(iommu_path, &result_path) < 0) { virReportSystemError(errno, _("failed to resolve '%s'"), iommu_pat= h); - goto cleanup; + return NULL; } =20 if (virAsprintf(&vfio_path, "/dev/vfio/%s", last_component(result_path= )) < 0) - goto cleanup; + return NULL; =20 - cleanup: - VIR_FREE(result_path); - VIR_FREE(iommu_path); - VIR_FREE(dev_path); return vfio_path; } =20 @@ -253,7 +239,7 @@ virMediatedDeviceGetIOMMUGroupDev(const char *uuidstr) int virMediatedDeviceGetIOMMUGroupNum(const char *uuidstr) { - char *vfio_path =3D NULL; + VIR_AUTOFREE(char *) vfio_path =3D NULL; char *group_num_str =3D NULL; unsigned int group_num =3D -1; =20 @@ -263,7 +249,6 @@ virMediatedDeviceGetIOMMUGroupNum(const char *uuidstr) group_num_str =3D last_component(vfio_path); ignore_value(virStrToLong_ui(group_num_str, NULL, 10, &group_num)); =20 - VIR_FREE(vfio_path); return group_num; } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list