domain_driver.c: use g_auto* in virDomainDriverNodeDeviceReset()

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Daniel Henrique Barboza 2021-01-30 13:30:37 -03:00
parent 714b22d745
commit 89450b5e73

View File

@ -375,51 +375,42 @@ int
virDomainDriverNodeDeviceReset(virNodeDevicePtr dev, virDomainDriverNodeDeviceReset(virNodeDevicePtr dev,
virHostdevManagerPtr hostdevMgr) virHostdevManagerPtr hostdevMgr)
{ {
virPCIDevicePtr pci; g_autoptr(virPCIDevice) pci = NULL;
virPCIDeviceAddress devAddr; virPCIDeviceAddress devAddr;
virNodeDeviceDefPtr def = NULL; g_autoptr(virNodeDeviceDef) def = NULL;
g_autofree char *xml = NULL; g_autofree char *xml = NULL;
virConnectPtr nodeconn = NULL; g_autoptr(virConnect) nodeconn = NULL;
virNodeDevicePtr nodedev = NULL; g_autoptr(virNodeDevice) nodedev = NULL;
int ret = -1;
if (!(nodeconn = virGetConnectNodeDev())) if (!(nodeconn = virGetConnectNodeDev()))
goto cleanup; return -1;
/* 'dev' is associated with virConnectPtr, so for split /* 'dev' is associated with virConnectPtr, so for split
* daemons, we need to get a copy that is associated with * daemons, we need to get a copy that is associated with
* the virnodedevd daemon. */ * the virnodedevd daemon. */
if (!(nodedev = virNodeDeviceLookupByName( if (!(nodedev = virNodeDeviceLookupByName(
nodeconn, virNodeDeviceGetName(dev)))) nodeconn, virNodeDeviceGetName(dev))))
goto cleanup; return -1;
xml = virNodeDeviceGetXMLDesc(nodedev, 0); xml = virNodeDeviceGetXMLDesc(nodedev, 0);
if (!xml) if (!xml)
goto cleanup; return -1;
def = virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL); def = virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL);
if (!def) if (!def)
goto cleanup; return -1;
/* ACL check must happen against original 'dev', /* ACL check must happen against original 'dev',
* not the new 'nodedev' we acquired */ * not the new 'nodedev' we acquired */
if (virNodeDeviceResetEnsureACL(dev->conn, def) < 0) if (virNodeDeviceResetEnsureACL(dev->conn, def) < 0)
goto cleanup; return -1;
if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0)
goto cleanup; return -1;
pci = virPCIDeviceNew(&devAddr); pci = virPCIDeviceNew(&devAddr);
if (!pci) if (!pci)
goto cleanup; return -1;
ret = virHostdevPCINodeDeviceReset(hostdevMgr, pci);
virPCIDeviceFree(pci);
cleanup:
virNodeDeviceDefFree(def);
virObjectUnref(nodedev);
virObjectUnref(nodeconn);
return ret;
return virHostdevPCINodeDeviceReset(hostdevMgr, pci);
} }