From nobody Sun Feb 8 05:40:53 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1590177421; cv=none; d=zohomail.com; s=zohoarc; b=RK11xiq7X153L3gqgqlojE3svL1oHUmFIRL6lrIMZljpI7dDunYgNL2o+7yvXqacU1ASOy0X5VrP6t7tAhzwftBCGBguhGdvWxj3oQf03V8KoqCt4z0m2qR0UaeHGqgy6h2HU1KkbXV3TP0vmeRroIqt9BCK5PtkDV8GLzf4RR0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590177421; h=Content-Type:Content-Transfer-Encoding:Cc: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=G10YNPIOx6BvlrPjpgISET0XS9iGQsERzRxsh7w0uco=; b=D5BSOI8+M9P+pwBzh4e6DDT0WMiVTPtb28Dn/Xbut8Epz4lHQPuqF1sru/AiH0mU2uqzN4CKdVlxgYm31cC7CSGGSJyVVDhehRPHUUt5+9iHMk1rUDNpzAMC73waDMlyA62/AM5g3BOuCnHUfR0C7GLvSaQ1k+T4DfjNij2txaU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1590177421132513.4920336530913; Fri, 22 May 2020 12:57:01 -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-317-3ZawtKytP9eOAta2-iJyZQ-1; Fri, 22 May 2020 15:56:55 -0400 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 0143F1005512; Fri, 22 May 2020 19:56:50 +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 3DF44707BA; Fri, 22 May 2020 19:56:49 +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 D9E311809542; Fri, 22 May 2020 19:56:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04MJujP9030396 for ; Fri, 22 May 2020 15:56:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id C9CDBF5679; Fri, 22 May 2020 19:56:45 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B96E6F567E for ; Fri, 22 May 2020 19:56:45 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8CC6C800294 for ; Fri, 22 May 2020 19:56:45 +0000 (UTC) Received: from mail-qv1-f68.google.com (mail-qv1-f68.google.com [209.85.219.68]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-417-cWHdqxdcMGy4vXThJp2GAw-1; Fri, 22 May 2020 15:56:42 -0400 Received: by mail-qv1-f68.google.com with SMTP id d1so5300374qvl.6 for ; Fri, 22 May 2020 12:56:42 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c6:e0b9:8f39:f7d8:19fe:be67]) by smtp.gmail.com with ESMTPSA id o23sm9247286qtf.53.2020.05.22.12.56.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 12:56:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590177419; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=G10YNPIOx6BvlrPjpgISET0XS9iGQsERzRxsh7w0uco=; b=Y8aUrHwm4A6D571FsP45H8MnI8u/tkSOyl4uhvx+y/UfUKs0Zp48fl/PcGqmMLTB4hrY+u E4nn1yNr1N4ZTjiTPumQEaDTqZvZEqdSwrtdUZ9qxUNSdRffHAWm5R9A64RBZRALPqa927 k33NdhwFXN2pEgm5iFj9edqg1LQQ/Qc= X-MC-Unique: 3ZawtKytP9eOAta2-iJyZQ-1 X-MC-Unique: cWHdqxdcMGy4vXThJp2GAw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=G10YNPIOx6BvlrPjpgISET0XS9iGQsERzRxsh7w0uco=; b=WmRNMTXbNjRtDcJVgTFJpUUvnURfGzWTzyW5Eq7G7PkwxnVVVvoSHcw04oiZuh01yL Koe9YFyQwJcvg8fxEW6zm7Sy3thdCeT9q3P4D8LF/3utlhqvFw8x1qNxLPz381dfYN16 kqBPH7sJuWL+1uITvRBbRtC550z6P7Etw3JOVWZQbqcMSzudkxD5CCXFLJEINe3lPkZk 94sz3kHrB9uoA3NNFGJtQa36Zm3p9jMob2h5PuYKobqpwfDwNOIP4AAkPiAyQP7i6fZD SIXZpFhS2WsH2HKgRu306x2Sm8yIBAQbEaHyUMnyMazy4bVg3NWwok4XMBQWe/ZFKKTX 5UBg== X-Gm-Message-State: AOAM530bIVICiUD7lLj/8VLE9EWZFzGsfR/aLQlxWlcka9UrIcgfnOJI BggRuzUer3MxYd3rEbnnNxovyrOR X-Google-Smtp-Source: ABdhPJzP+kk8LsVR3/sUYhve5LV94WMuuAHH2pZY3/ek6viU0FeidzwCesttVy6utQLft6/d56Uvwg== X-Received: by 2002:ad4:48c5:: with SMTP id v5mr5515852qvx.203.1590177402045; Fri, 22 May 2020 12:56:42 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 4/5] qemu_process.c: modernize qemuProcessUpdateCPU code path Date: Fri, 22 May 2020 16:56:19 -0300 Message-Id: <20200522195620.3843442-5-danielhb413@gmail.com> In-Reply-To: <20200522195620.3843442-1-danielhb413@gmail.com> References: <20200522195620.3843442-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Use automatic cleanup on qemuProcessUpdateCPU and the functions called by it. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Jiri Denemark --- src/qemu/qemu_process.c | 50 ++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 45af8f810c..a1ef1d42b0 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4187,8 +4187,8 @@ qemuProcessFetchGuestCPU(virQEMUDriverPtr driver, virCPUDataPtr *disabled) { qemuDomainObjPrivatePtr priv =3D vm->privateData; - virCPUDataPtr dataEnabled =3D NULL; - virCPUDataPtr dataDisabled =3D NULL; + g_autoptr(virCPUData) dataEnabled =3D NULL; + g_autoptr(virCPUData) dataDisabled =3D NULL; bool generic; int rc; =20 @@ -4201,7 +4201,7 @@ qemuProcessFetchGuestCPU(virQEMUDriverPtr driver, return 0; =20 if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) - goto error; + return -1; =20 if (generic) { rc =3D qemuMonitorGetGuestCPU(priv->mon, @@ -4213,19 +4213,14 @@ qemuProcessFetchGuestCPU(virQEMUDriverPtr driver, } =20 if (qemuDomainObjExitMonitor(driver, vm) < 0) - goto error; + return -1; =20 if (rc =3D=3D -1) - goto error; + return -1; =20 - *enabled =3D dataEnabled; - *disabled =3D dataDisabled; + *enabled =3D g_steal_pointer(&dataEnabled); + *disabled =3D g_steal_pointer(&dataDisabled); return 0; - - error: - virCPUDataFree(dataEnabled); - virCPUDataFree(dataDisabled); - return -1; } =20 =20 @@ -4261,9 +4256,8 @@ qemuProcessUpdateLiveGuestCPU(virDomainObjPtr vm, { virDomainDefPtr def =3D vm->def; qemuDomainObjPrivatePtr priv =3D vm->privateData; - virCPUDefPtr orig =3D NULL; + g_autoptr(virCPUDef) orig =3D NULL; int rc; - int ret =3D -1; =20 if (!enabled) return 0; @@ -4274,10 +4268,10 @@ qemuProcessUpdateLiveGuestCPU(virDomainObjPtr vm, return 0; =20 if (!(orig =3D virCPUDefCopy(def->cpu))) - goto cleanup; + return -1; =20 if ((rc =3D virCPUUpdateLive(def->os.arch, def->cpu, enabled, disabled= )) < 0) { - goto cleanup; + return -1; } else if (rc =3D=3D 0) { /* Store the original CPU in priv if QEMU changed it and we didn't * get the original CPU via migration, restore, or snapshot revert. @@ -4288,11 +4282,7 @@ qemuProcessUpdateLiveGuestCPU(virDomainObjPtr vm, def->cpu->check =3D VIR_CPU_CHECK_FULL; } =20 - ret =3D 0; - - cleanup: - virCPUDefFree(orig); - return ret; + return 0; } =20 =20 @@ -4351,10 +4341,9 @@ qemuProcessUpdateCPU(virQEMUDriverPtr driver, virDomainObjPtr vm, qemuDomainAsyncJob asyncJob) { - virCPUDataPtr cpu =3D NULL; - virCPUDataPtr disabled =3D NULL; + g_autoptr(virCPUData) cpu =3D NULL; + g_autoptr(virCPUData) disabled =3D NULL; g_autoptr(virDomainCapsCPUModels) models =3D NULL; - int ret =3D -1; =20 /* The host CPU model comes from host caps rather than QEMU caps so * fallback must be allowed no matter what the user specified in the X= ML. @@ -4362,21 +4351,16 @@ qemuProcessUpdateCPU(virQEMUDriverPtr driver, vm->def->cpu->fallback =3D VIR_CPU_FALLBACK_ALLOW; =20 if (qemuProcessFetchGuestCPU(driver, vm, asyncJob, &cpu, &disabled) < = 0) - goto cleanup; + return -1; =20 if (qemuProcessUpdateLiveGuestCPU(vm, cpu, disabled) < 0) - goto cleanup; + return -1; =20 if (qemuProcessFetchCPUDefinitions(driver, vm, asyncJob, &models) < 0 = || virCPUTranslate(vm->def->os.arch, vm->def->cpu, models) < 0) - goto cleanup; - - ret =3D 0; + return -1; =20 - cleanup: - virCPUDataFree(cpu); - virCPUDataFree(disabled); - return ret; + return 0; } =20 =20 --=20 2.26.2