From 355582e3dfcb8fa97784f46a2d7ff1cb2f3efad5 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 13 Feb 2023 15:08:53 +0100 Subject: [PATCH] virNetDevBandwidthParse: Use virXMLNodeGetSubelement instead of looped parser MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extract the 'inbound'/'outbound' subelements using virXMLNodeGetSubelement to simplify the code. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/conf/netdev_bandwidth_conf.c | 34 ++++---------------------------- 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/src/conf/netdev_bandwidth_conf.c b/src/conf/netdev_bandwidth_conf.c index f34d7499ae..38b7cc10fd 100644 --- a/src/conf/netdev_bandwidth_conf.c +++ b/src/conf/netdev_bandwidth_conf.c @@ -91,8 +91,8 @@ virNetDevBandwidthParse(virNetDevBandwidth **bandwidth, bool allowFloor) { g_autoptr(virNetDevBandwidth) def = NULL; - xmlNodePtr cur; - xmlNodePtr in = NULL, out = NULL; + xmlNodePtr in; + xmlNodePtr out; unsigned int class_id_value; int rc; @@ -113,40 +113,14 @@ virNetDevBandwidthParse(virNetDevBandwidth **bandwidth, *class_id = class_id_value; } - cur = node->children; - - while (cur) { - if (cur->type == XML_ELEMENT_NODE) { - if (virXMLNodeNameEqual(cur, "inbound")) { - if (in) { - virReportError(VIR_ERR_XML_DETAIL, "%s", - _("Only one child " - "element allowed")); - return -1; - } - in = cur; - } else if (virXMLNodeNameEqual(cur, "outbound")) { - if (out) { - virReportError(VIR_ERR_XML_DETAIL, "%s", - _("Only one child " - "element allowed")); - return -1; - } - out = cur; - } - /* Silently ignore unknown elements */ - } - cur = cur->next; - } - - if (in) { + if ((in = virXMLNodeGetSubelement(node, "inbound"))) { def->in = g_new0(virNetDevBandwidthRate, 1); if (virNetDevBandwidthParseRate(in, def->in, allowFloor) < 0) return -1; } - if (out) { + if ((out = virXMLNodeGetSubelement(node, "outbound"))) { def->out = g_new0(virNetDevBandwidthRate, 1); /* floor is not allowed for */