From nobody Mon Feb 9 01:06:26 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=1639052429; cv=none; d=zohomail.com; s=zohoarc; b=AB6TTQYf3AVWwdTaidIdjjW9aOx2a+n9I55gPGQpAXEWrySh/Z2PFDjDAZLsZX5/4yJGENTxtDVFGEj7dLyAZtZjdoQ41c8SOrxOQnAqmrSfT/upsoiIpTvJbofRm86AswiCWYqET58lKviJmpglAAGHW4QI2eER6SYxqOCIcFA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639052429; 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=yf+Q82zp4YGCqV5qyZVEqlAq8a9CnNfFXH/xHTbbB2Q=; b=K/taeCsEY6ylpy+hXmb9yHKcLF/8UJpu+YFj64teF+x1n+vY9b8MvdydeC9lOP/veAYUUDfeeuYBgssBPXbcnNxtihbQeQYCkfhnIrlQZ4Ln3Wo8k4TEyI6t9cBpBgxqwdUcK4jDoYrLwPiMulch37/xBWmqppQ8QTDcV06LxCk= 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 1639052429370861.0120642035017; Thu, 9 Dec 2021 04:20:29 -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-546-8V-4GagnOCi9xDi7gw8v0g-1; Thu, 09 Dec 2021 07:20:25 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6BC881966322; Thu, 9 Dec 2021 12:20:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5258445D74; Thu, 9 Dec 2021 12:20:20 +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 0F1401802FEA; Thu, 9 Dec 2021 12:20:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B9CKHrL014527 for ; Thu, 9 Dec 2021 07:20:17 -0500 Received: by smtp.corp.redhat.com (Postfix) id 28F0F17DBA; Thu, 9 Dec 2021 12:20:17 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 886655E26C for ; Thu, 9 Dec 2021 12:20:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639052428; 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=yf+Q82zp4YGCqV5qyZVEqlAq8a9CnNfFXH/xHTbbB2Q=; b=bVkP4KoqcgGn+pcHg/caCbSQCn2thYQRkjWmVQAQoDcw2+IHXjbawmYtBYyNkJZbnQlueS 966CoSIKUw8kKEsf++HpAkf2dboSId0rTvO5Xf+tzfP9wRr92+F37GfirRunPyM2eRuAxg NNZ1zNQuLOnuX6p+a1RrTRxESx8WRXs= X-MC-Unique: 8V-4GagnOCi9xDi7gw8v0g-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 16/36] virCgroupGetPercpuStats: Refactor cleanup Date: Thu, 9 Dec 2021 13:18:21 +0100 Message-Id: <1769ab3fc55822bad306d1a21c69c8a41035c208.1639052248.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.11 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1639052430631100003 Content-Type: text/plain; charset="utf-8" Use automatic memory freeing for the temporary bitmap and remove the pointless 'cleanup' section. Signed-off-by: Peter Krempa --- src/util/vircgroup.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 51da6e6a2f..bf8db47ad4 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -2347,7 +2347,6 @@ virCgroupGetPercpuStats(virCgroup *group, unsigned int ncpus, virBitmap *guestvcpus) { - int ret =3D -1; size_t i; int need_cpus, total_cpus; char *pos; @@ -2356,7 +2355,7 @@ virCgroupGetPercpuStats(virCgroup *group, virTypedParameterPtr ent; int param_idx; unsigned long long cpu_time; - virBitmap *cpumap =3D NULL; + g_autoptr(virBitmap) cpumap =3D NULL; /* return the number of supported params */ if (nparams =3D=3D 0 && ncpus !=3D 0) { @@ -2373,21 +2372,19 @@ virCgroupGetPercpuStats(virCgroup *group, total_cpus =3D virBitmapSize(cpumap); /* return total number of cpus */ - if (ncpus =3D=3D 0) { - ret =3D total_cpus; - goto cleanup; - } + if (ncpus =3D=3D 0) + return total_cpus; if (start_cpu >=3D total_cpus) { virReportError(VIR_ERR_INVALID_ARG, _("start_cpu %d larger than maximum of %d"), start_cpu, total_cpus - 1); - goto cleanup; + return -1; } /* we get percpu cputime accounting info. */ if (virCgroupGetCpuacctPercpuUsage(group, &buf)) - goto cleanup; + return -1; pos =3D buf; /* return percpu cputime in index 0 */ @@ -2402,14 +2399,14 @@ virCgroupGetPercpuStats(virCgroup *group, } else if (virStrToLong_ull(pos, &pos, 10, &cpu_time) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cpuacct parse error")); - goto cleanup; + return -1; } if (i < start_cpu) continue; ent =3D ¶ms[(i - start_cpu) * nparams + param_idx]; if (virTypedParameterAssign(ent, VIR_DOMAIN_CPU_STATS_CPUTIME, VIR_TYPED_PARAM_ULLONG, cpu_time) < 0) - goto cleanup; + return -1; } /* return percpu vcputime in index 1 */ @@ -2419,7 +2416,7 @@ virCgroupGetPercpuStats(virCgroup *group, sum_cpu_time =3D g_new0(unsigned long long, need_cpus); if (virCgroupGetPercpuVcpuSum(group, guestvcpus, sum_cpu_time, need_cpus, cpumap) < 0) - goto cleanup; + return -1; for (i =3D start_cpu; i < need_cpus; i++) { int idx =3D (i - start_cpu) * nparams + param_idx; @@ -2427,17 +2424,13 @@ virCgroupGetPercpuStats(virCgroup *group, VIR_DOMAIN_CPU_STATS_VCPUTIME, VIR_TYPED_PARAM_ULLONG, sum_cpu_time[i]) < 0) - goto cleanup; + return -1; } param_idx++; } - ret =3D param_idx; - - cleanup: - virBitmapFree(cpumap); - return ret; + return param_idx; } --=20 2.31.1