From nobody Sat May 4 15:44:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1658321141; cv=none; d=zohomail.com; s=zohoarc; b=FpfmZPdLPK33sG4KuV0iVZUWSDN9NrwEpNtYFLhgxs3NSuPXVn6+ZrsRYB3W5DMu1+mZfewSntGuvpy+JOSnwqlLFAtCiY8YcQ5XiIy+s1+cEm97CzElayETRH3qL9C3t5eFq92MSqWKTu0fJ/NCPcBuU1HrihZmDumdmAJls+I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658321141; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=FzFxr/lE/W974zUSm+0NDShGW76QXjHBS76Y3UXRRio=; b=B7FjPJLX2MJWALT3OEiaekMhsZSqp6aD9rFLGVTn6t6LgMNfg0p3yJ7nXSwgYeHlb2S3PZ2gLmQL+D7QTZl40Ge5Q16LGo56JUKX2llnz+lRQSeVIqATHY0Ytl5Y39YJ5E7oDOCWogx/kLi5Ao3uTLwJYcOpPjotE2X6x60XwBc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1658321141130389.8964758115303; Wed, 20 Jul 2022 05:45:41 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-655-CKGegqtRNXiTtJdWY89fAQ-1; Wed, 20 Jul 2022 08:45:35 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4013C811E75; Wed, 20 Jul 2022 12:45:33 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id DCC9840D2962; Wed, 20 Jul 2022 12:45:32 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C13BF1947067; Wed, 20 Jul 2022 12:45:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 25AE41947066 for ; Wed, 20 Jul 2022 12:42:39 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 033CC18ECC; Wed, 20 Jul 2022 12:42:39 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.43.2.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id A2AFE90A04 for ; Wed, 20 Jul 2022 12:42:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658321140; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=FzFxr/lE/W974zUSm+0NDShGW76QXjHBS76Y3UXRRio=; b=cO5pxnST0tiRL38lizEcOJx47uYO9ZoQZQj8C0IfMeMrTnpC+Rvl+MIXc6mNbuIsymHv9x +DU/HZcB1nn2xYXJUcQ6zrC++W+y1TCZiv1Fx7Q3GC3wwqMRRx33jJoOEO+anr941ilsLj 7dFKD4ULVBE6+lIxrGAhI9jS/loOzuQ= X-MC-Unique: CKGegqtRNXiTtJdWY89fAQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH] domain_conf: rewrite if else condition Date: Wed, 20 Jul 2022 14:42:29 +0200 Message-Id: <9291030ce4362808d702ee8fbde12a98c30ce8c2.1658320927.git.khanicov@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658321143475100001 Content-Type: text/plain; charset="utf-8"; x-default="true" This patch prevents nesting of if conditions and makes the code cleaner. Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- 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 =3D virXMLPropString(address, "type"); =20 - if (type) { - if ((info->type =3D virDomainDeviceAddressTypeFromString(type)) <= =3D 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; } =20 + if ((info->type =3D virDomainDeviceAddressTypeFromString(type)) <=3D 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, * . (the functions we're going to call expect address * type to already be known). */ - if (type) { - if ((def->source.subsys.type - =3D 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; } =20 + if ((def->source.subsys.type + =3D virDomainHostdevSubsysTypeFromString(type)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown host device source address type '%s'"), + type); + return -1; + } + if (!(sourcenode =3D virXPathNode("./source", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing element in hostdev device")); @@ -6304,20 +6304,20 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node G_G= NUC_UNUSED, * . (the functions we're going to call expect address * type to already be known). */ - if (type) { - if ((def->source.caps.type - =3D 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; } =20 + if ((def->source.caps.type + =3D 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 element in hostdev device")); --=20 2.35.3