From nobody Sun Feb 8 06:49:48 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1667314995; cv=none; d=zohomail.com; s=zohoarc; b=j7WGQosbDMoXFEAoQbJpuoS7E/QBfDQPvRh1ODCaCx8fX6iJlIspR54htFPexdaWBfNpEWA6TiArb7Fuw0dtYvZVlur+0hECa84HSqSqT2f3amTexNwIvP/cmwBlIj8MWvMVCWK5mw4KoekynFyHrhr9eosXjw0dFNdGkzmzojc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667314995; 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=oiMOPs3b8tjngMab5APUB1Q/DmSGgiC0MUfPTbByzuU=; b=KNACVdVNgoMxt9duABFS/yBBWPxYHcibG6tAYKggGyAw3e0Nfib8689pEh47shy6ZQ1AOS0Tw306oFnKk164VyS3/fqTshfn31NhaP9PxMI3Za54N6jXIasHYYUGbvcf4z46nvBTMnAdW3rUNDdr1kw6eH3N6srSjt4cIwmQCII= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1667314995703549.2313242915887; Tue, 1 Nov 2022 08:03:15 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-56-UVaLgegrNESiNRivMUgjQQ-1; Tue, 01 Nov 2022 11:03:03 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 44405823F74; Tue, 1 Nov 2022 15:02:45 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30326492B18; Tue, 1 Nov 2022 15:02:45 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 030C619465B3; Tue, 1 Nov 2022 15:02:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9C3E81946594 for ; Tue, 1 Nov 2022 15:02:44 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 8ED412166BB3; Tue, 1 Nov 2022 15:02:44 +0000 (UTC) Received: from speedmetal.redhat.com (ovpn-208-3.brq.redhat.com [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 364792166B2D for ; Tue, 1 Nov 2022 15:02:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667314992; 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=oiMOPs3b8tjngMab5APUB1Q/DmSGgiC0MUfPTbByzuU=; b=SKTVR5MRxyc2piQpz4rICznlY+TkcNmwikt6KRMbmtHfBTTdhWzhiwC2e9hkOANJfaFlsW X1ZEoXQ7BJu7qoe9apGCaeM36Ruzyis+BSu9LhXPwUKnnyN8cOv0fBOvh4PMv+xBFLnvKB VS4abhk5JN5LXUv6MDXxYRtJfI4hrm4= X-MC-Unique: UVaLgegrNESiNRivMUgjQQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 04/11] conf: domain: Refactor cleanup in virSysinfoSystemParseXML Date: Tue, 1 Nov 2022 16:02:18 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1667314996140100006 Content-Type: text/plain; charset="utf-8" Register automatic cleanup for virSysinfoSystemDef and use it to refactor the cleanup code paths in virSysinfoSystemParseXML. Signed-off-by: Peter Krempa --- src/conf/domain_conf.c | 24 ++++++++---------------- src/util/virsysinfo.h | 1 + 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b0a978cc62..8e9f415070 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -12184,8 +12184,7 @@ virSysinfoSystemParseXML(xmlNodePtr node, bool uuid_generated) { VIR_XPATH_NODE_AUTORESTORE(ctxt) - int ret =3D -1; - virSysinfoSystemDef *def; + g_autoptr(virSysinfoSystemDef) def =3D g_new0(virSysinfoSystemDef, 1); g_autofree char *tmpUUID =3D NULL; ctxt->node =3D node; @@ -12193,11 +12192,9 @@ virSysinfoSystemParseXML(xmlNodePtr node, if (!virXMLNodeNameEqual(node, "system")) { virReportError(VIR_ERR_XML_ERROR, "%s", _("XML does not contain expected 'system' element")= ); - return ret; + return -1; } - def =3D g_new0(virSysinfoSystemDef, 1); - def->manufacturer =3D virXPathString("string(entry[@name=3D'manufactur= er'])", ctxt); def->product =3D virXPathString("string(entry[@name=3D'product'])", ct= xt); def->version =3D virXPathString("string(entry[@name=3D'version'])", ct= xt); @@ -12209,15 +12206,14 @@ virSysinfoSystemParseXML(xmlNodePtr node, if (virUUIDParse(tmpUUID, uuidbuf) < 0) { virReportError(VIR_ERR_XML_DETAIL, "%s", _("malformed uuid element")); - goto cleanup; + return -1; } if (uuid_generated) { memcpy(domUUID, uuidbuf, VIR_UUID_BUFLEN); } else if (memcmp(domUUID, uuidbuf, VIR_UUID_BUFLEN) !=3D 0) { virReportError(VIR_ERR_XML_DETAIL, "%s", - _("UUID mismatch between and " - "")); - goto cleanup; + _("UUID mismatch between and ")= ); + return -1; } /* Although we've validated the UUID as good, virUUIDParse() is * lax with respect to allowing extraneous "-" and " ", but the @@ -12232,15 +12228,11 @@ virSysinfoSystemParseXML(xmlNodePtr node, def->family =3D virXPathString("string(entry[@name=3D'family'])", ctxt= ); if (!def->manufacturer && !def->product && !def->version && - !def->serial && !def->uuid && !def->sku && !def->family) { - g_clear_pointer(&def, virSysinfoSystemDefFree); - } + !def->serial && !def->uuid && !def->sku && !def->family) + return 0; *sysdef =3D g_steal_pointer(&def); - ret =3D 0; - cleanup: - virSysinfoSystemDefFree(def); - return ret; + return 0; } static int diff --git a/src/util/virsysinfo.h b/src/util/virsysinfo.h index 899193dc81..d9f15b06e2 100644 --- a/src/util/virsysinfo.h +++ b/src/util/virsysinfo.h @@ -144,6 +144,7 @@ virSysinfoDef *virSysinfoRead(void); void virSysinfoBIOSDefFree(virSysinfoBIOSDef *def); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virSysinfoBIOSDef, virSysinfoBIOSDefFree); void virSysinfoSystemDefFree(virSysinfoSystemDef *def); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virSysinfoSystemDef, virSysinfoSystemDefFree= ); void virSysinfoBaseBoardDefClear(virSysinfoBaseBoardDef *def); void virSysinfoChassisDefFree(virSysinfoChassisDef *def); void virSysinfoOEMStringsDefFree(virSysinfoOEMStringsDef *def); --=20 2.37.3