Add virObjectUnref an autoptr cleanup func for virNodeDevice,
then remove all unref and free calls from qemuNodeDeviceReAttach().
Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
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 */
};
+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 = dev->conn->privateData;
- virPCIDevicePtr pci = NULL;
+ g_autoptr(virPCIDevice) pci = NULL;
virPCIDeviceAddress devAddr;
- int ret = -1;
- virNodeDeviceDefPtr def = NULL;
+ g_autoptr(virNodeDeviceDef) def = NULL;
g_autofree char *xml = NULL;
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
- virConnectPtr nodeconn = NULL;
- virNodeDevicePtr nodedev = NULL;
+ g_autoptr(virConnect) nodeconn = NULL;
+ g_autoptr(virNodeDevice) nodedev = NULL;
if (!(nodeconn = virGetConnectNodeDev()))
- goto cleanup;
+ return -1;
/* '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 = virNodeDeviceLookupByName(
nodeconn, virNodeDeviceGetName(dev))))
- goto cleanup;
+ return -1;
xml = virNodeDeviceGetXMLDesc(nodedev, 0);
if (!xml)
- goto cleanup;
+ return -1;
def = virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL);
if (!def)
- goto cleanup;
+ return -1;
/* ACL check must happen against original 'dev',
* not the new 'nodedev' we acquired */
if (virNodeDeviceReAttachEnsureACL(dev->conn, def) < 0)
- goto cleanup;
+ return -1;
if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0)
- goto cleanup;
+ return -1;
pci = virPCIDeviceNew(&devAddr);
if (!pci)
- goto cleanup;
-
- ret = virHostdevPCINodeDeviceReAttach(hostdev_mgr, pci);
+ return -1;
- virPCIDeviceFree(pci);
- cleanup:
- virNodeDeviceDefFree(def);
- virObjectUnref(nodedev);
- virObjectUnref(nodeconn);
- return ret;
+ return virHostdevPCINodeDeviceReAttach(hostdev_mgr, pci);
}
static int
--
2.26.2