From nobody Sun Feb 8 22:35:21 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1601894293; cv=none; d=zohomail.com; s=zohoarc; b=Y2vJqHh38YVb5SvsHx1X+qWTGimEirIs26S6B/+RaINm4JiclDpxDyLgIztlXmA40bvuLi/OjLQH3JsoTSaAlW4ELj5mf4QUV0APpWFv7UKCz7C4AqgwxauLb04nCb/qYImkGj9GFHP72hKFMLKAMXqa2Hr2FrZOkxrfUP3J7o0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601894293; 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=hXTUlh1knrfxpt1GnRR16KC3ZuG/QxJxrduX9nsVygo=; b=BKcT0oOP7UmU5cZos5loWYqjqqTLySPb+C2/OrIPhbUvW0fcUpA1imDXDsS2wjSCrWtYZbgrwR/2wXL9npspsH/89dlsA4HlJcUhNFecwSJ/FVHITtqULhlOeybyh2n53Mxg8oplGONVDkj9AI5DWG/9n9X5KsKmWQF/1OI0Hno= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1601894293328803.5817783814191; Mon, 5 Oct 2020 03:38:13 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-162-VfMh3RqBNe-2ZVBY_Gqz2Q-1; Mon, 05 Oct 2020 06:38:10 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CC7221868412; Mon, 5 Oct 2020 10:38:03 +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 AC9245D9E4; Mon, 5 Oct 2020 10:38:03 +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 7AFC2181A88C; Mon, 5 Oct 2020 10:38:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 095Aan7a018908 for ; Mon, 5 Oct 2020 06:36:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id C91955C22B; Mon, 5 Oct 2020 10:36:49 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 51CFB5C1BD for ; Mon, 5 Oct 2020 10:36:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601894292; 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=hXTUlh1knrfxpt1GnRR16KC3ZuG/QxJxrduX9nsVygo=; b=CACfyKzfyD27RExoc5qlPK/LZrIPto6d8b5qCMY5MV6gR/AzbYWM/ko+1SXaFRSbHMCK7z tk+Lr4pSoGJG1RafUnIfMZQY5qH7CmErXMtM5mnosmezDPv1KcqD/9Vda/4fa6PH8g05Yc EcJVx8RK/j8hXH92vmrQ+p5WYp3bPZg= X-MC-Unique: VfMh3RqBNe-2ZVBY_Gqz2Q-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 4/9] qemu: driver: use g_new0 Date: Mon, 5 Oct 2020 12:36:34 +0200 Message-Id: <4c0cbd0a862205b052b36c149b0d8391b081406b.1601894130.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.14 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) Signed-off-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 62 ++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 41 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 85b6a6a321..e622da56bd 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -625,8 +625,7 @@ qemuStateInitialize(bool privileged, const char *defsecmodel =3D NULL; g_autofree virSecurityManagerPtr *sec_managers =3D NULL; =20 - if (VIR_ALLOC(qemu_driver) < 0) - return VIR_DRV_STATE_INIT_ERROR; + qemu_driver =3D g_new0(virQEMUDriver, 1); =20 qemu_driver->lockFD =3D -1; =20 @@ -1059,8 +1058,7 @@ qemuStateStop(void) VIR_CONNECT_LIST_DOMAINS_AC= TIVE)) < 0) goto cleanup; =20 - if (VIR_ALLOC_N(flags, numDomains) < 0) - goto cleanup; + flags =3D g_new0(unsigned int, numDomains); =20 /* First we pause all VMs to make them stop dirtying pages, etc. We remember if any VMs were paused so @@ -5043,14 +5041,12 @@ qemuDomainGetIOThreadsLive(virQEMUDriverPtr driver, goto endjob; } =20 - if (VIR_ALLOC_N(info_ret, niothreads) < 0) - goto endjob; + info_ret =3D g_new0(virDomainIOThreadInfoPtr, niothreads); =20 for (i =3D 0; i < niothreads; i++) { virBitmapPtr map =3D NULL; =20 - if (VIR_ALLOC(info_ret[i]) < 0) - goto endjob; + info_ret[i] =3D g_new0(virDomainIOThreadInfo, 1); info_ret[i]->iothread_id =3D iothreads[i]->iothread_id; =20 if (!(map =3D virProcessGetAffinity(iothreads[i]->thread_id))) @@ -5098,12 +5094,10 @@ qemuDomainGetIOThreadsConfig(virDomainDefPtr target= Def, if (targetDef->niothreadids =3D=3D 0) return 0; =20 - if (VIR_ALLOC_N(info_ret, targetDef->niothreadids) < 0) - goto cleanup; + info_ret =3D g_new0(virDomainIOThreadInfoPtr, targetDef->niothreadids); =20 for (i =3D 0; i < targetDef->niothreadids; i++) { - if (VIR_ALLOC(info_ret[i]) < 0) - goto cleanup; + info_ret[i] =3D g_new0(virDomainIOThreadInfo, 1); =20 /* IOThread ID's are taken from the iothreadids list */ info_ret[i]->iothread_id =3D targetDef->iothreadids[i]->iothread_i= d; @@ -5945,10 +5939,7 @@ static int qemuDomainGetSecurityLabelList(virDomainP= tr dom, for (i =3D 0; mgrs[i]; i++) len++; =20 - if (VIR_ALLOC_N((*seclabels), len) < 0) { - VIR_FREE(mgrs); - goto cleanup; - } + (*seclabels) =3D g_new0(virSecurityLabel, len); memset(*seclabels, 0, sizeof(**seclabels) * len); =20 /* Fill the array */ @@ -9979,8 +9970,7 @@ qemuDomainBlocksStatsGather(virQEMUDriverPtr driver, if (qemuDomainObjExitMonitor(driver, vm) < 0 || nstats < 0 || rc < 0) goto cleanup; =20 - if (VIR_ALLOC(*retstats) < 0) - goto cleanup; + *retstats =3D g_new0(qemuBlockStats, 1); =20 if (entryname) { if (!(stats =3D virHashLookup(blockstats, entryname))) { @@ -10284,10 +10274,9 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, goto endjob; } =20 - if ((VIR_ALLOC(bandwidth) < 0) || - (VIR_ALLOC(bandwidth->in) < 0) || - (VIR_ALLOC(bandwidth->out) < 0)) - goto endjob; + bandwidth =3D g_new0(virNetDevBandwidth, 1); + bandwidth->in =3D g_new0(virNetDevBandwidthRate, 1); + bandwidth->out =3D g_new0(virNetDevBandwidthRate, 1); =20 for (i =3D 0; i < nparams; i++) { virTypedParameterPtr param =3D ¶ms[i]; @@ -10321,16 +10310,14 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, VIR_FREE(bandwidth->out); =20 if (net) { - if (VIR_ALLOC(newBandwidth) < 0) - goto endjob; + newBandwidth =3D g_new0(virNetDevBandwidth, 1); =20 /* virNetDevBandwidthSet() will clear any previous value of * bandwidth parameters, so merge with old bandwidth parameters * here to prevent them from being lost. */ if (bandwidth->in || (!inboundSpecified && net->bandwidth && net->bandwidth->in)) { - if (VIR_ALLOC(newBandwidth->in) < 0) - goto endjob; + newBandwidth->in =3D g_new0(virNetDevBandwidthRate, 1); =20 memcpy(newBandwidth->in, bandwidth->in ? bandwidth->in : net->bandwidth->in, @@ -10338,8 +10325,7 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, } if (bandwidth->out || (!outboundSpecified && net->bandwidth && net->bandwidth->out))= { - if (VIR_ALLOC(newBandwidth->out) < 0) - goto endjob; + newBandwidth->out =3D g_new0(virNetDevBandwidthRate, 1); =20 memcpy(newBandwidth->out, bandwidth->out ? bandwidth->out : net->bandwidth->out, @@ -12463,8 +12449,7 @@ qemuConnectCPUModelBaseline(virQEMUCapsPtr qemuCaps, if (qemuProcessQMPStart(proc) < 0) return NULL; =20 - if (VIR_ALLOC(baseline) < 0) - return NULL; + baseline =3D g_new0(virCPUDef, 1); =20 if (virCPUDefCopyModel(baseline, cpus[0], false)) return NULL; @@ -17721,8 +17706,7 @@ qemuDomainGetResctrlMonData(virQEMUDriverPtr driver, if (domresmon->tag !=3D tag) continue; =20 - if (VIR_ALLOC(res) < 0) - return -1; + res =3D g_new0(virQEMUResctrlMonData, 1); =20 /* If virBitmapFormat successfully returns an vcpu string, then * res.vcpus is assigned with an memory space holding it, @@ -18036,9 +18020,8 @@ qemuDomainGetStatsVcpu(virQEMUDriverPtr driver, "vcpu.maximum") < 0) return -1; =20 - if (VIR_ALLOC_N(cpuinfo, virDomainDefGetVcpus(dom->def)) < 0 || - VIR_ALLOC_N(cpuwait, virDomainDefGetVcpus(dom->def)) < 0) - goto cleanup; + cpuinfo =3D g_new0(virVcpuInfo, virDomainDefGetVcpus(dom->def)); + cpuwait =3D g_new0(unsigned long long, virDomainDefGetVcpus(dom->def)); =20 if (HAVE_JOB(privflags) && virDomainObjIsActive(dom) && qemuDomainRefreshVcpuHalted(driver, dom, QEMU_ASYNC_JOB_NONE) < 0)= { @@ -18690,8 +18673,7 @@ qemuDomainGetStats(virConnectPtr conn, g_autoptr(virTypedParamList) params =3D NULL; size_t i; =20 - if (VIR_ALLOC(params) < 0) - return -1; + params =3D g_new0(virTypedParamList, 1); =20 for (i =3D 0; qemuDomainGetStatsWorkers[i].func; i++) { if (stats & qemuDomainGetStatsWorkers[i].stats) { @@ -18701,8 +18683,7 @@ qemuDomainGetStats(virConnectPtr conn, } } =20 - if (VIR_ALLOC(tmp) < 0) - return -1; + tmp =3D g_new0(virDomainStatsRecord, 1); =20 if (!(tmp->dom =3D virGetDomain(conn, dom->def->name, dom->def->uuid, dom->def->id))) @@ -18763,8 +18744,7 @@ qemuConnectGetAllDomainStats(virConnectPtr conn, return -1; } =20 - if (VIR_ALLOC_N(tmpstats, nvms + 1) < 0) - goto cleanup; + tmpstats =3D g_new0(virDomainStatsRecordPtr, nvms + 1); =20 if (qemuDomainGetStatsNeedMonitor(stats)) privflags |=3D QEMU_DOMAIN_STATS_HAVE_JOB; --=20 2.26.2