[libvirt] [PATCH 1/3] util: use VIR_AUTOPTR virNodeSuspendSupportsTargetPMUtils

Ján Tomko posted 3 patches 6 years, 5 months ago
[libvirt] [PATCH 1/3] util: use VIR_AUTOPTR virNodeSuspendSupportsTargetPMUtils
Posted by Ján Tomko 6 years, 5 months ago
Get rid of the ret variable as well as the cleanup label.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
---
 src/util/virnodesuspend.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/src/util/virnodesuspend.c b/src/util/virnodesuspend.c
index 3fc5b93ac7..af0ed615e1 100644
--- a/src/util/virnodesuspend.c
+++ b/src/util/virnodesuspend.c
@@ -238,9 +238,8 @@ int virNodeSuspend(unsigned int target,
 static int
 virNodeSuspendSupportsTargetPMUtils(unsigned int target, bool *supported)
 {
-    virCommandPtr cmd;
+    VIR_AUTOPTR(virCommand) cmd = NULL;
     int status;
-    int ret = -1;
 
     *supported = false;
 
@@ -259,18 +258,14 @@ virNodeSuspendSupportsTargetPMUtils(unsigned int target, bool *supported)
     }
 
     if (virCommandRun(cmd, &status) < 0)
-        goto cleanup;
+        return -1;
 
    /*
     * Check return code of command == 0 for success
     * (i.e., the PM capability is supported)
     */
     *supported = (status == 0);
-    ret = 0;
-
- cleanup:
-    virCommandFree(cmd);
-    return ret;
+    return 0;
 }
 #else /* ! WITH_PM_UTILS */
 static int
-- 
2.19.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/3] util: use VIR_AUTOPTR virNodeSuspendSupportsTargetPMUtils
Posted by Andrea Bolognani 6 years, 5 months ago
On Tue, 2019-08-13 at 17:24 +0200, Ján Tomko wrote:
> +++ b/src/util/virnodesuspend.c
> @@ -238,9 +238,8 @@ int virNodeSuspend(unsigned int target,
>     /*
>      * Check return code of command == 0 for success
>      * (i.e., the PM capability is supported)
>      */
>      *supported = (status == 0);
> -    ret = 0;
> -
> - cleanup:
> -    virCommandFree(cmd);
> -    return ret;
> +    return 0;

Please leave an empty line before 'return'.

Also this doesn't build:

  util/virnodesuspend.c: In function 'virNodeSuspendSupportsTargetPMUtils':
  util/virnodesuspend.c:257:16: error: 'ret' undeclared (first use in this function)
    257 |         return ret;
        |                ^~~

With the obvious fix (s/ret/-1/) applied and the empty line added,

  Reviewed-by: Andrea Bolognani <abologna@redhat.com>

-- 
Andrea Bolognani / Red Hat / Virtualization

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list