From nobody Thu May 16 01:46:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1568987599; cv=none; d=zoho.com; s=zohoarc; b=a97v3H027dv/35sTLvwliEaaHy+L/kZ5iWAruoQ+ObbS9onDe0dFHOqJRfYLlAYuq0zY2WDAWYIBiGoEvMvk6iJRLAThnSkukce8AcCFNhqHlgnzdgZ4j4liv7C6UMzCe0XS0imNxY0KBQgmneNdDpkBl/7Co7jHR1S7LLer8bo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568987599; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=jD8ynOP6z50L9MZ1RkqIlBZqy/xtHwzleRh1XLa9BWE=; b=KamEY7jnd/WsBkfN1RUR0nOla/msc5uhx7qi+zPkF8KYYeHmfmd5VmEldU2bJxF3fIU0HgKMYl/FFndzBdIWx+DOk8RC9ThdNxT0cwUBgELvtzKa9hryY8FWfTdRisOBxGPSEwXmg5DJcipdKTeOAUvgBaSnVJUeqK11pOBlAW4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568987599491167.1483087472086; Fri, 20 Sep 2019 06:53:19 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A01E618C426E; Fri, 20 Sep 2019 13:53:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 380F41001281; Fri, 20 Sep 2019 13:53:16 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D8D314E58C; Fri, 20 Sep 2019 13:53:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8KDrCBQ013135 for ; Fri, 20 Sep 2019 09:53:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6CB586017E; Fri, 20 Sep 2019 13:53:12 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2C056600C6; Fri, 20 Sep 2019 13:53:10 +0000 (UTC) Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E760C36899; Fri, 20 Sep 2019 13:53:08 +0000 (UTC) Received: by mail-qt1-f195.google.com with SMTP id o12so8746614qtf.3; Fri, 20 Sep 2019 06:53:08 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c6:df05:2a1f:6ce3:83c3:51c0]) by smtp.gmail.com with ESMTPSA id c26sm1102633qtk.93.2019.09.20.06.53.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2019 06:53:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LG2ejEn4T4rUfr24W4Wgjl6x5dyE88CkSXok66qobKw=; b=qqVRlecrVQpABuq++YzTMu3WNkrqFj8g19BMi1zoGRT6hoAScxDjwVjbXa9fmqOp+j vck+aJmDYCzbejfHk4MaK7zsnFRStJhxe4QGlVtHid0CoeZ7EmUCqj/vVDZBOXBQiSWB LiRnS+QUqRw6eIE0PmubTVkV0HWtESbjmvQCl05KLZhKBPdNkdEgxrxzX5WkrNBCUHwx 5Xn/uWLiWhNOvS5bYUb0YsfoJHcAU0NCOliHgco8oFtZptc6/pxCbSXkYRgbxVS9Alsd YLSqTdCPrwGWm7w9C3auklkmzaSBM1cj6Vcs1gALlU9zm8iRc/sKA6PkGYfFqLOpVl5+ PNrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LG2ejEn4T4rUfr24W4Wgjl6x5dyE88CkSXok66qobKw=; b=lQ7Diaq1Ypj9qavKyHXg2GAHRYt0K5qmIY8WmOqrPtMiKIUagJz5kBCkQtRnv4stSd 8zc+0/56wzTNULwSvhUKLdeFet5w19QXW/bnzHXC3GQW3oEfqBxsvw6io7A4+jkqnd+L HEsjgd9B9UH7GMfdcc7HLhCwP/jMEGvaHMeW3hH99TQjREq4XU58A1WCeWHoj/mbXft7 XOhTIdSCQM4zptTaYpJTXhykRPatSXylDai7UXSTfcMWhTAIkE8JyqnZ6lg6vVgrtysV QxsP3ot43SO04wRtqA9vdG/qaT2b8MhS8Duxo9cYBMYM5ylC2YPky0hlyo8ZjCT0R07r 6Liw== X-Gm-Message-State: APjAAAUw1cXJ3dK5/TGdZZ6ORVDBq+v/4Barhe+osJA2xK40TnAyJBwh qZ4GeYNotOXdy8VHERcfz0ylXJwy X-Google-Smtp-Source: APXvYqwa4c3JCAFBf/8HsFVGQbwRiygk/5yeiJ09V1lI67Usan7O5uu2jRdiEIuVPBL6FkSS6LM/6A== X-Received: by 2002:a0c:ef87:: with SMTP id w7mr13139886qvr.49.1568987587868; Fri, 20 Sep 2019 06:53:07 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Fri, 20 Sep 2019 10:52:54 -0300 Message-Id: <20190920135255.28834-2-danielhb413@gmail.com> In-Reply-To: <20190920135255.28834-1-danielhb413@gmail.com> References: <20190920135255.28834-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 20 Sep 2019 13:53:09 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 20 Sep 2019 13:53:09 +0000 (UTC) for IP:'209.85.160.195' DOMAIN:'mail-qt1-f195.google.com' HELO:'mail-qt1-f195.google.com' FROM:'danielhb413@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.153 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS) 209.85.160.195 mail-qt1-f195.google.com 209.85.160.195 mail-qt1-f195.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , eskultet@redhat.com Subject: [libvirt] [PATCH v2 1/2] qemu_domain_address.c: use VIR_AUTOFREE() in strings X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.62]); Fri, 20 Sep 2019 13:53:18 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" A few 'cleanup' labels gone after using VIR_AUTOFREE() on the @addrStr variable. Reviewed-by: Erik Skultety Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_domain_address.c | 69 +++++++++++++++------------------- 1 file changed, 30 insertions(+), 39 deletions(-) diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 216ba6235e..e20481607f 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -1524,12 +1524,11 @@ qemuDomainCollectPCIAddress(virDomainDefPtr def ATT= RIBUTE_UNUSED, * inappropriate address types. */ if (!info->pciConnectFlags) { - char *addrStr =3D virPCIDeviceAddressAsString(&info->addr.pci); + VIR_AUTOFREE(char *) addrStr =3D virPCIDeviceAddressAsString(&info= ->addr.pci); =20 VIR_WARN("qemuDomainDeviceCalculatePCIConnectFlags() thinks that t= he " "device with PCI address %s should not have a PCI address= ", addrStr ? addrStr : "(unknown)"); - VIR_FREE(addrStr); =20 info->pciConnectFlags =3D VIR_PCI_CONNECT_TYPE_PCI_DEVICE; } @@ -1720,11 +1719,10 @@ qemuDomainValidateDevicePCISlotsPIIX3(virDomainDefP= tr def, virQEMUCapsPtr qemuCaps, virDomainPCIAddressSetPtr addrs) { - int ret =3D -1; size_t i; virPCIDeviceAddress tmp_addr; bool qemuDeviceVideoUsable =3D virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVI= CE_VIDEO_PRIMARY); - char *addrStr =3D NULL; + VIR_AUTOFREE(char *) addrStr =3D NULL; virDomainPCIConnectFlags flags =3D (VIR_PCI_CONNECT_HOTPLUGGABLE | VIR_PCI_CONNECT_TYPE_PCI_DEVICE); =20 @@ -1742,7 +1740,7 @@ qemuDomainValidateDevicePCISlotsPIIX3(virDomainDefPtr= def, cont->info.addr.pci.function !=3D 1) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Primary IDE controller must have PCI= address 0:0:1.1")); - goto cleanup; + return -1; } } else { cont->info.type =3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; @@ -1762,7 +1760,7 @@ qemuDomainValidateDevicePCISlotsPIIX3(virDomainDefPtr= def, cont->info.addr.pci.function !=3D 2) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("PIIX3 USB controller at index 0 must= have PCI address 0:0:1.2")); - goto cleanup; + return -1; } } else { cont->info.type =3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; @@ -1777,7 +1775,7 @@ qemuDomainValidateDevicePCISlotsPIIX3(virDomainDefPtr= def, } if (addrs->nbuses && virDomainPCIAddressReserveAddr(addrs, &cont->info.addr.pci, fl= ags, 0) < 0) - goto cleanup; + return -1; } =20 /* Implicit PIIX3 devices living on slot 1 not handled above */ @@ -1786,11 +1784,11 @@ qemuDomainValidateDevicePCISlotsPIIX3(virDomainDefP= tr def, tmp_addr.slot =3D 1; /* ISA Bridge at 00:01.0 */ if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags, 0) < 0) - goto cleanup; + return -1; /* Bridge at 00:01.3 */ tmp_addr.function =3D 3; if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags, 0) < 0) - goto cleanup; + return -1; } =20 if (def->nvideos > 0 && @@ -1808,26 +1806,26 @@ qemuDomainValidateDevicePCISlotsPIIX3(virDomainDefP= tr def, tmp_addr.slot =3D 2; =20 if (!(addrStr =3D virPCIDeviceAddressAsString(&tmp_addr))) - goto cleanup; + return -1; if (!virDomainPCIAddressValidate(addrs, &tmp_addr, addrStr, flags, true)) - goto cleanup; + return -1; =20 if (virDomainPCIAddressSlotInUse(addrs, &tmp_addr)) { if (qemuDeviceVideoUsable) { if (qemuDomainPCIAddressReserveNextAddr(addrs, &primaryVideo-= >info) < 0) { - goto cleanup; + return -1; } } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("PCI address 0:0:2.0 is in use, " "QEMU needs it for primary video")); - goto cleanup; + return -1; } } else { if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags= , 0) < 0) - goto cleanup; + return -1; primaryVideo->info.addr.pci =3D tmp_addr; primaryVideo->info.type =3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE= _PCI; } @@ -1838,7 +1836,7 @@ qemuDomainValidateDevicePCISlotsPIIX3(virDomainDefPtr= def, primaryVideo->info.addr.pci.function !=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Primary video card must have PCI address= 0:0:2.0")); - goto cleanup; + return -1; } /* If TYPE =3D=3D PCI, then qemuDomainCollectPCIAddress() func= tion * has already reserved the address, so we must skip */ @@ -1852,13 +1850,10 @@ qemuDomainValidateDevicePCISlotsPIIX3(virDomainDefP= tr def, " device will not be possible without manual" " intervention"); } else if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags,= 0) < 0) { - goto cleanup; + return -1; } } - ret =3D 0; - cleanup: - VIR_FREE(addrStr); - return ret; + return 0; } =20 =20 @@ -1867,11 +1862,10 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr= def, virQEMUCapsPtr qemuCaps, virDomainPCIAddressSetPtr addrs) { - int ret =3D -1; size_t i; virPCIDeviceAddress tmp_addr; bool qemuDeviceVideoUsable =3D virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVI= CE_VIDEO_PRIMARY); - char *addrStr =3D NULL; + VIR_AUTOFREE(char *) addrStr =3D NULL; virDomainPCIConnectFlags flags =3D VIR_PCI_CONNECT_TYPE_PCIE_DEVICE; =20 for (i =3D 0; i < def->ncontrollers; i++) { @@ -1891,7 +1885,7 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr d= ef, cont->info.addr.pci.function !=3D 2) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Primary SATA controller must hav= e PCI address 0:0:1f.2")); - goto cleanup; + return -1; } } else { cont->info.type =3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; @@ -1928,7 +1922,7 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr d= ef, } if (assign) { if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, f= lags, 0) < 0) - goto cleanup; + return -1; =20 cont->info.type =3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; cont->info.addr.pci.domain =3D 0; @@ -1951,7 +1945,7 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr d= ef, tmp_addr.slot =3D 0x1E; if (!virDomainPCIAddressSlotInUse(addrs, &tmp_addr)) { if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, f= lags, 0) < 0) - goto cleanup; + return -1; =20 cont->info.type =3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; cont->info.addr.pci.domain =3D 0; @@ -1975,12 +1969,12 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr= def, tmp_addr.function =3D 0; tmp_addr.multi =3D VIR_TRISTATE_SWITCH_ON; if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags, 0) < 0) - goto cleanup; + return -1; =20 tmp_addr.function =3D 3; tmp_addr.multi =3D VIR_TRISTATE_SWITCH_ABSENT; if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags, 0) < 0) - goto cleanup; + return -1; } =20 if (def->nvideos > 0 && @@ -1997,25 +1991,25 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr= def, tmp_addr.slot =3D 1; =20 if (!(addrStr =3D virPCIDeviceAddressAsString(&tmp_addr))) - goto cleanup; + return -1; if (!virDomainPCIAddressValidate(addrs, &tmp_addr, addrStr, flags, true)) - goto cleanup; + return -1; =20 if (virDomainPCIAddressSlotInUse(addrs, &tmp_addr)) { if (qemuDeviceVideoUsable) { if (qemuDomainPCIAddressReserveNextAddr(addrs, &primaryVideo-= >info) < 0) - goto cleanup; + return -1; } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("PCI address 0:0:1.0 is in use, " "QEMU needs it for primary video")); - goto cleanup; + return -1; } } else { if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags= , 0) < 0) - goto cleanup; + return -1; primaryVideo->info.type =3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE= _PCI; primaryVideo->info.addr.pci =3D tmp_addr; } @@ -2026,7 +2020,7 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr d= ef, primaryVideo->info.addr.pci.function !=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Primary video card must have PCI address= 0:0:1.0")); - goto cleanup; + return -1; } /* If TYPE =3D=3D PCI, then qemuDomainCollectPCIAddress() func= tion * has already reserved the address, so we must skip */ @@ -2041,7 +2035,7 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr d= ef, " intervention"); virResetLastError(); } else if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags,= 0) < 0) { - goto cleanup; + return -1; } } =20 @@ -2062,7 +2056,7 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr d= ef, continue; } if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags, 0)= < 0) - goto cleanup; + return -1; =20 sound->info.type =3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; sound->info.addr.pci =3D tmp_addr; @@ -2070,10 +2064,7 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr = def, } } =20 - ret =3D 0; - cleanup: - VIR_FREE(addrStr); - return ret; + return 0; } =20 =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 16 01:46:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1568987623; cv=none; d=zoho.com; s=zohoarc; b=bwxIhF82AHs2QzN1cE39sjU/fZsLS89e76VlMPxKhGizhfkpzFV9Sljq0U8aOSPHPYHCp9xMXlyrTMX5B7PMQRvORsFZZtvXJHkJYOXbbw7e5C72iEmKNpmuWOeiS79D3JJRRtci0imppWdcT3dYeumRoweWd9dYGeNbsWPUFbM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568987623; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=oFG7aMBObnV/zV5kpLix1JTt3oSAWXIkTZmyeV6NIS0=; b=E3vp84Lh5hZ+XR/W8k2CFjxvLFG/PyyYPfmY73eGI5wSEG9Y/+Ok+1QKc1pDbauzjp8UfP7YJy5GLYurEKGwIAUJNJ0tqsUE27I4PIjEdifWEGA6fma0v3yDHceJwUXHhY5iIdgtoJnk7RA3Ance1VBZz+Lcl9fVNpV7AohwjcI= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568987623226415.05148129519887; Fri, 20 Sep 2019 06:53:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6DBC83082A6C; Fri, 20 Sep 2019 13:53:41 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4458B60C80; Fri, 20 Sep 2019 13:53:41 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 040EE1800B74; Fri, 20 Sep 2019 13:53:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8KDrDwR013142 for ; Fri, 20 Sep 2019 09:53:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 884FE19C5B; Fri, 20 Sep 2019 13:53:13 +0000 (UTC) Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2FA5319D70; Fri, 20 Sep 2019 13:53:11 +0000 (UTC) Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4EF673082A8D; Fri, 20 Sep 2019 13:53:10 +0000 (UTC) Received: by mail-qt1-f195.google.com with SMTP id n7so8723172qtb.6; Fri, 20 Sep 2019 06:53:10 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c6:df05:2a1f:6ce3:83c3:51c0]) by smtp.gmail.com with ESMTPSA id c26sm1102633qtk.93.2019.09.20.06.53.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2019 06:53:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OiR4DiAgZ94ZhUK+gzDIPF8i1rrHY776GvN/w0esPoU=; b=C6O9oT28vGIrWIrcZNSo06utaQcEaO6YmCdMvUJfX59KvdZujyz5bmAFFiRQ+1PLai fd2R4eWhEFN6Hvt/PB3W0ipSnab1VjuguFp0JDg+dLxUKPb5zSjz58dCmqnHvnHbw0aA 5R2iSM5vRwgwEHdgXAdyVWMpsXLgoROeH7KLURxD5AihAMS4c+nSqWNky08fPNEfPVmx cDI9znyk7RDk+62N6bWY/DzoorS9fB7X+ZUmSaFQBPHK8vneVtBum3Ak+Qj63yCQERyA HsaB5iaTNikc00eHRwd4NE0v4/kl1hCMYBNTtf+LnFmrP0PTtWVITeKFTfRRQwUSo8V0 9vkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OiR4DiAgZ94ZhUK+gzDIPF8i1rrHY776GvN/w0esPoU=; b=tD4+GgYKoRaQtBzAKfazds/CAy55qPtDWQsmJtZpGGnDboLo2V2PSDzEwFZ88veCG9 L5sQY4LATXoOl7+uoF4xuWRsVBTHSJINdYarRMo3TAddD0GVMh/fGd+408CAs0v/YhdL UfiiotTfiGD2jjb/0Utqc4jJL5JpG+QGxru/M+uiQ0UKmHTYoFlrtzosWEB1uoVV5Gfv rDYU7KblCToPsMVxmCzqnjZID3SAss1TxCUw5NrRCxHkXdVjJy2H936YFG3+kckd2Gpm huDj9NJYlTiCOMtOx4HavB6+ykSKl87xvsy2ciwGiynT4cQaqJ8kYKUyOyBUepiEO4i5 +QSQ== X-Gm-Message-State: APjAAAX8py6k8zN6MQgbW5rXgXFX5iGvMeDJZCPtq1ohM6hirsGD/syl MZQ3Hkk9GNJ4fCSU+PSGiBdybVQN X-Google-Smtp-Source: APXvYqzBnJE4OYOd5axYmu29B0nj1R35AK35E8dZLbnX32doXVPVwKBrDRBKiZSRkKsEUuDqjclKbA== X-Received: by 2002:a05:6214:180e:: with SMTP id o14mr12411418qvw.99.1568987589310; Fri, 20 Sep 2019 06:53:09 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Fri, 20 Sep 2019 10:52:55 -0300 Message-Id: <20190920135255.28834-3-danielhb413@gmail.com> In-Reply-To: <20190920135255.28834-1-danielhb413@gmail.com> References: <20190920135255.28834-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 20 Sep 2019 13:53:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 20 Sep 2019 13:53:10 +0000 (UTC) for IP:'209.85.160.195' DOMAIN:'mail-qt1-f195.google.com' HELO:'mail-qt1-f195.google.com' FROM:'danielhb413@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.153 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS) 209.85.160.195 mail-qt1-f195.google.com 209.85.160.195 mail-qt1-f195.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.45 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , eskultet@redhat.com Subject: [libvirt] [PATCH v2 2/2] qemu_domain_address: use virPCIDeviceAddressEqual() in conditionals X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 20 Sep 2019 13:53:41 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" A common operation in qemu_domain_address is comparing a virPCIDeviceAddress and assigning domain, bus, slot and function to a specific value. The former can be done with the existing virPCIDeviceAddressEqual() helper, as long as we provide a virPCIDeviceAddress to compare it to. The later can be done by direct assignment of the now existing virPCIDeviceAddress struct. The defined values of domain, bus, slot and function will be assigned to info->addr.pci, the other values are zeroed (which happens to be their default values too). It's also worth noticing that all these assignments are being conditioned by virDeviceInfoPCIAddressIsPresent() calls, thus it's sensible to discard any non-zero values that might happen to exist in @cont->info.addr, if we settled beforehand that @cont->info.addr is not present or bogus. Suggested-by: Erik Skultety Signed-off-by: Daniel Henrique Barboza Reviewed-by: Erik Skultety --- src/qemu/qemu_domain_address.c | 56 +++++++++++++++------------------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index e20481607f..4f9ae1f37d 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -1729,45 +1729,41 @@ qemuDomainValidateDevicePCISlotsPIIX3(virDomainDefP= tr def, /* Verify that first IDE and USB controllers (if any) is on the PIIX3,= fn 1 */ for (i =3D 0; i < def->ncontrollers; i++) { virDomainControllerDefPtr cont =3D def->controllers[i]; + virPCIDeviceAddress primaryIDEAddr =3D {.domain =3D 0, .bus =3D 0, + .slot =3D 1, .function =3D 1= }; + virPCIDeviceAddress piix3USBAddr =3D {.domain =3D 0, .bus =3D 0, + .slot =3D 1, .function =3D 2}; =20 /* First IDE controller lives on the PIIX3 at slot=3D1, function= =3D1 */ if (cont->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_IDE && cont->idx =3D=3D 0) { if (virDeviceInfoPCIAddressIsPresent(&cont->info)) { - if (cont->info.addr.pci.domain !=3D 0 || - cont->info.addr.pci.bus !=3D 0 || - cont->info.addr.pci.slot !=3D 1 || - cont->info.addr.pci.function !=3D 1) { + if (!virPCIDeviceAddressEqual(&cont->info.addr.pci, + &primaryIDEAddr)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Primary IDE controller must have PCI= address 0:0:1.1")); + _("Primary IDE controller must have PCI= " + "address 0:0:1.1")); return -1; } } else { cont->info.type =3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; - cont->info.addr.pci.domain =3D 0; - cont->info.addr.pci.bus =3D 0; - cont->info.addr.pci.slot =3D 1; - cont->info.addr.pci.function =3D 1; + cont->info.addr.pci =3D primaryIDEAddr; } } else if (cont->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_USB && cont->idx =3D=3D 0 && (cont->model =3D=3D VIR_DOMAIN_CONTROLLER_MODEL_USB_PII= X3_UHCI || cont->model =3D=3D VIR_DOMAIN_CONTROLLER_MODEL_USB_DEF= AULT)) { if (virDeviceInfoPCIAddressIsPresent(&cont->info)) { - if (cont->info.addr.pci.domain !=3D 0 || - cont->info.addr.pci.bus !=3D 0 || - cont->info.addr.pci.slot !=3D 1 || - cont->info.addr.pci.function !=3D 2) { + if (!virPCIDeviceAddressEqual(&cont->info.addr.pci, + &piix3USBAddr)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("PIIX3 USB controller at index 0 must= have PCI address 0:0:1.2")); + _("PIIX3 USB controller at index 0 must= " + "have PCI address 0:0:1.2")); return -1; } } else { cont->info.type =3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; - cont->info.addr.pci.domain =3D 0; - cont->info.addr.pci.bus =3D 0; - cont->info.addr.pci.slot =3D 1; - cont->info.addr.pci.function =3D 2; + cont->info.addr.pci =3D piix3USBAddr; } } else { /* this controller is not skipped in qemuDomainCollectPCIAddre= ss */ @@ -1800,6 +1796,8 @@ qemuDomainValidateDevicePCISlotsPIIX3(virDomainDefPtr= def, * at slot 2. */ virDomainVideoDefPtr primaryVideo =3D def->videos[0]; + virPCIDeviceAddress primaryCardAddr =3D {.domain =3D 0, .bus =3D 0, + .slot =3D 2, .function =3D = 0}; =20 if (virDeviceInfoPCIAddressIsWanted(&primaryVideo->info)) { memset(&tmp_addr, 0, sizeof(tmp_addr)); @@ -1830,10 +1828,8 @@ qemuDomainValidateDevicePCISlotsPIIX3(virDomainDefPt= r def, primaryVideo->info.type =3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE= _PCI; } } else if (!qemuDeviceVideoUsable) { - if (primaryVideo->info.addr.pci.domain !=3D 0 || - primaryVideo->info.addr.pci.bus !=3D 0 || - primaryVideo->info.addr.pci.slot !=3D 2 || - primaryVideo->info.addr.pci.function !=3D 0) { + if (!virPCIDeviceAddressEqual(&primaryVideo->info.addr.pci, + &primaryCardAddr)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Primary video card must have PCI address= 0:0:2.0")); return -1; @@ -1870,6 +1866,8 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr d= ef, =20 for (i =3D 0; i < def->ncontrollers; i++) { virDomainControllerDefPtr cont =3D def->controllers[i]; + virPCIDeviceAddress primarySATAAddr =3D {.domain =3D 0, .bus =3D 0, + .slot =3D 0x1F, .function = =3D 2}; =20 switch (cont->type) { case VIR_DOMAIN_CONTROLLER_TYPE_SATA: @@ -1879,20 +1877,16 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDefPtr= def, */ if (cont->idx =3D=3D 0) { if (virDeviceInfoPCIAddressIsPresent(&cont->info)) { - if (cont->info.addr.pci.domain !=3D 0 || - cont->info.addr.pci.bus !=3D 0 || - cont->info.addr.pci.slot !=3D 0x1F || - cont->info.addr.pci.function !=3D 2) { + if (!virPCIDeviceAddressEqual(&cont->info.addr.pci, + &primarySATAAddr)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Primary SATA controller must hav= e PCI address 0:0:1f.2")); + _("Primary SATA controller must hav= e " + "PCI address 0:0:1f.2")); return -1; } } else { cont->info.type =3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; - cont->info.addr.pci.domain =3D 0; - cont->info.addr.pci.bus =3D 0; - cont->info.addr.pci.slot =3D 0x1F; - cont->info.addr.pci.function =3D 2; + cont->info.addr.pci =3D primarySATAAddr; } } break; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list