From nobody Sun May 5 20:53:46 2024 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=1623752862; cv=none; d=zohomail.com; s=zohoarc; b=WIrPJweIpOoTdyNQpz/7g3YtqEfFrgO/pJjaJveqg9Me7HnzZN4Z7QMhHsLofPSX0Oj3H3tfkyujga0gezH0Z8sSOAPBFIecr1Zv2L62ANtyKMwcrf0AWoekf2DQWpTTuRyKLPWFheDU1LCU5dB0zZEcS51DXZDlZW+LSr8Q0jE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623752862; 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=iwFIlfVFiOVu0Ppu+BbqixF1ccTyc+8E7l+mZ2r2hGA=; b=ES2rAkbyDzb3gIZPP8CHOj4BCScV5che+62xefhXd2X+c7Ys5kOWg0j2MZvZ8Y2RnDiXmxidnfzIekGb7Cbgp4FlcR4jOIutsqMDiId3dsLuxZoEeohFfVVEflvSWrv4NalK323VSsGt67clBKUD3x/sZOuXY0WfTxYi3E+VdBE= 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 1623752862014945.1877193487717; Tue, 15 Jun 2021 03:27:42 -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-548-es55ZNtPMUqKx5-Wk4norg-1; Tue, 15 Jun 2021 06:27:39 -0400 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 BFB92A40C3; Tue, 15 Jun 2021 10:27:34 +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 A2E8B60BD9; Tue, 15 Jun 2021 10:27:34 +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 56D0646F58; Tue, 15 Jun 2021 10:27:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15FARWiV019613 for ; Tue, 15 Jun 2021 06:27:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 740B5189BB; Tue, 15 Jun 2021 10:27:32 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id D72E118F0A for ; Tue, 15 Jun 2021 10:27:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623752860; 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=iwFIlfVFiOVu0Ppu+BbqixF1ccTyc+8E7l+mZ2r2hGA=; b=b8MraBjcjl3FyzVHPv5fEBGYusx9SQUFmX/4C8w5ZoxXl+g9Mw+3WkrKOhGlq1O4UOBZeu omaGg7/GIG0LDZIe0UKIf0AF8CPiZP9ggcC+LzbGTOS5d62TLSZrdSktZ64ARiGV8dXlE3 tOnuTixFMpZ+NcTC7bVUYNBKtk7JS1M= X-MC-Unique: es55ZNtPMUqKx5-Wk4norg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 01/13] qemuMonitorJSONParsePropsList: Refactor cleanup Date: Tue, 15 Jun 2021 12:27:14 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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) Content-Type: text/plain; charset="utf-8" Use 'g_auto' for @proplist and remove @ret. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_monitor_json.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 46aa3330a8..3e7a61c52c 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -6615,14 +6615,13 @@ qemuMonitorJSONParsePropsList(virJSONValue *cmd, char ***props) { virJSONValue *data; - char **proplist =3D NULL; + g_auto(GStrv) proplist =3D NULL; size_t n =3D 0; size_t count =3D 0; size_t i; - int ret =3D -1; if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) - goto cleanup; + return -1; data =3D virJSONValueObjectGetArray(reply, "return"); n =3D virJSONValueArraySize(data); @@ -6641,18 +6640,14 @@ qemuMonitorJSONParsePropsList(virJSONValue *cmd, if (!(tmp =3D virJSONValueObjectGetString(child, "name"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("reply data was missing 'name'")); - goto cleanup; + return -1; } proplist[count++] =3D g_strdup(tmp); } - ret =3D count; *props =3D g_steal_pointer(&proplist); - - cleanup: - g_strfreev(proplist); - return ret; + return count; } --=20 2.31.1 From nobody Sun May 5 20:53:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1623752864; cv=none; d=zohomail.com; s=zohoarc; b=RPp2S+7Luz7JuTLpc+SP0BSW4EgA8CGIwyXkqElaB+76fHvlmIsR5pUeUwL5+ip9vVsnSNu+skZRq7m4GInO9MTKNZYDip2LVF5gtZzuT+RqhFVp8NGjmgtrePbPXnhomwaGck4K4MNwzuSUEJd5/wGiagAMXu0h6v2+w5Xi11E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623752864; 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=z+pOr+NbuQk7rpKofq7514AkTySRE5w1PsLV1t8+kA0=; b=AQ4/bkhecXS3+if+rRsB7zFYeNs39zKSOCS0bcCQNTXKF3taanIehukwpA5tbGKQJbW5LbXWk7nbRayHHZdNMzppCUq+mb7YiuiTuKl39jYtj2P1iHdp2kSx/sZVVoSOsxfRmqmTjWXSd0d5lQ7n+khSvL1FYQPUcJ681k4J+T8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1623752864061503.3281335207106; Tue, 15 Jun 2021 03:27:44 -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-341-6f5t_WEyNsq2Ez91R1Smxg-1; Tue, 15 Jun 2021 06:27:41 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6232D107ACF6; Tue, 15 Jun 2021 10:27:36 +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 36A935D6DC; Tue, 15 Jun 2021 10:27:36 +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 D27E146F5B; Tue, 15 Jun 2021 10:27:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15FARX0g019623 for ; Tue, 15 Jun 2021 06:27:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7CD43189BB; Tue, 15 Jun 2021 10:27:33 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD5C060BD9 for ; Tue, 15 Jun 2021 10:27:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623752863; 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=z+pOr+NbuQk7rpKofq7514AkTySRE5w1PsLV1t8+kA0=; b=Eg4sS2pgOUe2sNkZ7e+oKr/ke3sNf/NhwSg9gEuks9g0tA2n+CaXd9wQcY+9YBxpuzv+Mm rLfavBaCC8/LXdEwgZhBAw03vnnqBhSCDRj66IIMmP8/woHE2DU7diBIHDYYz7i/POU6Oz mUU8O22D16isnglke1KzOA9VXXXUMkg= X-MC-Unique: 6f5t_WEyNsq2Ez91R1Smxg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 02/13] qemuMonitorJSONGetObjectProps: Refactor cleanup Date: Tue, 15 Jun 2021 12:27:15 +0200 Message-Id: <8093c8e536e1403b99c9b295e037d865e951022e.1623752803.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.15 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) Content-Type: text/plain; charset="utf-8" Use 'g_autoptr' for the two temporary JSON objects and remove the cleanup section. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_monitor_json.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 3e7a61c52c..64696da210 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -6709,9 +6709,8 @@ qemuMonitorJSONGetObjectProps(qemuMonitor *mon, const char *object, char ***props) { - int ret =3D -1; - virJSONValue *cmd; - virJSONValue *reply =3D NULL; + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) reply =3D NULL; *props =3D NULL; @@ -6721,18 +6720,12 @@ qemuMonitorJSONGetObjectProps(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; - if (qemuMonitorJSONHasError(reply, "DeviceNotFound")) { - ret =3D 0; - goto cleanup; - } + if (qemuMonitorJSONHasError(reply, "DeviceNotFound")) + return 0; - ret =3D qemuMonitorJSONParsePropsList(cmd, reply, NULL, props); - cleanup: - virJSONValueFree(reply); - virJSONValueFree(cmd); - return ret; + return qemuMonitorJSONParsePropsList(cmd, reply, NULL, props); } --=20 2.31.1 From nobody Sun May 5 20:53:46 2024 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=1623752866; cv=none; d=zohomail.com; s=zohoarc; b=UYoY/Rwbn3m/+8JDJDc1q8hy4RVBCKWD+Rlzikg20onH6f5UQPeSLQhX6RnfKWnIJ31g+qFmQOmNGGyFRIUb+c5Rcw6Eaw3D/bbgt0xKDY5HopL6ZxpVg2FSejnfWz1aUzbjcbkBAd0+88DKue3AMTZa7SetGtP+MOQf4n6uJ5E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623752866; 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=+R8Jywp4oGb6siH99XbHMDXSg8Vnpa90E996hfix40w=; b=ITYL1pUq+Ot2Fm5eJGCRjbDUzZebBRyjH53gYMcfHhfHOBmxM/fyEhqJ3Eq62SSaT9FDrMA0iVB+AfU4Pi3G+6fbDRwFqYM85UBA47cw9VJ9MK7+9HXFvfaF4XzVA/EyA41cxK20Y4OZtDpxQ8RnKylaPZ/XQd+3IQ+SvDcJ7Ic= 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 1623752866384500.8770467337897; Tue, 15 Jun 2021 03:27:46 -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-314-wK8saVcROjaZINjQlfKtfA-1; Tue, 15 Jun 2021 06:27:43 -0400 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 0C857A40CB; Tue, 15 Jun 2021 10:27:39 +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 E27491962D; Tue, 15 Jun 2021 10:27:38 +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 A8C6D1809CAE; Tue, 15 Jun 2021 10:27:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15FARYUW019632 for ; Tue, 15 Jun 2021 06:27:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8357E189BB; Tue, 15 Jun 2021 10:27:34 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD7DA60BD9 for ; Tue, 15 Jun 2021 10:27:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623752865; 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=+R8Jywp4oGb6siH99XbHMDXSg8Vnpa90E996hfix40w=; b=F+1Jrd9+XXVMoCu0BSxRvf8sZH3SZZT6iO8TgnP4tK9JzSqmlqcbgMiY4jmrXKTJSUua0e ist3EMpMRihaagLEbtDjy1BVtLRQh2MRMvZLpfA6efOmiTl84r51Md4VNOR7oNvnJnISv6 /h2do4OKekKM+g5CKEicSxfXIhFjflQ= X-MC-Unique: wK8saVcROjaZINjQlfKtfA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 03/13] qemuMonitorJSONGetMigrationCapabilities: Refactor cleanup Date: Tue, 15 Jun 2021 12:27:16 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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) Content-Type: text/plain; charset="utf-8" Use automatic memory clearing and remove the cleanup section. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_monitor_json.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 64696da210..f0d67f8f20 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -6768,11 +6768,10 @@ int qemuMonitorJSONGetMigrationCapabilities(qemuMonitor *mon, char ***capabilities) { - int ret =3D -1; - virJSONValue *cmd; - virJSONValue *reply =3D NULL; + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) reply =3D NULL; virJSONValue *caps; - char **list =3D NULL; + g_auto(GStrv) list =3D NULL; size_t i; size_t n; @@ -6783,15 +6782,13 @@ qemuMonitorJSONGetMigrationCapabilities(qemuMonitor= *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; - if (qemuMonitorJSONHasError(reply, "CommandNotFound")) { - ret =3D 0; - goto cleanup; - } + if (qemuMonitorJSONHasError(reply, "CommandNotFound")) + return 0; if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) - goto cleanup; + return -1; caps =3D virJSONValueObjectGetArray(reply, "return"); n =3D virJSONValueArraySize(caps); @@ -6805,26 +6802,20 @@ qemuMonitorJSONGetMigrationCapabilities(qemuMonitor= *mon, if (!cap || virJSONValueGetType(cap) !=3D VIR_JSON_TYPE_OBJECT) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing entry in migration capabilities list= ")); - goto cleanup; + return -1; } if (!(name =3D virJSONValueObjectGetString(cap, "capability"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing migration capability name")); - goto cleanup; + return -1; } list[i] =3D g_strdup(name); } - ret =3D n; *capabilities =3D g_steal_pointer(&list); - - cleanup: - g_strfreev(list); - virJSONValueFree(cmd); - virJSONValueFree(reply); - return ret; + return n; } --=20 2.31.1 From nobody Sun May 5 20:53:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1623752866; cv=none; d=zohomail.com; s=zohoarc; b=NVLyWIvj3KDoLH6ZHEeBv4LxPmxp0QpQzHKRCqBl7R2hhRBYXNqpU7cz84GzOz9o8hFp5jIdofdIoGcMkdqkToCUWUDiurEGCFUMi3xZa9ak8W3ABuA421hjKlQXc6YgOShxuIwjtcpdInN4u66DLcNdPTo17JuBohy2ZZDxAHo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623752866; 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=0E9aVY58DoFjs6L1PnnIB7RyVlKzfmvJbDpFARveKZI=; b=XesFF+8yr8C+6Y/Y/eREHQnzBuwYg/uOXztI1vkV/+X4tmGRO2AgwHajTrQSBidzfjUUG6wNHbQeg9ucVW6bS7j7zsP6C3qAvyRNub/m9rHgcewfidvjzPkcyN95K0t11s/RPwBNzfUJNeEjXdrefn+yVufKKjW4W/uCM4HlWKE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1623752866781177.993348396506; Tue, 15 Jun 2021 03:27:46 -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-95-C_YK_4RTNyi5aWbT03U_Ig-1; Tue, 15 Jun 2021 06:27:44 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D43B1801FCD; Tue, 15 Jun 2021 10:27:38 +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 B0FBF5C1C2; Tue, 15 Jun 2021 10:27:38 +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 792DA1809CAD; Tue, 15 Jun 2021 10:27:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15FARZBW019639 for ; Tue, 15 Jun 2021 06:27:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8C47B189CE; Tue, 15 Jun 2021 10:27:35 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id EEF2E189BB for ; Tue, 15 Jun 2021 10:27:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623752865; 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=0E9aVY58DoFjs6L1PnnIB7RyVlKzfmvJbDpFARveKZI=; b=GFl9L+QghSfOMqTGsWchs3X4a/tQLYXCbvQ9MwdXVyIohkDmhLOB230ZtQ3ZU8oEMuh30S DJLYkL0Fz8p5RsY0rLYDPwdNz2cno+YiCZpz0zh0v02WVdFP4JJLzVdNSRKj9zNVeg+tDy Pc4o6GBZh97brCmGwLPACPddTrB1QhI= X-MC-Unique: C_YK_4RTNyi5aWbT03U_Ig-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 04/13] qemuMonitorJSONGetCommands: Refactor cleanup Date: Tue, 15 Jun 2021 12:27:17 +0200 Message-Id: <65f5d31d5c8b79cb4a14825e3e4ecd7843636cf3.1623752803.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.16 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) Content-Type: text/plain; charset="utf-8" Use automatic memory freeing to simplify the control flow. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_monitor_json.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index f0d67f8f20..683b389670 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -6159,11 +6159,10 @@ qemuMonitorJSONGetCPUModelComparison(qemuMonitor *m= on, int qemuMonitorJSONGetCommands(qemuMonitor *mon, char ***commands) { - int ret =3D -1; - virJSONValue *cmd; - virJSONValue *reply =3D NULL; + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) reply =3D NULL; virJSONValue *data; - char **commandlist =3D NULL; + g_auto(GStrv) commandlist =3D NULL; size_t n =3D 0; size_t i; @@ -6173,10 +6172,10 @@ int qemuMonitorJSONGetCommands(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) - goto cleanup; + return -1; data =3D virJSONValueObjectGetArray(reply, "return"); n =3D virJSONValueArraySize(data); @@ -6191,21 +6190,14 @@ int qemuMonitorJSONGetCommands(qemuMonitor *mon, if (!(tmp =3D virJSONValueObjectGetString(child, "name"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("query-commands reply data was missing 'name'= ")); - goto cleanup; + return -1; } commandlist[i] =3D g_strdup(tmp); } - ret =3D n; *commands =3D g_steal_pointer(&commandlist); - - - cleanup: - g_strfreev(commandlist); - virJSONValueFree(cmd); - virJSONValueFree(reply); - return ret; + return n; } --=20 2.31.1 From nobody Sun May 5 20:53:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1623752870; cv=none; d=zohomail.com; s=zohoarc; b=arLfNu+tQpXfUbHnyM7y0kARtJjzUgdItJSgKpnoclIwH+tDh/zkj8k45fE2a4ZiGhhPLury1tE903g+yxpqKtYfAWgfYe91AsUWq18kjOoZXNNordu7b92NpmyWeZdqOPZu2cVARPIjBX4UwJDHKtiIzuTExjaBrlTQyWLcWH0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623752870; 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=sa6FVMG5CheexXIn/dw1K6SlgYKBdpU6pBHE/Q6CJL0=; b=fCio4Ibmeuw5spqfKJP0RdsGT3ix2yzGPl+gD1m5OYY4PJs3qIcsG9jDcmjcJmVwUADGxlKigQlYk6SAhAZ9JwIrR6Zl3b58g0rg/DnBTJU6qPU9Ae7BFZ03Q5tS7GnwfXsHngpX5KxJwBr3PTk/VtUqhNp2fprnjuqufgUSwq0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 16237528704422.242363672351644; Tue, 15 Jun 2021 03:27:50 -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-479-Ecx6KqJ4N46ho1l0OzJiiw-1; Tue, 15 Jun 2021 06:27:48 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DFF641084F4B; Tue, 15 Jun 2021 10:27:41 +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 B92B81000358; Tue, 15 Jun 2021 10:27:41 +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 75F841806D0C; Tue, 15 Jun 2021 10:27:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15FARafZ019654 for ; Tue, 15 Jun 2021 06:27:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 935C7189BB; Tue, 15 Jun 2021 10:27:36 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED2A3620DE for ; Tue, 15 Jun 2021 10:27:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623752869; 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=sa6FVMG5CheexXIn/dw1K6SlgYKBdpU6pBHE/Q6CJL0=; b=Ec6fUDxslO1TheBg67R9ii3CCi3I3fy580se877oTtMXR7kJaFYKUh2WjkwL7mQIYuTIoN Cx6+SmkaKfQaXfB+MuxiD31TbPVTxnN8dTs5Xf6Y6qhouFUv8caBMu62dlvJpwPP3Z76l+ 7TSNHfxb3yR1Pe7GcxUjphzT6FLuBWA= X-MC-Unique: Ecx6KqJ4N46ho1l0OzJiiw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 05/13] qemuMonitorJSONGetStringArray: Refactor cleanup Date: Tue, 15 Jun 2021 12:27:18 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.84 on 10.5.11.22 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) Content-Type: text/plain; charset="utf-8" Use automatic memory clearing to simplify the control flow. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_monitor_json.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 683b389670..c25e282d51 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -7201,12 +7201,12 @@ qemuMonitorJSONBlockExportAdd(qemuMonitor *mon, static int -qemuMonitorJSONGetStringArray(qemuMonitor *mon, const char *qmpCmd, +qemuMonitorJSONGetStringArray(qemuMonitor *mon, + const char *qmpCmd, char ***array) { - int ret =3D -1; - virJSONValue *cmd; - virJSONValue *reply =3D NULL; + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) reply =3D NULL; *array =3D NULL; @@ -7214,25 +7214,18 @@ qemuMonitorJSONGetStringArray(qemuMonitor *mon, con= st char *qmpCmd, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; - if (qemuMonitorJSONHasError(reply, "CommandNotFound")) { - ret =3D 0; - goto cleanup; - } + if (qemuMonitorJSONHasError(reply, "CommandNotFound")) + return 0; if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) - goto cleanup; + return -1; if (!(*array =3D virJSONValueObjectGetStringArray(reply, "return"))) - goto cleanup; - - ret =3D g_strv_length(*array); + return -1; - cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); - return ret; + return g_strv_length(*array); } int qemuMonitorJSONGetTPMModels(qemuMonitor *mon, --=20 2.31.1 From nobody Sun May 5 20:53:46 2024 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=1623752898; cv=none; d=zohomail.com; s=zohoarc; b=oIJ5+RGWnH8D9pGfr/ofgIz8VJGN2XTcibNs7bmh2uOs124w0IqKch6BZGhbWrIQCGGle0aOQB9G4tFBVDtCwJ/ig3CWBLD+SoVaCpVz4lOGKHRrCaon8FhmjHN8pDlt+HKQq1yRFffQcAM1t1Rs7Snzj4uhqci6Cxf9TOB65bE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623752898; 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=N2EAT4Ww5BUlN5QiBOwCtg7tWZ+7sxVF/AsGZj+8vss=; b=LVkCPObdOcGBAVjkAY6xOH7A1d1WqEEa4ncX/MfVe0CwjvDUVNU3E/hij1uyIw4m3ggRf9L1Bzg5vl/8FLT9U6P0y3Dis5NguSAMFGRJR8OobRGGdTnSnOf60IL3PqsQEIJ38CVzFElIimAFDWnNHfJF2j9xH9cxm3kQ1XEOqrE= 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 1623752898843322.04052217199705; Tue, 15 Jun 2021 03:28:18 -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-219-KhX0wQ5CMyONSdod5ayAOg-1; Tue, 15 Jun 2021 06:27:50 -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 BF4EA1084F54; Tue, 15 Jun 2021 10:27:44 +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 9C3585D9DD; Tue, 15 Jun 2021 10:27:44 +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 57DCC180100E; Tue, 15 Jun 2021 10:27:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15FARbKq019660 for ; Tue, 15 Jun 2021 06:27:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9DE77189BB; Tue, 15 Jun 2021 10:27:37 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08DDF60BD9 for ; Tue, 15 Jun 2021 10:27:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623752897; 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=N2EAT4Ww5BUlN5QiBOwCtg7tWZ+7sxVF/AsGZj+8vss=; b=ZWFtzPjZyFeukGZ9jT5e+M7HT8kW2Bd6hrtB64h959dyJvNSUW3hpU++q2vOxBwZ33sKHs a+aw4GzWP53Ho8XHvhCzfhj52/mqW+Y6yLPesd6lCpVoqsGRCMx41vhKPgHx4RErTQYXFI lzVegKekL9/13tYQN/V0yujuPVQ1ecg= X-MC-Unique: KhX0wQ5CMyONSdod5ayAOg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 06/13] qemuMonitorJSONGetObjectTypes: Refactor cleanup Date: Tue, 15 Jun 2021 12:27:19 +0200 Message-Id: <8bc10471e663f685fa0d127aabd139663e815997.1623752803.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Use automatic memory clearing to simplify the control flow. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_monitor_json.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index c25e282d51..74e06e7604 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -6293,14 +6293,14 @@ int qemuMonitorJSONGetKVMState(qemuMonitor *mon, } -int qemuMonitorJSONGetObjectTypes(qemuMonitor *mon, - char ***types) +int +qemuMonitorJSONGetObjectTypes(qemuMonitor *mon, + char ***types) { - int ret =3D -1; - virJSONValue *cmd; - virJSONValue *reply =3D NULL; + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) reply =3D NULL; virJSONValue *data; - char **typelist =3D NULL; + g_auto(GStrv) typelist =3D NULL; size_t n =3D 0; size_t i; @@ -6310,10 +6310,10 @@ int qemuMonitorJSONGetObjectTypes(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) - goto cleanup; + return -1; data =3D virJSONValueObjectGetArray(reply, "return"); n =3D virJSONValueArraySize(data); @@ -6328,20 +6328,14 @@ int qemuMonitorJSONGetObjectTypes(qemuMonitor *mon, if (!(tmp =3D virJSONValueObjectGetString(child, "name"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("qom-list-types reply data was missing 'name'= ")); - goto cleanup; + return -1; } typelist[i] =3D g_strdup(tmp); } - ret =3D n; *types =3D g_steal_pointer(&typelist); - - cleanup: - g_strfreev(typelist); - virJSONValueFree(cmd); - virJSONValueFree(reply); - return ret; + return n; } --=20 2.31.1 From nobody Sun May 5 20:53:46 2024 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=1623752872; cv=none; d=zohomail.com; s=zohoarc; b=ignuByG7J15xivX/cZbnbKrHJAblqk16DoNhGKeywXDB0Co4StAKycHje/S7V6qTReFNqi29IqvJAqbaDdt58BtRLsBEvh+K8Lh0WdwhJoeWILRRxjPI6hGZt0e0MbEDy0yC2SxjbrtU8UVexnjlhWxUrXHrO1GvhLiHm0K84zc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623752872; 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=AkysYiU5GOxTfcIUq0wofcK1WijU9Fhk8vOdSf127+o=; b=fs9WOK+uvjQtN/cEyVE1sh0y77G7Mpp111k5L+mfd/2ji1Pn3GjsPMnl2PtnfD5KfqAfIUWLWpdjayM7NEQTg4IONkfJ0vcwdZ02aEXjkH79UsBhyTJKN4aF183iDEZ0FVp2Ix6mpjqAqFkEq8TkejL6npvGnHhoMkPW4JS4zXU= 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 1623752872262187.67521780818288; Tue, 15 Jun 2021 03:27:52 -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-126-ORkNv3bYM5mv3KR3Z2tWCw-1; Tue, 15 Jun 2021 06:27:48 -0400 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 DE64B8005A2; Tue, 15 Jun 2021 10:27:43 +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 C0704189BB; Tue, 15 Jun 2021 10:27:43 +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 890D446F5F; Tue, 15 Jun 2021 10:27:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15FARcev019674 for ; Tue, 15 Jun 2021 06:27:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id A76F518A69; Tue, 15 Jun 2021 10:27:38 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B843189BB for ; Tue, 15 Jun 2021 10:27:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623752871; 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=AkysYiU5GOxTfcIUq0wofcK1WijU9Fhk8vOdSf127+o=; b=cpNIXsqLeXhzJMr2IhRa0ag9gNNdVKJBgUJ9Bwz0p2ZBRrSJxDn/Y5HHJ23NqNum+DCVm6 YTFuJ2m2oEepGXVvqoHafUNAMGdn54tzWWVaMrje4kjY+tlDJiguhYi456r72oP0yhI2gf 8R4B/1+iSvYetrde19gvmFBvp5KJGNc= X-MC-Unique: ORkNv3bYM5mv3KR3Z2tWCw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 07/13] testQemuMonitorJSONGetCommands: Refactor cleanup Date: Tue, 15 Jun 2021 12:27:20 +0200 Message-Id: <9112a7c48f47c0dfc1e04144fcd53abaa282783d.1623752803.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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) Content-Type: text/plain; charset="utf-8" Use g_auto(GStrv) for clearing the string list and thus remove the 'cleanup' section and 'ret' variable. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tests/qemumonitorjsontest.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 0dce8f6ab5..5d03f83787 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -502,10 +502,8 @@ testQemuMonitorJSONGetCommands(const void *opaque) { const testGenericData *data =3D opaque; virDomainXMLOption *xmlopt =3D data->xmlopt; - int ret =3D -1; - char **commands =3D NULL; + g_auto(GStrv) commands =3D NULL; int ncommands =3D 0; - size_t i; g_autoptr(qemuMonitorTest) test =3D NULL; if (!(test =3D qemuMonitorTestNewSchema(xmlopt, data->schema))) @@ -525,16 +523,16 @@ testQemuMonitorJSONGetCommands(const void *opaque) " } " " ]" "}") < 0) - goto cleanup; + return -1; if ((ncommands =3D qemuMonitorGetCommands(qemuMonitorTestGetMonitor(te= st), &commands)) < 0) - goto cleanup; + return -1; if (ncommands !=3D 3) { virReportError(VIR_ERR_INTERNAL_ERROR, "ncommands %d is not 3", ncommands); - goto cleanup; + return -1; } #define CHECK(i, wantname) \ @@ -543,7 +541,7 @@ testQemuMonitorJSONGetCommands(const void *opaque) virReportError(VIR_ERR_INTERNAL_ERROR, \ "name %s is not %s", \ commands[i], (wantname)); \ - goto cleanup; \ + return -1; \ } \ } while (0) @@ -552,13 +550,8 @@ testQemuMonitorJSONGetCommands(const void *opaque) CHECK(2, "quit"); #undef CHECK - ret =3D 0; - cleanup: - for (i =3D 0; i < ncommands; i++) - VIR_FREE(commands[i]); - VIR_FREE(commands); - return ret; + return 0; } --=20 2.31.1 From nobody Sun May 5 20:53:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1623752876; cv=none; d=zohomail.com; s=zohoarc; b=Iawlnwhq9VJBHgbwPL6nruOEC8QPJmlVssY27OZ6/QUxSS/8AYfG+1LY/+NAcSm9kW2ADftUEfl1uVM0zABRCn8qnsuIE9B+5PXiRXv5+NM+r6mCD56zJJlhayMa4kaMiL1+2CfuaSfijYal7H9QYez5PxgCNA50r5AeCXnWbxM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623752876; 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=ndePIj6elKz1jPX7RNgJ3gGJ/nuOIl4th5+xXQS/RE8=; b=cxqrpoG+ENTTCJXcweZ1o8C8KonDQsR437W31dSXiSHIru7OmQlwBbMDVdd1sKlVkei+CeT3L4PNiXiy2Gq0E6Swagw6EpAUGRLLsyHH+Be6aJiyO/O9p/gEOFMVtzLybUL+euTJyXfAmexEJcEl8+IqScu4sEIGDqBLjdVglk8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 162375287658735.315271899906634; Tue, 15 Jun 2021 03:27:56 -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-189-wXpvadieMMmKVMvPE24bJA-1; Tue, 15 Jun 2021 06:27:54 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A3F4580362D; Tue, 15 Jun 2021 10:27:47 +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 865F85C1D5; Tue, 15 Jun 2021 10:27:47 +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 50FC746F63; Tue, 15 Jun 2021 10:27:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15FARdVB019687 for ; Tue, 15 Jun 2021 06:27:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id AFEC6189BB; Tue, 15 Jun 2021 10:27:39 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E63819630 for ; Tue, 15 Jun 2021 10:27:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623752875; 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=ndePIj6elKz1jPX7RNgJ3gGJ/nuOIl4th5+xXQS/RE8=; b=YDXrtkBuZzk21u6sCSw5E1+FjhnTT5g7GwQlq0uiueoiOBPmCzIBiyZ26BLotYEYwZp+5K nOEzvLCSh6/2/owjw49evEoiY4UdbOwBwwFHnZDJePUcUZaAeZz5YVmFfXPDo42Pw23pvh h8/K10k5mF6XwS4x3YULab1BQVs6Zas= X-MC-Unique: wXpvadieMMmKVMvPE24bJA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 08/13] testQemuMonitorJSONGetTPMModels: Refactor cleanup Date: Tue, 15 Jun 2021 12:27:21 +0200 Message-Id: <7ab4971f4ea44767faecf430f83af6144f8ba4dd.1623752803.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.16 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) Content-Type: text/plain; charset="utf-8" Use automatic memory freeing and remove the cleanup section.t Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tests/qemumonitorjsontest.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 5d03f83787..ab589135ba 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -560,8 +560,7 @@ testQemuMonitorJSONGetTPMModels(const void *opaque) { const testGenericData *data =3D opaque; virDomainXMLOption *xmlopt =3D data->xmlopt; - int ret =3D -1; - char **tpmmodels =3D NULL; + g_auto(GStrv) tpmmodels =3D NULL; int ntpmmodels =3D 0; g_autoptr(qemuMonitorTest) test =3D NULL; @@ -574,16 +573,16 @@ testQemuMonitorJSONGetTPMModels(const void *opaque) " \"passthrough\"" " ]" "}") < 0) - goto cleanup; + return -1; if ((ntpmmodels =3D qemuMonitorGetTPMModels(qemuMonitorTestGetMonitor(= test), &tpmmodels)) < 0) - goto cleanup; + return -1; if (ntpmmodels !=3D 1) { virReportError(VIR_ERR_INTERNAL_ERROR, "ntpmmodels %d is not 1", ntpmmodels); - goto cleanup; + return -1; } #define CHECK(i, wantname) \ @@ -592,7 +591,7 @@ testQemuMonitorJSONGetTPMModels(const void *opaque) virReportError(VIR_ERR_INTERNAL_ERROR, \ "name %s is not %s", \ tpmmodels[i], (wantname)); \ - goto cleanup; \ + return -1; \ } \ } while (0) @@ -600,11 +599,7 @@ testQemuMonitorJSONGetTPMModels(const void *opaque) #undef CHECK - ret =3D 0; - - cleanup: - g_strfreev(tpmmodels); - return ret; + return 0; } --=20 2.31.1 From nobody Sun May 5 20:53:46 2024 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=1623752886; cv=none; d=zohomail.com; s=zohoarc; b=JwX5bjPd1CSnPcgRNOYHKgXfTkyDIVIoUi4f/fdbf2mqqAvTG0quWip7rB4TE1Au730TonSdI2pASKbdfmsSKIH8ocx/Q5RZY/q09w1nGuCGDc1MJj5WpPbBLUjDOQ2nLfItiknYtnC51yDW5dFo+YpeMwRtAd+fluUUTTGv+xo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623752886; 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=QWEcZGXWY0qd8w8ilnBkLS95MkbsmPkCxIBcrKWn7q4=; b=DkbZs1g1PFd/Tteuj5SWZc/G354VRKvmMmutZlRg5Dec98d1ndG5L8+xZVwPgngc2iKzORyKikBVvCAu7cVniBeJEKzf/vAIMK44Ib7jCRdkZX512guOoJKzXODTGo4kecZlpd2EFYHuMOqRWkDHHCHf9QdBZLdlJ2554RyAH2g= 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 1623752886074359.25173687537347; Tue, 15 Jun 2021 03:28:06 -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-202-cHH6XXfWPTS-Qx2h4cjBIw-1; Tue, 15 Jun 2021 06:27:47 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E5A5E1084F4A; Tue, 15 Jun 2021 10:27:41 +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 C0F935C22B; Tue, 15 Jun 2021 10:27:41 +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 7F36A1806D0D; Tue, 15 Jun 2021 10:27:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15FAReWK019699 for ; Tue, 15 Jun 2021 06:27:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id BAB0C189BB; Tue, 15 Jun 2021 10:27:40 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B21B60BD9 for ; Tue, 15 Jun 2021 10:27:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623752885; 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=QWEcZGXWY0qd8w8ilnBkLS95MkbsmPkCxIBcrKWn7q4=; b=cipZVeNCLf3HgO04+/kq+WAhzKOZoqrWX/2EcVy+uksfHG/ygpBfr8jVjT2RosX1k9DX6/ 3Sa0qhdxyGxblMRAot9OVoesEObuFU0Bf1wy7yhYx+p29JCd4G6JjuDV+VwWt8zbToRgif JQG8sHLKvz4gHakRz7xTLZHxi8/tdTg= X-MC-Unique: cHH6XXfWPTS-Qx2h4cjBIw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 09/13] qemu: capabilities: Use g_auto(GStrv) instead of virStringListFreeCount Date: Tue, 15 Jun 2021 12:27:22 +0200 Message-Id: <3a4416324f27c54e53cf253e2477b74002cb5b01.1623752803.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.16 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) Content-Type: text/plain; charset="utf-8" All the capability getters which return a string list do in fact return a NULL-terminated list so we can use g_auto(GStrv) to free it. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_capabilities.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 436fe40f65..18a682f2a6 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2564,7 +2564,7 @@ static int virQEMUCapsProbeQMPCommands(virQEMUCaps *qemuCaps, qemuMonitor *mon) { - char **commands =3D NULL; + g_auto(GStrv) commands =3D NULL; int ncommands; if ((ncommands =3D qemuMonitorGetCommands(mon, &commands)) < 0) @@ -2574,7 +2574,6 @@ virQEMUCapsProbeQMPCommands(virQEMUCaps *qemuCaps, G_N_ELEMENTS(virQEMUCapsCommands), virQEMUCapsCommands, ncommands, commands); - virStringListFreeCount(commands, ncommands); return 0; } @@ -2584,8 +2583,8 @@ static int virQEMUCapsProbeQMPObjectTypes(virQEMUCaps *qemuCaps, qemuMonitor *mon) { + g_auto(GStrv) values =3D NULL; int nvalues; - char **values; if ((nvalues =3D qemuMonitorGetObjectTypes(mon, &values)) < 0) return -1; @@ -2593,7 +2592,6 @@ virQEMUCapsProbeQMPObjectTypes(virQEMUCaps *qemuCaps, G_N_ELEMENTS(virQEMUCapsObjectTypes), virQEMUCapsObjectTypes, nvalues, values); - virStringListFreeCount(values, nvalues); return 0; } @@ -2863,8 +2861,6 @@ virQEMUCapsProbeQMPMachineProps(virQEMUCaps *qemuCaps, virDomainVirtType virtType, qemuMonitor *mon) { - char **values; - int nvalues; size_t i; if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QOM_LIST_PROPERTIES)) @@ -2874,6 +2870,8 @@ virQEMUCapsProbeQMPMachineProps(virQEMUCaps *qemuCaps, virQEMUCapsObjectTypeProps props =3D virQEMUCapsMachineProps[i]; const char *canon =3D virQEMUCapsGetCanonicalMachine(qemuCaps, vir= tType, props.type); g_autofree char *type =3D NULL; + g_auto(GStrv) values =3D NULL; + int nvalues; if (STRNEQ(canon, "none") && !virQEMUCapsIsMachineSupported(qemuCaps, virtType, canon)) { @@ -2891,8 +2889,6 @@ virQEMUCapsProbeQMPMachineProps(virQEMUCaps *qemuCaps, props.nprops, props.props, nvalues, values); - - virStringListFreeCount(values, nvalues); } return 0; @@ -3309,7 +3305,7 @@ static int virQEMUCapsProbeQMPMigrationCapabilities(virQEMUCaps *qemuCaps, qemuMonitor *mon) { - char **caps =3D NULL; + g_auto(GStrv) caps =3D NULL; int ncaps; if ((ncaps =3D qemuMonitorGetMigrationCapabilities(mon, &caps)) < 0) @@ -3319,7 +3315,6 @@ virQEMUCapsProbeQMPMigrationCapabilities(virQEMUCaps = *qemuCaps, G_N_ELEMENTS(virQEMUCapsMigration), virQEMUCapsMigration, ncaps, caps); - virStringListFreeCount(caps, ncaps); return 0; } --=20 2.31.1 From nobody Sun May 5 20:53:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1623752872; cv=none; d=zohomail.com; s=zohoarc; b=gIv3pwzcLk5tTlpYnFy5bjMtDcCgF0CRBymyLxLFk6u8LMiqTH24IPNKq/xVlQGQral388TzNfMffDTGSYz6hQcxRxwDASMMHsLD3R7wqADRYpBGRYiMogbdykjQOhQeFqryf8szEdl7cghwcXNWG6DdMtWc2UXzJZvIT32XFoY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623752872; 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=NqMb4GGEIkFvrU8zQ32RZYByf8UMDuwnTKDU/aAdEIM=; b=oEEuLeoQusQNRvrQ8q24LqO67mFdd954XCDXB338+p5E3JILmpJpGbZ17+gnPPXzCScOemyKvq+7rKdWjvr4O/1mx94R7p3f+jReRCQYsy9kbTIahsEpvLY9wr/bG7Hn+4os02+lTt56TldMEsAC4JwSFNsGHQRkgArckYrmUSU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1623752872761233.19219977616638; Tue, 15 Jun 2021 03:27:52 -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-361-43WJbTmUPKa7ammYbdyHwA-1; Tue, 15 Jun 2021 06:27:49 -0400 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 B00AC100C625; Tue, 15 Jun 2021 10:27:44 +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 9211C189BB; Tue, 15 Jun 2021 10:27:44 +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 5023946F62; Tue, 15 Jun 2021 10:27:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15FARfRQ019704 for ; Tue, 15 Jun 2021 06:27:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id C48C9189BB; Tue, 15 Jun 2021 10:27:41 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2729018F0A for ; Tue, 15 Jun 2021 10:27:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623752871; 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=NqMb4GGEIkFvrU8zQ32RZYByf8UMDuwnTKDU/aAdEIM=; b=Z2NTgIH4mqZHdBgLTADhgtYSvTlsUca9Jri2Ra0ef5aONKEGYSXIlOL5W72JWGnlM4o4bH S0ffEqk7xJ33vxzIjJVDCfkzj88thbBmsV1BwLiARDKu1VSS8HhSQ4NCq3wm+EvZJ29ded 4C+WltzqaS3zThk7vkQ1jvubkErOP0E= X-MC-Unique: 43WJbTmUPKa7ammYbdyHwA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 10/13] virQEMUCapsProcessStringFlags: Don't require 'nvalues' Date: Tue, 15 Jun 2021 12:27:23 +0200 Message-Id: <516e4fb120554d4365ad421cfb4c1fcec8155067.1623752803.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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) Content-Type: text/plain; charset="utf-8" All callers pass in NULL-terminated string lists. Remove the 'nvalues' argument and fix all callers. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_capabilities.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 18a682f2a6..576fb6429b 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -1779,16 +1779,17 @@ static void virQEMUCapsProcessStringFlags(virQEMUCaps *qemuCaps, size_t nflags, struct virQEMUCapsStringFlags *flags, - size_t nvalues, - char *const*values) + char **values) { - size_t i, j; + size_t i; + char **value; + for (i =3D 0; i < nflags; i++) { if (virQEMUCapsGet(qemuCaps, flags[i].flag)) continue; - for (j =3D 0; j < nvalues; j++) { - if (STREQ(values[j], flags[i].value)) { + for (value =3D values; *value; value++) { + if (STREQ(*value, flags[i].value)) { virQEMUCapsSet(qemuCaps, flags[i].flag); break; } @@ -2565,15 +2566,14 @@ virQEMUCapsProbeQMPCommands(virQEMUCaps *qemuCaps, qemuMonitor *mon) { g_auto(GStrv) commands =3D NULL; - int ncommands; - if ((ncommands =3D qemuMonitorGetCommands(mon, &commands)) < 0) + if (qemuMonitorGetCommands(mon, &commands) < 0) return -1; virQEMUCapsProcessStringFlags(qemuCaps, G_N_ELEMENTS(virQEMUCapsCommands), virQEMUCapsCommands, - ncommands, commands); + commands); return 0; } @@ -2584,14 +2584,13 @@ virQEMUCapsProbeQMPObjectTypes(virQEMUCaps *qemuCap= s, qemuMonitor *mon) { g_auto(GStrv) values =3D NULL; - int nvalues; - if ((nvalues =3D qemuMonitorGetObjectTypes(mon, &values)) < 0) + if (qemuMonitorGetObjectTypes(mon, &values) < 0) return -1; virQEMUCapsProcessStringFlags(qemuCaps, G_N_ELEMENTS(virQEMUCapsObjectTypes), virQEMUCapsObjectTypes, - nvalues, values); + values); return 0; } @@ -2645,19 +2644,18 @@ virQEMUCapsProbeQMPObjectProperties(virQEMUCaps *qe= muCaps, for (i =3D 0; i < G_N_ELEMENTS(virQEMUCapsObjectProps); i++) { virQEMUCapsObjectTypeProps *props =3D virQEMUCapsObjectProps + i; g_auto(GStrv) values =3D NULL; - int nvalues; if (props->capsCondition >=3D 0 && !virQEMUCapsGet(qemuCaps, props->capsCondition)) continue; - if ((nvalues =3D qemuMonitorGetObjectProps(mon, props->type, &valu= es)) < 0) + if (qemuMonitorGetObjectProps(mon, props->type, &values) < 0) return -1; virQEMUCapsProcessStringFlags(qemuCaps, props->nprops, props->props, - nvalues, values); + values); } return 0; @@ -2871,7 +2869,6 @@ virQEMUCapsProbeQMPMachineProps(virQEMUCaps *qemuCaps, const char *canon =3D virQEMUCapsGetCanonicalMachine(qemuCaps, vir= tType, props.type); g_autofree char *type =3D NULL; g_auto(GStrv) values =3D NULL; - int nvalues; if (STRNEQ(canon, "none") && !virQEMUCapsIsMachineSupported(qemuCaps, virtType, canon)) { @@ -2882,13 +2879,13 @@ virQEMUCapsProbeQMPMachineProps(virQEMUCaps *qemuCa= ps, * followed by the -machine suffix */ type =3D g_strdup_printf("%s-machine", canon); - if ((nvalues =3D qemuMonitorGetObjectProps(mon, type, &values)) < = 0) + if (qemuMonitorGetObjectProps(mon, type, &values) < 0) return -1; virQEMUCapsProcessStringFlags(qemuCaps, props.nprops, props.props, - nvalues, values); + values); } return 0; @@ -3306,15 +3303,14 @@ virQEMUCapsProbeQMPMigrationCapabilities(virQEMUCap= s *qemuCaps, qemuMonitor *mon) { g_auto(GStrv) caps =3D NULL; - int ncaps; - if ((ncaps =3D qemuMonitorGetMigrationCapabilities(mon, &caps)) < 0) + if (qemuMonitorGetMigrationCapabilities(mon, &caps) < 0) return -1; virQEMUCapsProcessStringFlags(qemuCaps, G_N_ELEMENTS(virQEMUCapsMigration), virQEMUCapsMigration, - ncaps, caps); + caps); return 0; } --=20 2.31.1 From nobody Sun May 5 20:53:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1623752876; cv=none; d=zohomail.com; s=zohoarc; b=V2cB+UvedPj41htR6FtViNp5NPyPMq0CS6cKwgpeL+S/crVj651PkbxrYTx0/wFJ5NzYu/UMEv9jF3+Qr9FTzhoxXVQpiXMeAknVqAtJVWyJPdvY08F/P354BWAKNVnlo7BHzJDS3QW8cXx3n7B3aW2lSi4jIzSus17ZB5wA/Rc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623752876; 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=5gWkXhG1NK9/IBib0o2vRH3Y3TOKk8Zzh88whAmyaFA=; b=SwzP6aesUWg/fy1YhinmikcZfvbaorXerRegV249zc4CXFWeFT/AkEwgNiSxTysojWhw/1IbZ8WTak9L4XBFfxVIpkX9vhiKXWXMqqrlBmROWnUPno4jnE2NfHumE7z2FYBtr+YkZLMPx7a89YQMXsPlNWKsfAJy/9Qp3BviDeg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 162375287643265.21500976906736; Tue, 15 Jun 2021 03:27:56 -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-467-MiMERyOEPaCxaIPzyLh_qQ-1; Tue, 15 Jun 2021 06:27:52 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 00C81107ACF6; Tue, 15 Jun 2021 10:27:47 +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 D28105C1D5; Tue, 15 Jun 2021 10:27:46 +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 9C1FA1800BBE; Tue, 15 Jun 2021 10:27:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15FARgL8019720 for ; Tue, 15 Jun 2021 06:27:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id CAD77189BB; Tue, 15 Jun 2021 10:27:42 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3AF13620DE for ; Tue, 15 Jun 2021 10:27:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623752874; 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=5gWkXhG1NK9/IBib0o2vRH3Y3TOKk8Zzh88whAmyaFA=; b=FBISeAJfC61Pfemb5RvaqZdbk34aovjlIYIaB5288+6w14GH35WHK07vdNusO58eekycpK el/14HlomOq+OjTO3nK0A01xHtNmAoDxMrJaWNWuiuqNtRcvlaJNAacbURUIr1WOVDYGF7 WYaD8kzKsmeFOq4B2D4DqkVNba5Qgcw= X-MC-Unique: MiMERyOEPaCxaIPzyLh_qQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 11/13] virQEMUCapsProbeQMPTPM: Refactor handling of string lists Date: Tue, 15 Jun 2021 12:27:24 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.16 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) Content-Type: text/plain; charset="utf-8" This refactors multiple aspects of the function: 1) Use automatic memory freeing 2) Remove need to check element count in the returned arrays 3) Fixes questionable code linebreaks 4) Removes reuse of variables Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_capabilities.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 576fb6429b..bd7a24cf38 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -3167,36 +3167,27 @@ static int virQEMUCapsProbeQMPTPM(virQEMUCaps *qemuCaps, qemuMonitor *mon) { - int nentries; + g_auto(GStrv) models =3D NULL; + g_auto(GStrv) types =3D NULL; size_t i; - char **entries =3D NULL; - if ((nentries =3D qemuMonitorGetTPMModels(mon, &entries)) < 0) + if (qemuMonitorGetTPMModels(mon, &models) < 0) return -1; - if (nentries > 0) { - for (i =3D 0; i < G_N_ELEMENTS(virQEMUCapsTPMModelsToCaps); i++) { - const char *needle =3D virDomainTPMModelTypeToString( - virQEMUCapsTPMModelsToCaps[i].type); - if (g_strv_contains((const char **)entries, needle)) - virQEMUCapsSet(qemuCaps, - virQEMUCapsTPMModelsToCaps[i].caps); - } + for (i =3D 0; i < G_N_ELEMENTS(virQEMUCapsTPMModelsToCaps); i++) { + const char *needle =3D virDomainTPMModelTypeToString(virQEMUCapsTP= MModelsToCaps[i].type); + if (g_strv_contains((const char **)models, needle)) + virQEMUCapsSet(qemuCaps, virQEMUCapsTPMModelsToCaps[i].caps); } - g_strfreev(entries); - if ((nentries =3D qemuMonitorGetTPMTypes(mon, &entries)) < 0) + if (qemuMonitorGetTPMTypes(mon, &types) < 0) return -1; - if (nentries > 0) { - for (i =3D 0; i < G_N_ELEMENTS(virQEMUCapsTPMTypesToCaps); i++) { - const char *needle =3D virDomainTPMBackendTypeToString( - virQEMUCapsTPMTypesToCaps[i].type); - if (g_strv_contains((const char **)entries, needle)) - virQEMUCapsSet(qemuCaps, virQEMUCapsTPMTypesToCaps[i].caps= ); - } + for (i =3D 0; i < G_N_ELEMENTS(virQEMUCapsTPMTypesToCaps); i++) { + const char *needle =3D virDomainTPMBackendTypeToString(virQEMUCaps= TPMTypesToCaps[i].type); + if (g_strv_contains((const char **)types, needle)) + virQEMUCapsSet(qemuCaps, virQEMUCapsTPMTypesToCaps[i].caps); } - g_strfreev(entries); return 0; } --=20 2.31.1 From nobody Sun May 5 20:53:46 2024 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=1623752954; cv=none; d=zohomail.com; s=zohoarc; b=J2/ZS2b4HksRF0eV36VRxoiVgOaIp1O3UbFJiHW0b7KhvgmHZwcKTTjvVWyXlkLIRm+GnHpGjFnHLj4GMGzHkrh99Q2CJ7f2AS5YgeXXJq3q4DcivosS2dxhDbRRwKsU7oQwX9y0lGOn11j+ZrD9cQtRFfgM3Hx3KobO0DlsVyc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623752954; 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=sgpbbHRLj0OqEvFVLgZqr3ili0QRKS0C6up0xEywuJk=; b=Nk6cER3N9UpUcwYTcYowZI2LHiwi5N2b2Ts2nWrgmFoMIZRLaT5XOV33cGO2D2WduIvs3sdO33gbO1iqSaYgewJXAiWtqD6pr++SBgJuH5fUXW0dpgDWwocmEDYOH5tZHarM4nbEBz5ATFHb0IzAk8DsuTXNRXjD/ylQva5ymxI= 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 1623752954912693.211239837341; Tue, 15 Jun 2021 03:29:14 -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-343-pxeTODAINheR5Vjy6aFMFA-1; Tue, 15 Jun 2021 06:27:55 -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 001821850608; Tue, 15 Jun 2021 10:27:50 +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 D62E75D9CA; Tue, 15 Jun 2021 10:27: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 A2E3A46F69; Tue, 15 Jun 2021 10:27:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15FARhei019734 for ; Tue, 15 Jun 2021 06:27:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id CD602189CE; Tue, 15 Jun 2021 10:27:43 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3790D620DE for ; Tue, 15 Jun 2021 10:27:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623752953; 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=sgpbbHRLj0OqEvFVLgZqr3ili0QRKS0C6up0xEywuJk=; b=W01smKRei0eg8Eev2SoQ0Set+AlZo7hOU58aMfC2nkkxdRNzkO7B4IZJo1NejzyWQ+zNqU 9ocg8rZktKM3lsMeKuN+huyhzRe6UojTrSOXVj2YHuaDJvMD4hKiA+vF82ENFuA1gsf6LR Xu1RezA7x+rZp/TkNP0rT39MB3UcqiU= X-MC-Unique: pxeTODAINheR5Vjy6aFMFA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 12/13] qemuMonitorJSONGetStringArray: Don't return element count Date: Tue, 15 Jun 2021 12:27:25 +0200 Message-Id: <235b4a52ed078c5cd80ee59badb3c9d7b597546b.1623752803.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" There's just one caller who cares (testQemuMonitorJSONGetTPMModels). Fix it and remove the counting of elements. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_monitor_json.c | 2 +- tests/qemumonitorjsontest.c | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 74e06e7604..340d8a1027 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -7219,7 +7219,7 @@ qemuMonitorJSONGetStringArray(qemuMonitor *mon, if (!(*array =3D virJSONValueObjectGetStringArray(reply, "return"))) return -1; - return g_strv_length(*array); + return 0; } int qemuMonitorJSONGetTPMModels(qemuMonitor *mon, diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index ab589135ba..e6746b806f 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -561,7 +561,6 @@ testQemuMonitorJSONGetTPMModels(const void *opaque) const testGenericData *data =3D opaque; virDomainXMLOption *xmlopt =3D data->xmlopt; g_auto(GStrv) tpmmodels =3D NULL; - int ntpmmodels =3D 0; g_autoptr(qemuMonitorTest) test =3D NULL; if (!(test =3D qemuMonitorTestNewSchema(xmlopt, data->schema))) @@ -575,13 +574,12 @@ testQemuMonitorJSONGetTPMModels(const void *opaque) "}") < 0) return -1; - if ((ntpmmodels =3D qemuMonitorGetTPMModels(qemuMonitorTestGetMonitor(= test), - &tpmmodels)) < 0) + if (qemuMonitorGetTPMModels(qemuMonitorTestGetMonitor(test), &tpmmodel= s) < 0) return -1; - if (ntpmmodels !=3D 1) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "ntpmmodels %d is not 1", ntpmmodels); + if (g_strv_length(tpmmodels) !=3D 1) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "expected 1 tpm model"); return -1; } --=20 2.31.1 From nobody Sun May 5 20:53:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1623752949; cv=none; d=zohomail.com; s=zohoarc; b=S7oKgHRwMcXgCfGuU3ITCX1GuiBFI4c7HLxILzvmWM5pEIQc2HEb4a/eiPPqQP7iwFcMuuP1eaCCTtmXedC1DvJOzAY19YTgmw1YujZ3z/isVj4xBZj3d4kugBGWiUl9aeINkScSIGDEOYB+OYd3DejBubpd37e3AgYh9+E8Tss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623752949; 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=yE/GA41zOHddGFz2E3EFpR5uHyC6/g+y+kzOUEsD0qg=; b=lTdKKJRW+Y5wCgcJpDwD1bkml7h9p2jXrG7K8S2NrxzhYpLHHmQE+P4d5YRoJG/LKkuGVamK54LM59QZB3bQHmjxIqhAXUlVmG8R12hMePpJPmyynd1IHHB92aufpsWKOQ3cGiZ+BlHoQauul1y/2Fg5SVYb/Nayd6YAxlGeme4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1623752949417731.024353753619; Tue, 15 Jun 2021 03:29:09 -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-6-qCs38cznNmCeRC-NOPuI6w-1; Tue, 15 Jun 2021 06:27:57 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9B6C6800D62; Tue, 15 Jun 2021 10:27:52 +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 7E8845C1D5; Tue, 15 Jun 2021 10:27:52 +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 4BA6246F6D; Tue, 15 Jun 2021 10:27:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15FARi0l019743 for ; Tue, 15 Jun 2021 06:27:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id DCEDB189BB; Tue, 15 Jun 2021 10:27:44 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 47BC3189CE for ; Tue, 15 Jun 2021 10:27:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623752948; 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=yE/GA41zOHddGFz2E3EFpR5uHyC6/g+y+kzOUEsD0qg=; b=UKnqnP1x9S5R9FApWA5KDDZtFRzDFq9V1Wjt1Dd1yElT4Iau7J28ZXFUwnmhozSNOWIKT5 1glyAfhHV+G4PI57QPWfvrdaQqPKLg22VWXe4IYyrFidhqRzOScIU/QuQLcFtdk9YWE1Rj xBXm+SlZj4sa11kRNrd/0bmmf6sl6Xg= X-MC-Unique: qCs38cznNmCeRC-NOPuI6w-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 13/13] qemuMonitorJSONGetStringListProperty: Don't return element count Date: Tue, 15 Jun 2021 12:27:26 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.16 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) Content-Type: text/plain; charset="utf-8" The only caller doesn't care about the number of elements in the string list so we don't have to calculate it. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_monitor_json.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 340d8a1027..223777739d 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -6524,7 +6524,7 @@ qemuMonitorJSONGetStringListProperty(qemuMonitor *mon, if (!(*strList =3D virJSONValueObjectGetStringArray(reply, "return"))) return -1; - return g_strv_length(*strList); + return 0; } --=20 2.31.1