From nobody Mon Feb 9 00:07:19 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=1666621007; cv=none; d=zohomail.com; s=zohoarc; b=On52RTIvZnIW6aouTVFhwTG2QMz8TsZelB+/TqPkSjXGuCUrulLwjuxYwoN1QJ8mFzpTRTFv4YhrhJ6c1wBKm06u2BNdYo6QBZL5tP5Ya9o+mTHWfvJXsp5oPOQvcj+ULP0uO3fLlrv4VLf8ijIfADjXWtcDJeHSYaw1HSewd1g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666621007; 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=2Kw/ACL7kgZvpOpgFnHd+pMk0Blj0l7nQpJotxzb4oo=; b=FRnmSNw5EXBQnQxjBfBb0rmAE9Wu3o0u6tDrNsrw4bprobJ7hjOhrLsU3dr0HJ71KGYzn1ueU15u9YTYQMlOkbfZ3TFrZ8amwnxjyCHfRPtaoUuznZA8kj1DyJSSluCT59V3QNOvQ/LqMg5Na6LJbbe4NP0COppu5G659JjUZHM= 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 1666621007088183.452722327654; Mon, 24 Oct 2022 07:16:47 -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-655-MQiRfHlrNK2TWnjQ0cZsGw-1; Mon, 24 Oct 2022 10:16:28 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E03CD1818212; Mon, 24 Oct 2022 14:15:39 +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 CE95A492CA2; Mon, 24 Oct 2022 14:15:39 +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 BDC691946594; Mon, 24 Oct 2022 14:15:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2A327194658D for ; Mon, 24 Oct 2022 14:15:38 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 102CA40C83BA; Mon, 24 Oct 2022 14:15:38 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-27.brq.redhat.com [10.40.208.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6BB1540C83AA for ; Mon, 24 Oct 2022 14:15:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666621006; 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=2Kw/ACL7kgZvpOpgFnHd+pMk0Blj0l7nQpJotxzb4oo=; b=NTzZvTUm3ZKNm9ceBpmPYb5kL5+GBwyBzdnV1VEtNYU8H4vYtJ8V7jwE2BNXM9y2qyLKGZ hj4XRY1XK6Tg/GIRCD5zywe0qNetPUB7C4lw5S/NpyRDP/Fb4s0sIQPkeJ/O3LK2/XpSbs 0xM2i+YS5Us58XgNhRq+E0PJwJQ5VkM= X-MC-Unique: MQiRfHlrNK2TWnjQ0cZsGw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 29/43] virNetDevVlanParse: Use virXMLProp* helpers instead of XPath lookups Date: Mon, 24 Oct 2022 16:14:34 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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.9 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: 1666621008599100003 Content-Type: text/plain; charset="utf-8" The loop inside virNetDevVlanParse fetches multiple attributes from the element. Convert it to use the virXMLProp* helpers, which also simplifies error reporting. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/netdev_vlan_conf.c | 39 ++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/src/conf/netdev_vlan_conf.c b/src/conf/netdev_vlan_conf.c index 9d7cc732ba..28a818ad85 100644 --- a/src/conf/netdev_vlan_conf.c +++ b/src/conf/netdev_vlan_conf.c @@ -35,7 +35,6 @@ virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ct= xt, virNetDevVlan *def) int ret =3D -1; VIR_XPATH_NODE_AUTORESTORE(ctxt) char *trunk =3D NULL; - char *nativeMode =3D NULL; xmlNodePtr *tagNodes =3D NULL; int nTags; size_t i; @@ -57,37 +56,34 @@ virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr = ctxt, virNetDevVlan *def) def->nativeMode =3D 0; def->nativeTag =3D 0; for (i =3D 0; i < nTags; i++) { - unsigned long id; + unsigned int nativeMode =3D 0; + int rc; - ctxt->node =3D tagNodes[i]; - if (virXPathULong("string(./@id)", ctxt, &id) < 0) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing or invalid vlan tag id attribute")); + if (virXMLPropUInt(tagNodes[i], "id", 10, VIR_XML_PROP_REQUIRED, + &def->tag[i]) < 0) goto cleanup; - } - if (id > 4095) { + + if (def->tag[i] > 4095) { virReportError(VIR_ERR_XML_ERROR, - _("vlan tag id %lu too large (maximum 4095)"), = id); + _("vlan tag id %u too large (maximum 4095)"), d= ef->tag[i]); goto cleanup; } - if ((nativeMode =3D virXPathString("string(./@nativeMode)", ctxt))= ) { + + if ((rc =3D virXMLPropEnum(tagNodes[i], "nativeMode", + virNativeVlanModeTypeFromString, + VIR_XML_PROP_NONZERO, &nativeMode)) < 0) + return -1; + + if (rc =3D=3D 1) { if (def->nativeMode !=3D 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("duplicate native vlan setting")); goto cleanup; } - if ((def->nativeMode - =3D virNativeVlanModeTypeFromString(nativeMode)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Invalid \"nativeMode=3D'%s'\" " - "in vlan element"), - nativeMode); - goto cleanup; - } - VIR_FREE(nativeMode); - def->nativeTag =3D id; + + def->nativeMode =3D nativeMode; + def->nativeTag =3D def->tag[i]; } - def->tag[i] =3D id; } def->nTags =3D nTags; @@ -128,7 +124,6 @@ virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr = ctxt, virNetDevVlan *def) cleanup: VIR_FREE(tagNodes); VIR_FREE(trunk); - VIR_FREE(nativeMode); if (ret < 0) virNetDevVlanClear(def); return ret; --=20 2.37.3