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

Daniel Henrique Barboza posted 20 patches 5 years ago
[PATCH RESEND 12/20] libxl_driver.c: modernize libxlNodeDeviceReAttach()
Posted by Daniel Henrique Barboza 5 years ago
Use g_auto* wherever we can and remove the 'cleanup' label.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
 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
-- 
2.26.2

Re: [PATCH RESEND 12/20] libxl_driver.c: modernize libxlNodeDeviceReAttach()
Posted by Laine Stump 4 years, 11 months ago
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@gmail.com>


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
>