From nobody Sat Feb 7 11:05:16 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1609764939; cv=none; d=zohomail.com; s=zohoarc; b=EfojbKF0OsuhjoEBn5edvYIWACSbYfuE18QESqqZC4S6CWPbKiEKr+OSU3mAVpBX/0qtPO0f4GT4a/t0DOLhNwvnaNYEcCd/FUkFe/PEoufvhRbkliLMQO6qKLTlbgbzzM6oH3qdeoW3r31VIbQzIxFEk2n4iN0jJjUAQ+wr7bY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609764939; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mU6JXVxWXI1r8w5+sHUToc4p/D6vMgwMTfi7GhUCM9I=; b=K1pzqJOVcgS7pKkTCMDGLxaeBFMLH7edKxqlLLRF9UcPajSdkUfYZNy6YZlHAgncDhKfy6Miz5oBol1FID9LR3ayApoeyvS1znjsQ8aQc9D4PkIbCL/ZO0T1RTdqxcOXXLJt9aUOttuy0n+sQQOyufxl4JYjwtDYBb5T9XxZzVs= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1609764939166439.411840929998; Mon, 4 Jan 2021 04:55:39 -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-181-M2yzvlP5O1eURJyK_i4lqA-1; Mon, 04 Jan 2021 07:55:35 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 39F04C73BC; Mon, 4 Jan 2021 12:55:28 +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 1875760C13; Mon, 4 Jan 2021 12:55:28 +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 DB0711809CB1; Mon, 4 Jan 2021 12:55:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104CtJBd014229 for ; Mon, 4 Jan 2021 07:55:19 -0500 Received: by smtp.corp.redhat.com (Postfix) id E7D4B2026D48; Mon, 4 Jan 2021 12:55:18 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E27B92026D47 for ; Mon, 4 Jan 2021 12:55:18 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CEB93811E76 for ; Mon, 4 Jan 2021 12:55:18 +0000 (UTC) Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-373--uwzxZ51Ohuqztyat9oslw-1; Mon, 04 Jan 2021 07:55:16 -0500 Received: by mail-qk1-f179.google.com with SMTP id b64so23161808qkc.12 for ; Mon, 04 Jan 2021 04:55:16 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:ca55:7a5d:da5b:906f:bedd]) by smtp.gmail.com with ESMTPSA id m64sm2342866qkb.90.2021.01.04.04.55.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jan 2021 04:55:15 -0800 (PST) X-MC-Unique: M2yzvlP5O1eURJyK_i4lqA-1 X-MC-Unique: -uwzxZ51Ohuqztyat9oslw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mU6JXVxWXI1r8w5+sHUToc4p/D6vMgwMTfi7GhUCM9I=; b=VDgm0dReeoLHqTnYMVaY2YCZDj4uWp69lS50CN6GaUEC1s2wSpaAGwWLcKPJLQ/+FR RHiCtAxEjdv09ejK8wyW+a1GsCUolQKWoRPn9dwEPLVPsHnQWbO8C0V5DUqKn4oSFeId LBprvt2QCL30ZOywvjclZ40R9QrZgfOI27o8FXZoyH0Cc0HRDW2mhu1q6+ApYP50fJPz OqAqh3CZ4SK4WYYX1ko18DzhGt6TtkKh3InKl95lbZ5RDl+qwmAqNdco1ED0R5MkFY2B SYDAw1oDkhGUXak4csJPxcoUHmZ5/iZHKF6cZ+q1B0JSDpdiRH0os0afqHwXG2B9ENpW hxvw== X-Gm-Message-State: AOAM5324IJgLTvEaELDHeWSpym9EpaUeqz6jQyNTGY2CMazrkVw1RS8G HOGk4Fzn8wCX9cUv6y9e6gwK2x6Zvmn5TA== X-Google-Smtp-Source: ABdhPJxm+SFLqRZvahRbgF18ICa+ntY0wasO22GmGBJovT2/OHQLLotMWlyUFtJB+o1/D079jUDmQg== X-Received: by 2002:ae9:c013:: with SMTP id u19mr70772064qkk.59.1609764916244; Mon, 04 Jan 2021 04:55:16 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 11/20] qemu_driver.c: modernize qemuNodeDeviceReAttach() Date: Mon, 4 Jan 2021 09:54:35 -0300 Message-Id: <20210104125444.200536-12-danielhb413@gmail.com> In-Reply-To: <20210104125444.200536-1-danielhb413@gmail.com> References: <20210104125444.200536-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add virObjectUnref an autoptr cleanup func for virNodeDevice, then remove all unref and free calls from qemuNodeDeviceReAttach(). Signed-off-by: Daniel Henrique Barboza --- src/datatypes.h | 2 ++ src/qemu/qemu_driver.c | 32 ++++++++++++-------------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/datatypes.h b/src/datatypes.h index ade3779e43..7a88aba0df 100644 --- a/src/datatypes.h +++ b/src/datatypes.h @@ -707,6 +707,8 @@ struct _virNodeDevice { char *parentName; /* parent device name */ }; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNodeDevice, virObjectUnref); + /** * _virSecret: * diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index c450501c4d..7b8350dff3 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12041,17 +12041,16 @@ static int qemuNodeDeviceReAttach(virNodeDevicePtr dev) { virQEMUDriverPtr driver =3D dev->conn->privateData; - virPCIDevicePtr pci =3D NULL; + g_autoptr(virPCIDevice) pci =3D NULL; virPCIDeviceAddress devAddr; - int ret =3D -1; - virNodeDeviceDefPtr def =3D NULL; + g_autoptr(virNodeDeviceDef) def =3D NULL; g_autofree char *xml =3D NULL; virHostdevManagerPtr hostdev_mgr =3D driver->hostdevMgr; - virConnectPtr nodeconn =3D NULL; - virNodeDevicePtr nodedev =3D NULL; + g_autoptr(virConnect) nodeconn =3D NULL; + g_autoptr(virNodeDevice) nodedev =3D NULL; =20 if (!(nodeconn =3D virGetConnectNodeDev())) - goto cleanup; + return -1; =20 /* 'dev' is associated with the QEMU virConnectPtr, * so for split daemons, we need to get a copy that @@ -12059,36 +12058,29 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev) */ if (!(nodedev =3D virNodeDeviceLookupByName( nodeconn, virNodeDeviceGetName(dev)))) - goto cleanup; + return -1; =20 xml =3D virNodeDeviceGetXMLDesc(nodedev, 0); if (!xml) - goto cleanup; + return -1; =20 def =3D virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL); if (!def) - goto cleanup; + return -1; =20 /* ACL check must happen against original 'dev', * not the new 'nodedev' we acquired */ if (virNodeDeviceReAttachEnsureACL(dev->conn, def) < 0) - goto cleanup; + return -1; =20 if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) - goto cleanup; + return -1; =20 pci =3D virPCIDeviceNew(&devAddr); if (!pci) - goto cleanup; - - ret =3D virHostdevPCINodeDeviceReAttach(hostdev_mgr, pci); + return -1; =20 - virPCIDeviceFree(pci); - cleanup: - virNodeDeviceDefFree(def); - virObjectUnref(nodedev); - virObjectUnref(nodeconn); - return ret; + return virHostdevPCINodeDeviceReAttach(hostdev_mgr, pci); } =20 static int --=20 2.26.2