From 6f8ac7bc46d0bfff08f860bcc2e81be437d90da0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Mon, 17 Jan 2022 18:02:29 +0100 Subject: [PATCH] util: virNetDevBandwidthUpdateRate: refactor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use automatic cleanup and remove the 'ret' variable in favor of direct returns. Signed-off-by: Ján Tomko Reviewed-by: Michal Privoznik --- src/util/virnetdevbandwidth.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/util/virnetdevbandwidth.c b/src/util/virnetdevbandwidth.c index 75fc5607ad..083b860059 100644 --- a/src/util/virnetdevbandwidth.c +++ b/src/util/virnetdevbandwidth.c @@ -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); } /**