util: virNetDevBandwidthUpdateRate: refactor

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>
This commit is contained in:
Ján Tomko 2022-01-17 18:02:29 +01:00
parent aa9cd08d92
commit 6f8ac7bc46

View 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);
}
/**