From: Tim Wiederhake Date: Mon, 10 May 2021 12:48:36 +0000 (+0200) Subject: virPCIEDeviceInfoLinkParseXML: Use virXMLProp* X-Git-Tag: v7.4.0-rc1~163 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bfba1758a2496579d0f8087346cdb8436c3f4662;p=thirdparty%2Flibvirt.git virPCIEDeviceInfoLinkParseXML: Use virXMLProp* Signed-off-by: Tim Wiederhake Reviewed-by: Michal Privoznik --- diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index faa36c1944..ef09ed0a6f 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -1601,38 +1601,16 @@ virPCIEDeviceInfoLinkParseXML(xmlXPathContextPtr ctxt, virPCIELink *lnk) { VIR_XPATH_NODE_AUTORESTORE(ctxt) - int speed; - g_autofree char *speedStr = NULL; - g_autofree char *portStr = NULL; - ctxt->node = linkNode; - - if (virXPathUInt("number(./@width)", ctxt, &lnk->width) < 0) { - virReportError(VIR_ERR_XML_DETAIL, "%s", - _("mandatory attribute 'width' is missing or malformed")); + if (virXMLPropUInt(linkNode, "width", 0, VIR_XML_PROP_REQUIRED, &lnk->width) < 0) return -1; - } - if ((speedStr = virXPathString("string(./@speed)", ctxt))) { - if ((speed = virPCIELinkSpeedTypeFromString(speedStr)) < 0) { - virReportError(VIR_ERR_XML_DETAIL, - _("malformed 'speed' attribute: %s"), - speedStr); - return -1; - } - lnk->speed = speed; - } + if (virXMLPropEnum(linkNode, "speed", virPCIELinkSpeedTypeFromString, + VIR_XML_PROP_NONE, &lnk->speed) < 0) + return -1; - if ((portStr = virXPathString("string(./@port)", ctxt))) { - if (virStrToLong_i(portStr, NULL, 10, &lnk->port) < 0) { - virReportError(VIR_ERR_XML_DETAIL, - _("malformed 'port' attribute: %s"), - portStr); - return -1; - } - } else { - lnk->port = -1; - } + if (virXMLPropInt(linkNode, "port", 10, VIR_XML_PROP_NONE, &lnk->port, -1) < 0) + return -1; return 0; }