From 793e71ee76acb49b215e31ee89e0c9cb52322811 Mon Sep 17 00:00:00 2001 From: Tim Wiederhake Date: Tue, 18 May 2021 17:04:43 +0200 Subject: [PATCH] virDomainHostdevSubsysUSBDefParseXML: Use virXMLProp* Signed-off-by: Tim Wiederhake Reviewed-by: Laine Stump --- src/conf/domain_conf.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 734fa584a4..661fa53206 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6694,28 +6694,23 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node, virDomainHostdevDef *def) { virDomainHostdevSubsysUSB *usbsrc = &def->source.subsys.u.usb; - g_autofree char *startupPolicy = NULL; - g_autofree char *autoAddress = NULL; xmlNodePtr vendorNode; xmlNodePtr productNode; xmlNodePtr addressNode; + virTristateBool autoAddress; VIR_XPATH_NODE_AUTORESTORE(ctxt) ctxt->node = node; - if ((startupPolicy = virXMLPropString(node, "startupPolicy"))) { - int value = virDomainStartupPolicyTypeFromString(startupPolicy); - if (value <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown startup policy '%s'"), - startupPolicy); - return -1; - } - def->startupPolicy = value; - } + if (virXMLPropEnum(node, "startupPolicy", + virDomainStartupPolicyTypeFromString, + VIR_XML_PROP_NONZERO, &def->startupPolicy) < 0) + return -1; - if ((autoAddress = virXMLPropString(node, "autoAddress"))) - ignore_value(virStringParseYesNo(autoAddress, &usbsrc->autoAddress)); + if (virXMLPropTristateBool(node, "autoAddress", VIR_XML_PROP_NONE, + &autoAddress) < 0) + return -1; + usbsrc->autoAddress = autoAddress == VIR_TRISTATE_BOOL_YES; /* Product can validly be 0, so we need some extra help to determine * if it is uninitialized */