]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: virNetDevBandwidthUpdateRate: refactor
authorJán Tomko <jtomko@redhat.com>
Mon, 17 Jan 2022 17:02:29 +0000 (18:02 +0100)
committerJán Tomko <jtomko@redhat.com>
Fri, 28 Jan 2022 19:38:44 +0000 (20:38 +0100)
Use automatic cleanup and remove the 'ret' variable in favor of
direct returns.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/util/virnetdevbandwidth.c

index 75fc5607adededc09d5c8ee58d5d58df947e433e..083b8600594a896ec77085b2af14c18af75274f3 100644 (file)
@@ -685,11 +685,10 @@ virNetDevBandwidthUpdateRate(const char *ifname,
                              virNetDevBandwidth *bandwidth,
                              unsigned long long new_rate)
 {
-    int ret = -1;
-    virCommand *cmd = NULL;
-    char *class_id = NULL;
-    char *rate = NULL;
-    char *ceil = NULL;
+    g_autoptr(virCommand) cmd = NULL;
+    g_autofree char *class_id = NULL;
+    g_autofree char *rate = NULL;
+    g_autofree char *ceil = NULL;
 
     class_id = g_strdup_printf("1:%x", id);
     rate = g_strdup_printf("%llukbps", new_rate);
@@ -703,17 +702,7 @@ virNetDevBandwidthUpdateRate(const char *ifname,
                          "ceil", ceil, NULL);
     virNetDevBandwidthCmdAddOptimalQuantum(cmd, bandwidth->in);
 
-    if (virCommandRun(cmd, NULL) < 0)
-        goto cleanup;
-
-    ret = 0;
-
- cleanup:
-    virCommandFree(cmd);
-    VIR_FREE(class_id);
-    VIR_FREE(rate);
-    VIR_FREE(ceil);
-    return ret;
+    return virCommandRun(cmd, NULL);
 }
 
 /**