[PATCH] domain_conf: rewrite if else condition
Michal Prívozník
mprivozn at redhat.com
Wed Jul 20 12:55:51 UTC 2022
On 7/20/22 14:42, Kristina Hanicova wrote:
> This patch prevents nesting of if conditions and makes the code
> cleaner.
>
> Signed-off-by: Kristina Hanicova <khanicov at 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) {
Here, and ....
> + 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) {
.. here I'd rather have a slightly longer line than this. I'll fix that
before pushing.
Reviewed-by: Michal Privoznik <mprivozn at redhat.com>
Michal
More information about the libvir-list
mailing list