[libvirt PATCH 6/6] util: refactor virNetDevBandwidthUnplug

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

 



Remove pointless 'ret', cmd variable reuse and use g_auto.

Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 src/util/virnetdevbandwidth.c | 35 ++++++++++++++---------------------
 1 file changed, 14 insertions(+), 21 deletions(-)

diff --git a/src/util/virnetdevbandwidth.c b/src/util/virnetdevbandwidth.c
index 7f394926ef..2895be8d27 100644
--- a/src/util/virnetdevbandwidth.c
+++ b/src/util/virnetdevbandwidth.c
@@ -605,11 +605,11 @@ int
 virNetDevBandwidthUnplug(const char *brname,
                          unsigned int id)
 {
-    int ret = -1;
     int cmd_ret = 0;
-    virCommand *cmd = NULL;
-    char *class_id = NULL;
-    char *qdisc_id = NULL;
+    g_autoptr(virCommand) cmd1 = NULL;
+    g_autoptr(virCommand) cmd2 = NULL;
+    g_autofree char *class_id = NULL;
+    g_autofree char *qdisc_id = NULL;
 
     if (id <= 2) {
         virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid class ID %d"), id);
@@ -619,34 +619,27 @@ virNetDevBandwidthUnplug(const char *brname,
     class_id = g_strdup_printf("1:%x", id);
     qdisc_id = g_strdup_printf("%x:", id);
 
-    cmd = virCommandNew(TC);
-    virCommandAddArgList(cmd, "qdisc", "del", "dev", brname,
+    cmd1 = virCommandNew(TC);
+    virCommandAddArgList(cmd1, "qdisc", "del", "dev", brname,
                          "handle", qdisc_id, NULL);
 
     /* Don't threat tc errors as fatal, but
      * try to remove as much as possible */
-    if (virCommandRun(cmd, &cmd_ret) < 0)
-        goto cleanup;
+    if (virCommandRun(cmd1, &cmd_ret) < 0)
+        return -1;
 
     if (virNetDevBandwidthManipulateFilter(brname, NULL, id,
                                            NULL, true, false) < 0)
-        goto cleanup;
+        return -1;
 
-    virCommandFree(cmd);
-    cmd = virCommandNew(TC);
-    virCommandAddArgList(cmd, "class", "del", "dev", brname,
+    cmd2 = virCommandNew(TC);
+    virCommandAddArgList(cmd2, "class", "del", "dev", brname,
                          "classid", class_id, NULL);
 
-    if (virCommandRun(cmd, &cmd_ret) < 0)
-        goto cleanup;
+    if (virCommandRun(cmd2, &cmd_ret) < 0)
+        return -1;
 
-    ret = 0;
-
- cleanup:
-    VIR_FREE(qdisc_id);
-    VIR_FREE(class_id);
-    virCommandFree(cmd);
-    return ret;
+    return 0;
 }
 
 /**
-- 
2.31.1




[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