Reviewed-by: Ján Tomko <jtomko(a)redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
src/hypervisor/domain_driver.c | 32 ++++++++++++--------------------
1 file changed, 12 insertions(+), 20 deletions(-)
diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c
index c559f94348..ea4c3c9466 100644
--- a/src/hypervisor/domain_driver.c
+++ b/src/hypervisor/domain_driver.c
@@ -420,50 +420,42 @@ int
virDomainDriverNodeDeviceReAttach(virNodeDevicePtr dev,
virHostdevManagerPtr hostdevMgr)
{
- 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;
- 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 virConnectPtr, so for split
* daemons, we need to get a copy that is associated with
* the virnodedevd daemon. */
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(hostdevMgr, pci);
+ return -1;
- virPCIDeviceFree(pci);
- cleanup:
- virNodeDeviceDefFree(def);
- virObjectUnref(nodedev);
- virObjectUnref(nodeconn);
- return ret;
+ return virHostdevPCINodeDeviceReAttach(hostdevMgr, pci);
}
--
2.26.2