From nobody Mon Nov 25 09:41:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1716371807; cv=none; d=zohomail.com; s=zohoarc; b=RJXaNv5sgrJtBxoqvISLO8oE+XpcYmJJjfjXkGv6Ys1w9rEwPQwcah+ubU0hgNm35eHsEiBHQbl8eshRtWRw5UnTT1IFVASoh83oXQtnUMiEeSmzh+tNiduQJDJ9oDMDyTYiUxCtcWPUMsV0g93/TcN88mD8Hjml64JvF/AlpVc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371807; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NNLlcHvWav9P68aqT0gvS8T3g+3N5HiMfA2h8sJ5x7g=; b=T6VxgAZvTvihgbJg541Tp5Z+epmkWjLnlcl0zfZzZvdcKZo2J+LKK6qgpbsopryedKR7GKCQDbVsPV21YEjSFVpyH9SbktgDo/2icOTYEVHEAL6Qxy6ozTcOmoD2Ve9rEmGrtNIPFYO7Y14dkWtIzI8u9O5jW6RQuYkGGqWEzJU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1716371807749882.908492156498; Wed, 22 May 2024 02:56:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihS-0004yp-9j; Wed, 22 May 2024 05:55:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9ihP-0004ez-5b for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9ihL-0001ou-TU for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:54 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-235-yBhmIAcPPXSRCgc3A17tRQ-1; Wed, 22 May 2024 05:55:49 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 25C6B8008A4; Wed, 22 May 2024 09:55:49 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 047CA2818; Wed, 22 May 2024 09:55:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371751; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NNLlcHvWav9P68aqT0gvS8T3g+3N5HiMfA2h8sJ5x7g=; b=Vcw7ZD7wowelFSIx/hymDv5LqlHgOhT6yzIWmImVbcQfJHoyt67q6mTkX/aCEpfjTHpoB7 MO3uR3zOloamP3HYekorZXYf3H8y/KgWUPyTKugOvjMMEuQgaTJ0GX/OExjGzQjz8qZokT KHJkobvrNs9CsxDLRJQ+ebOk6dC5xNk= X-MC-Unique: yBhmIAcPPXSRCgc3A17tRQ-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 42/47] vfio/pci: Make capability related functions return bool Date: Wed, 22 May 2024 11:54:37 +0200 Message-ID: <20240522095442.195243-43-clg@redhat.com> In-Reply-To: <20240522095442.195243-1-clg@redhat.com> References: <20240522095442.195243-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1716371808918100001 From: Zhenzhong Duan The functions operating on capability don't have a consistent return style. Below functions are in bool-valued functions style: vfio_msi_setup() vfio_msix_setup() vfio_add_std_cap() vfio_add_capabilities() Below two are integer-valued functions: vfio_add_vendor_specific_cap() vfio_setup_pcie_cap() But the returned integer is only used for check succeed/failure. Change them all to return bool so now all capability related functions follow the coding standand in qapi/error.h to return bool. Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.c | 77 ++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 41 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index ab8f74299eab85e224a02f45d4b506e860b514f9..c3323912dd773e80ad2dbbefc5d= 833e8a33cd147 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -1339,7 +1339,7 @@ static void vfio_disable_interrupts(VFIOPCIDevice *vd= ev) } } =20 -static int vfio_msi_setup(VFIOPCIDevice *vdev, int pos, Error **errp) +static bool vfio_msi_setup(VFIOPCIDevice *vdev, int pos, Error **errp) { uint16_t ctrl; bool msi_64bit, msi_maskbit; @@ -1349,7 +1349,7 @@ static int vfio_msi_setup(VFIOPCIDevice *vdev, int po= s, Error **errp) if (pread(vdev->vbasedev.fd, &ctrl, sizeof(ctrl), vdev->config_offset + pos + PCI_CAP_FLAGS) !=3D sizeof(ctrl)= ) { error_setg_errno(errp, errno, "failed reading MSI PCI_CAP_FLAGS"); - return -errno; + return false; } ctrl =3D le16_to_cpu(ctrl); =20 @@ -1362,14 +1362,14 @@ static int vfio_msi_setup(VFIOPCIDevice *vdev, int = pos, Error **errp) ret =3D msi_init(&vdev->pdev, pos, entries, msi_64bit, msi_maskbit, &e= rr); if (ret < 0) { if (ret =3D=3D -ENOTSUP) { - return 0; + return true; } error_propagate_prepend(errp, err, "msi_init failed: "); - return ret; + return false; } vdev->msi_cap_size =3D 0xa + (msi_maskbit ? 0xa : 0) + (msi_64bit ? 0x= 4 : 0); =20 - return 0; + return true; } =20 static void vfio_pci_fixup_msix_region(VFIOPCIDevice *vdev) @@ -1644,7 +1644,7 @@ static bool vfio_msix_early_setup(VFIOPCIDevice *vdev= , Error **errp) return vfio_pci_relocate_msix(vdev, errp); } =20 -static int vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp) +static bool vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp) { int ret; Error *err =3D NULL; @@ -1660,11 +1660,11 @@ static int vfio_msix_setup(VFIOPCIDevice *vdev, int= pos, Error **errp) if (ret < 0) { if (ret =3D=3D -ENOTSUP) { warn_report_err(err); - return 0; + return true; } =20 error_propagate(errp, err); - return ret; + return false; } =20 /* @@ -1698,7 +1698,7 @@ static int vfio_msix_setup(VFIOPCIDevice *vdev, int p= os, Error **errp) memory_region_set_enabled(&vdev->pdev.msix_table_mmio, false); } =20 - return 0; + return true; } =20 static void vfio_teardown_msi(VFIOPCIDevice *vdev) @@ -1977,8 +1977,8 @@ static void vfio_pci_disable_rp_atomics(VFIOPCIDevice= *vdev) } } =20 -static int vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size, - Error **errp) +static bool vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size, + Error **errp) { uint16_t flags; uint8_t type; @@ -1992,7 +1992,7 @@ static int vfio_setup_pcie_cap(VFIOPCIDevice *vdev, i= nt pos, uint8_t size, =20 error_setg(errp, "assignment of PCIe type 0x%x " "devices is not currently supported", type); - return -EINVAL; + return false; } =20 if (!pci_bus_is_express(pci_get_bus(&vdev->pdev))) { @@ -2025,7 +2025,7 @@ static int vfio_setup_pcie_cap(VFIOPCIDevice *vdev, i= nt pos, uint8_t size, } =20 if (pci_bus_is_express(bus)) { - return 0; + return true; } =20 } else if (pci_bus_is_root(pci_get_bus(&vdev->pdev))) { @@ -2063,7 +2063,7 @@ static int vfio_setup_pcie_cap(VFIOPCIDevice *vdev, i= nt pos, uint8_t size, * Legacy endpoints don't belong on the root complex. Windows * seems to be happier with devices if we skip the capability. */ - return 0; + return true; } =20 } else { @@ -2099,12 +2099,12 @@ static int vfio_setup_pcie_cap(VFIOPCIDevice *vdev,= int pos, uint8_t size, pos =3D pci_add_capability(&vdev->pdev, PCI_CAP_ID_EXP, pos, size, errp); if (pos < 0) { - return pos; + return false; } =20 vdev->pdev.exp.exp_cap =3D pos; =20 - return pos; + return true; } =20 static void vfio_check_pcie_flr(VFIOPCIDevice *vdev, uint8_t pos) @@ -2137,14 +2137,14 @@ static void vfio_check_af_flr(VFIOPCIDevice *vdev, = uint8_t pos) } } =20 -static int vfio_add_vendor_specific_cap(VFIOPCIDevice *vdev, int pos, - uint8_t size, Error **errp) +static bool vfio_add_vendor_specific_cap(VFIOPCIDevice *vdev, int pos, + uint8_t size, Error **errp) { PCIDevice *pdev =3D &vdev->pdev; =20 pos =3D pci_add_capability(pdev, PCI_CAP_ID_VNDR, pos, size, errp); if (pos < 0) { - return pos; + return false; } =20 /* @@ -2156,15 +2156,15 @@ static int vfio_add_vendor_specific_cap(VFIOPCIDevi= ce *vdev, int pos, memset(pdev->cmask + pos + 3, 0, size - 3); } =20 - return pos; + return true; } =20 -static int vfio_add_std_cap(VFIOPCIDevice *vdev, uint8_t pos, Error **errp) +static bool vfio_add_std_cap(VFIOPCIDevice *vdev, uint8_t pos, Error **err= p) { ERRP_GUARD(); PCIDevice *pdev =3D &vdev->pdev; uint8_t cap_id, next, size; - int ret; + bool ret; =20 cap_id =3D pdev->config[pos]; next =3D pdev->config[pos + PCI_CAP_LIST_NEXT]; @@ -2185,9 +2185,8 @@ static int vfio_add_std_cap(VFIOPCIDevice *vdev, uint= 8_t pos, Error **errp) * will be changed as we unwind the stack. */ if (next) { - ret =3D vfio_add_std_cap(vdev, next, errp); - if (ret) { - return ret; + if (!vfio_add_std_cap(vdev, next, errp)) { + return false; } } else { /* Begin the rebuild, use QEMU emulated list bits */ @@ -2197,7 +2196,7 @@ static int vfio_add_std_cap(VFIOPCIDevice *vdev, uint= 8_t pos, Error **errp) =20 ret =3D vfio_add_virt_caps(vdev, errp); if (ret) { - return ret; + return false; } } =20 @@ -2221,28 +2220,27 @@ static int vfio_add_std_cap(VFIOPCIDevice *vdev, ui= nt8_t pos, Error **errp) case PCI_CAP_ID_PM: vfio_check_pm_reset(vdev, pos); vdev->pm_cap =3D pos; - ret =3D pci_add_capability(pdev, cap_id, pos, size, errp); + ret =3D pci_add_capability(pdev, cap_id, pos, size, errp) >=3D 0; break; case PCI_CAP_ID_AF: vfio_check_af_flr(vdev, pos); - ret =3D pci_add_capability(pdev, cap_id, pos, size, errp); + ret =3D pci_add_capability(pdev, cap_id, pos, size, errp) >=3D 0; break; case PCI_CAP_ID_VNDR: ret =3D vfio_add_vendor_specific_cap(vdev, pos, size, errp); break; default: - ret =3D pci_add_capability(pdev, cap_id, pos, size, errp); + ret =3D pci_add_capability(pdev, cap_id, pos, size, errp) >=3D 0; break; } =20 - if (ret < 0) { + if (!ret) { error_prepend(errp, "failed to add PCI capability 0x%x[0x%x]@0x%x: ", cap_id, size, pos); - return ret; } =20 - return 0; + return ret; } =20 static int vfio_setup_rebar_ecap(VFIOPCIDevice *vdev, uint16_t pos) @@ -2388,23 +2386,21 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev) return; } =20 -static int vfio_add_capabilities(VFIOPCIDevice *vdev, Error **errp) +static bool vfio_add_capabilities(VFIOPCIDevice *vdev, Error **errp) { PCIDevice *pdev =3D &vdev->pdev; - int ret; =20 if (!(pdev->config[PCI_STATUS] & PCI_STATUS_CAP_LIST) || !pdev->config[PCI_CAPABILITY_LIST]) { - return 0; /* Nothing to add */ + return true; /* Nothing to add */ } =20 - ret =3D vfio_add_std_cap(vdev, pdev->config[PCI_CAPABILITY_LIST], errp= ); - if (ret) { - return ret; + if (!vfio_add_std_cap(vdev, pdev->config[PCI_CAPABILITY_LIST], errp)) { + return false; } =20 vfio_add_ext_cap(vdev); - return 0; + return true; } =20 void vfio_pci_pre_reset(VFIOPCIDevice *vdev) @@ -3133,8 +3129,7 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) =20 vfio_bars_register(vdev); =20 - ret =3D vfio_add_capabilities(vdev, errp); - if (ret) { + if (!vfio_add_capabilities(vdev, errp)) { goto out_teardown; } =20 --=20 2.45.1