Re: [PATCH RESEND 12/20] libxl_driver.c: modernize libxlNodeDeviceReAttach()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 1/18/21 2:53 PM, Daniel Henrique Barboza wrote:
Use g_auto* wherever we can and remove the 'cleanup' label.

Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>


This patch is also obsoleted by 23cdab6a3de0f6336505adcb446f77a6e0628e6b


---
  src/libxl/libxl_driver.c | 37 ++++++++++++++-----------------------
  1 file changed, 14 insertions(+), 23 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 3eaf106006..fbb67e9ed6 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -5852,18 +5852,17 @@ libxlNodeDeviceDettach(virNodeDevicePtr dev)
  static int
  libxlNodeDeviceReAttach(virNodeDevicePtr dev)
  {
-    virPCIDevicePtr pci = NULL;
+    g_autoptr(virPCIDevice) pci = NULL;
      virPCIDeviceAddress devAddr;
-    int ret = -1;
-    virNodeDeviceDefPtr def = NULL;
-    char *xml = NULL;
+    g_autoptr(virNodeDeviceDef) def = NULL;
+    g_autofree char *xml = NULL;
      libxlDriverPrivatePtr driver = dev->conn->privateData;
      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
@@ -5871,40 +5870,32 @@ libxlNodeDeviceReAttach(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;
+        return -1;
if (virHostdevPCINodeDeviceReAttach(hostdev_mgr, pci) < 0)
-        goto cleanup;
-
-    ret = 0;
+        return -1;
- cleanup:
-    virPCIDeviceFree(pci);
-    virNodeDeviceDefFree(def);
-    virObjectUnref(nodedev);
-    virObjectUnref(nodeconn);
-    VIR_FREE(xml);
-    return ret;
+    return 0;
  }
static int





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux