From nobody Mon Feb 9 12:26:31 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1642439008; cv=none; d=zohomail.com; s=zohoarc; b=NX1KzE+i5l1HzfcO//6SmZF47NzE4N7eYR+cY3pOYY85wKpGK1g6kf4buOIiF7CJ/saIIE1ZqJSrQopXzJ8UW59Hv0Ob53bk6H0qF3R2WQwtyK/+cdrMSacBAt5snCEf0JByKhSRiU8zQtiLxxM+sUf+K5gQizM0otokSHZDGp4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642439008; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BAWNWa4vIMC6+8SkxX6Ml87fYDK6gTZhUqCV+aUmfEM=; b=hBfwp4SSSQe+W1czU9uf8MQ9PwpgT77yBLxFFCKUlmvonSuCWcsbEwluc/IdUSGSfTd++bmmc2EknseMQgfj09KCx3SfEhvoIQVBzr1F2aZwaR0YXdD4FqRDBgaBfcrWzitTX4Lx0YQ7X7fFcAfOhfjw1qKgV2mPjKk8CR/ejFI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 164243900828432.63683435665905; Mon, 17 Jan 2022 09:03:28 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-550-O-eSzH6QNKOxrgVBfooXsg-1; Mon, 17 Jan 2022 12:03:25 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 89384101873A; Mon, 17 Jan 2022 17:03:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2BF055B95A; Mon, 17 Jan 2022 17:03:19 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E5D804A707; Mon, 17 Jan 2022 17:03:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 20HH2wJ2012524 for ; Mon, 17 Jan 2022 12:02:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id AB9D8694C1; Mon, 17 Jan 2022 17:02:58 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34CC05E4A6 for ; Mon, 17 Jan 2022 17:02:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642439007; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=BAWNWa4vIMC6+8SkxX6Ml87fYDK6gTZhUqCV+aUmfEM=; b=djxe7FzTf3kxiJ5inwrHR6725te/QPBsLNdJEglLSionqDPQSyVANFUq8NvemyqhrJtRPC GaHxGPtb8/sul47z/CSi41GH0VFUB27sxaX3cAZToDDv4HJxVa4rY/Th32sSsvyG4GAalj Wz230HAsza7SCsCP5XN/8ywByQfKfdw= X-MC-Unique: O-eSzH6QNKOxrgVBfooXsg-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 5/6] util: refactor virNetDevBandwidthPlug Date: Mon, 17 Jan 2022 18:02:32 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1642439009689100005 Use g_auto, split the double use of 'cmd' variable and remove useless ret variable. Signed-off-by: J=C3=A1n Tomko --- src/util/virnetdevbandwidth.c | 43 ++++++++++++++--------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/src/util/virnetdevbandwidth.c b/src/util/virnetdevbandwidth.c index cb9a22a369..7f394926ef 100644 --- a/src/util/virnetdevbandwidth.c +++ b/src/util/virnetdevbandwidth.c @@ -538,12 +538,12 @@ virNetDevBandwidthPlug(const char *brname, virNetDevBandwidth *bandwidth, unsigned int id) { - int ret =3D -1; - virCommand *cmd =3D NULL; - char *class_id =3D NULL; - char *qdisc_id =3D NULL; - char *floor =3D NULL; - char *ceil =3D NULL; + g_autoptr(virCommand) cmd1 =3D NULL; + g_autoptr(virCommand) cmd2 =3D NULL; + g_autofree char *class_id =3D NULL; + g_autofree char *qdisc_id =3D NULL; + g_autofree char *floor =3D NULL; + g_autofree char *ceil =3D NULL; char ifmacStr[VIR_MAC_STRING_BUFLEN]; =20 if (id <=3D 2) { @@ -568,37 +568,28 @@ virNetDevBandwidthPlug(const char *brname, net_bandwidth->in->peak : net_bandwidth->in->average); =20 - cmd =3D virCommandNew(TC); - virCommandAddArgList(cmd, "class", "add", "dev", brname, "parent", "1:= 1", + cmd1 =3D virCommandNew(TC); + virCommandAddArgList(cmd1, "class", "add", "dev", brname, "parent", "1= :1", "classid", class_id, "htb", "rate", floor, "ceil", ceil, NULL); - virNetDevBandwidthCmdAddOptimalQuantum(cmd, bandwidth->in); + virNetDevBandwidthCmdAddOptimalQuantum(cmd1, bandwidth->in); =20 - if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + if (virCommandRun(cmd1, NULL) < 0) + return -1; =20 - virCommandFree(cmd); - cmd =3D virCommandNew(TC); - virCommandAddArgList(cmd, "qdisc", "add", "dev", brname, "parent", + cmd2 =3D virCommandNew(TC); + virCommandAddArgList(cmd2, "qdisc", "add", "dev", brname, "parent", class_id, "handle", qdisc_id, "sfq", "perturb", "10", NULL); =20 - if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + if (virCommandRun(cmd2, NULL) < 0) + return -1; =20 if (virNetDevBandwidthManipulateFilter(brname, ifmac_ptr, id, class_id, false, true) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - - cleanup: - VIR_FREE(ceil); - VIR_FREE(floor); - VIR_FREE(qdisc_id); - VIR_FREE(class_id); - virCommandFree(cmd); - return ret; + return 0; } =20 /* --=20 2.31.1