This patch prevents nesting of if conditions and makes the code cleaner. Signed-off-by: Kristina Hanicova <khani...@redhat.com> --- src/conf/domain_conf.c | 50 +++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 25 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 44a01ab628..6b81c61056 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5309,18 +5309,18 @@ virDomainDeviceAddressParseXML(xmlNodePtr address, { g_autofree char *type = virXMLPropString(address, "type"); - if (type) { - if ((info->type = virDomainDeviceAddressTypeFromString(type)) <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown address type '%s'"), type); - return -1; - } - } else { + if (!type) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("No type specified for device address")); return -1; } + if ((info->type = virDomainDeviceAddressTypeFromString(type)) <= 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown address type '%s'"), type); + return -1; + } + switch ((virDomainDeviceAddressType) info->type) { case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI: if (virPCIDeviceAddressParseXML(address, &info->addr.pci) < 0) @@ -5996,20 +5996,20 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, * <hostdev>. (the functions we're going to call expect address * type to already be known). */ - if (type) { - if ((def->source.subsys.type - = virDomainHostdevSubsysTypeFromString(type)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown host device source address type '%s'"), - type); - return -1; - } - } else { + if (!type) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing source address type")); return -1; } + if ((def->source.subsys.type + = virDomainHostdevSubsysTypeFromString(type)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown host device source address type '%s'"), + type); + return -1; + } + if (!(sourcenode = virXPathNode("./source", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing <source> element in hostdev device")); @@ -6304,20 +6304,20 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node G_GNUC_UNUSED, * <hostdev>. (the functions we're going to call expect address * type to already be known). */ - if (type) { - if ((def->source.caps.type - = virDomainHostdevCapsTypeFromString(type)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown host device source address type '%s'"), - type); - return -1; - } - } else { + if (!type) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing source address type")); return -1; } + if ((def->source.caps.type + = virDomainHostdevCapsTypeFromString(type)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown host device source address type '%s'"), + type); + return -1; + } + if (!virXPathNode("./source", ctxt)) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing <source> element in hostdev device")); -- 2.35.3