From nobody Thu Apr 25 11:29:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1578693090; cv=none; d=zohomail.com; s=zohoarc; b=agxdHtBxpr9bMAtKSBgPqN9WdSv9OlO088actJTButp/Y3VsDB94GW1rKbWZzXFnitTjWUdnnFCIcvfHNPETF+Pqe2m/eMxiYvFHPbAyioUCIp/FIbDlahx7iLd1wqBvJkLqYjGRuyLQKFT9Go+xUCbaY7LBOR0ms7D1F0i/GmE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578693090; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=6RQSIB+L+hK9qcQfsHaJVEoGxhj/S2aQr+42nhFWJD0=; b=Nam6X0iGgOxLoPI9ITzWPQF5k1QwjvgMdaN6l5lag+pxmF9e3tEFiRPq6C3rd5xjL9PAv7R41ZhWOExOPGTY0BXgn1bv/cPx8tz6WGyyUXX9SgXxAwP8pSrTULZSqe6qRNuT8coGcGfRpKZJGr9sG34+GYrv7JC4nZfaYEU2V0g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1578693090241920.3014509182939; Fri, 10 Jan 2020 13:51:30 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-17-sE3b7K_IOoaUlc3aqNi8cw-1; Fri, 10 Jan 2020 16:51:27 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 68433800A02; Fri, 10 Jan 2020 21:51:21 +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 B837A78E77; Fri, 10 Jan 2020 21:51:18 +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 934F018089CD; Fri, 10 Jan 2020 21:51:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 00ALpBJN012468 for ; Fri, 10 Jan 2020 16:51:11 -0500 Received: by smtp.corp.redhat.com (Postfix) id 20B0F5DA66; Fri, 10 Jan 2020 21:51:11 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-117-214.phx2.redhat.com [10.3.117.214]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E16875DA60 for ; Fri, 10 Jan 2020 21:51:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578693088; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=6RQSIB+L+hK9qcQfsHaJVEoGxhj/S2aQr+42nhFWJD0=; b=GqKCMqODhAK/F0hf/3A7l+wgTaQUjneto3H/rIDnKhSIhTnQLpyGE7EkFn74oYkPUbY8qV mDNYODq4+vRHbDHUxy5zeiBOGTPvSIfH+C4V33UZ6dNGL+JAZqKHKEIVFMx6KQv4X5yNE4 EeESStx2i9zbHWJ2JQ1A6VLSEYjk9tg= From: Jonathon Jongsma To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 15:51:07 -0600 Message-Id: <20200110215107.8628-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] nodedev: use autofree for more local variables 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: , 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-MC-Unique: sE3b7K_IOoaUlc3aqNi8cw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Simplify function logic by using g_autofree to free local variables so that we can remove some goto statements that are used for cleanup. Introduce a g_autoptr cleanup function for virNodeDeviceDef. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- src/conf/node_device_conf.h | 2 ++ src/node_device/node_device_driver.c | 47 +++++++++++----------------- 2 files changed, 20 insertions(+), 29 deletions(-) diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index bf7939fbb3..4ff616ee90 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -344,6 +344,8 @@ virNodeDeviceGetWWNs(virNodeDeviceDefPtr def, void virNodeDeviceDefFree(virNodeDeviceDefPtr def); =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNodeDeviceDef, virNodeDeviceDefFree); + void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps); =20 diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index b630be4399..fda77ede24 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -106,10 +106,9 @@ int nodeConnectIsAlive(virConnectPtr conn G_GNUC_UNUSE= D) static int nodeDeviceUpdateDriverName(virNodeDeviceDefPtr def) { - char *driver_link =3D NULL; - char *devpath =3D NULL; + g_autofree char *driver_link =3D NULL; + g_autofree char *devpath =3D NULL; char *p; - int ret =3D -1; =20 VIR_FREE(def->driver); =20 @@ -117,26 +116,20 @@ nodeDeviceUpdateDriverName(virNodeDeviceDefPtr def) =20 /* Some devices don't have an explicit driver, so just return without a name */ - if (access(driver_link, R_OK) < 0) { - ret =3D 0; - goto cleanup; - } + if (access(driver_link, R_OK) < 0) + return 0; =20 if (virFileResolveLink(driver_link, &devpath) < 0) { virReportSystemError(errno, _("cannot resolve driver link %s"), driver_li= nk); - goto cleanup; + return -1; } =20 p =3D strrchr(devpath, '/'); if (p) def->driver =3D g_strdup(p + 1); - ret =3D 0; =20 - cleanup: - VIR_FREE(driver_link); - VIR_FREE(devpath); - return ret; + return 0; } #else /* XXX: Implement me for non-linux */ @@ -468,8 +461,9 @@ nodeDeviceCreateXML(virConnectPtr conn, const char *xmlDesc, unsigned int flags) { - virNodeDeviceDefPtr def =3D NULL; - char *wwnn =3D NULL, *wwpn =3D NULL; + g_autoptr(virNodeDeviceDef) def =3D NULL; + g_autofree char *wwnn =3D NULL; + g_autofree char *wwpn =3D NULL; int parent_host =3D -1; virNodeDevicePtr device =3D NULL; const char *virt_type =3D NULL; @@ -478,19 +472,19 @@ nodeDeviceCreateXML(virConnectPtr conn, virt_type =3D virConnectGetType(conn); =20 if (!(def =3D virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE, virt= _type))) - goto cleanup; + return NULL; =20 if (virNodeDeviceCreateXMLEnsureACL(conn, def) < 0) - goto cleanup; + return NULL; =20 if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) =3D=3D -1) - goto cleanup; + return NULL; =20 if ((parent_host =3D virNodeDeviceObjListGetParentHost(driver->devs, d= ef)) < 0) - goto cleanup; + return NULL; =20 if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_CREATE) < 0) - goto cleanup; + return NULL; =20 device =3D nodeDeviceFindNewDevice(conn, wwnn, wwpn); /* We don't check the return value, because one way or another, @@ -501,10 +495,7 @@ nodeDeviceCreateXML(virConnectPtr conn, _("no node device for '%s' with matching " "wwnn '%s' and wwpn '%s'"), def->name, wwnn, wwpn); - cleanup: - virNodeDeviceDefFree(def); - VIR_FREE(wwnn); - VIR_FREE(wwpn); + return device; } =20 @@ -515,8 +506,9 @@ nodeDeviceDestroy(virNodeDevicePtr device) int ret =3D -1; virNodeDeviceObjPtr obj =3D NULL; virNodeDeviceDefPtr def; - char *parent =3D NULL; - char *wwnn =3D NULL, *wwpn =3D NULL; + g_autofree char *parent =3D NULL; + g_autofree char *wwnn =3D NULL; + g_autofree char *wwpn =3D NULL; unsigned int parent_host; =20 if (!(obj =3D nodeDeviceObjFindByName(device->name))) @@ -554,9 +546,6 @@ nodeDeviceDestroy(virNodeDevicePtr device) =20 cleanup: virNodeDeviceObjEndAPI(&obj); - VIR_FREE(parent); - VIR_FREE(wwnn); - VIR_FREE(wwpn); return ret; } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list