From nobody Sat Feb 7 03:51:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; 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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1715064357; cv=none; d=zohomail.com; s=zohoarc; b=R8HFuWcgQq0b7snn6Xhh1oilk00afbZpW4iiTmy5suZvckSAPgdxUGG2DL+TlWjL8G7kuLafELAfWeKKEyMvILxbnC3cUMJYIACFMJa8hDP9IFs+4tPEXXAkfBkM1jdPX5UrXH4ZC3BfkGcAtCKn25jghu+SxG/piqVAEXhruwM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715064357; h=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=GT41Rvaq2i1NCqW0550cl1aaCz1pp6luF6Zejt8Kf3A=; b=Hgver4n4S8c2DoGmV6eIfQi+TIrpsjAU7REAnoTQB6uzNSoEuAJ/cXRnSHlnMjyhbUPZN2YYwkhiu7kQ02+ii5CaF+U9jHTLfUgIpT/TVmyTm68GZ4oD6s4mxbaBdD2dFvN3ZvyPgku8WqTcjVLsIP94h0K1hmWOf0Z1K/FurG4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; 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 1715064357054550.9655885662379; Mon, 6 May 2024 23:45:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4EZo-00038m-JK; Tue, 07 May 2024 02:45:25 -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 1s4EZg-000365-RS for qemu-devel@nongnu.org; Tue, 07 May 2024 02:45:17 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4EZf-000550-3m for qemu-devel@nongnu.org; Tue, 07 May 2024 02:45:16 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 23:45:13 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 23:45:11 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715064315; x=1746600315; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bFd4oSxT+3OuxTU6241PGfq4mw6h6aaCpEOi35TjN4M=; b=eT3xpiBQJe4DpwgQ25U8sF5RU3NCRwGlIJ+LKF6fVQH9z6goEfFAVOVl i3u7aQ3ItXk5j8+33h45pFZkv/619KtaOCQ2v9xBGlCJpDGcA1zNNHsgE oYFuPTTYIJcL6EQYm4I0DSfbkxbxkzkl/RR98m68qzYSh7MNHd9jq7E0a oBY+A7WXikFzOQZ562y14llf5/GBW0YZ7Tj/HWbR2Z3219+ZsfeBuZFe/ F/kolaDJoUpundul1FqVbK9s7FyCiXu1e1LRmHCZvgCfP1dzDqJ65wnQa +WuLuAi67Hu1wvSFVYIiAud1lcYEKsSVeQDVqX80yAP0b12bbezy7toX6 Q==; X-CSE-ConnectionGUID: QnpaZsFLSZiKsLgN9sbEhg== X-CSE-MsgGUID: N+Vi9G9jT2SVMcJWiCJuTQ== X-IronPort-AV: E=McAfee;i="6600,9927,11065"; a="22240215" X-IronPort-AV: E=Sophos;i="6.07,260,1708416000"; d="scan'208";a="22240215" X-CSE-ConnectionGUID: DpczNi9WRzyxRpESV0KdSQ== X-CSE-MsgGUID: klhrWXTZQ5qjIi74yUkZZA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,260,1708416000"; d="scan'208";a="28407506" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v2 01/11] vfio/pci: Use g_autofree in vfio_realize Date: Tue, 7 May 2024 14:42:42 +0800 Message-Id: <20240507064252.457884-2-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240507064252.457884-1-zhenzhong.duan@intel.com> References: <20240507064252.457884-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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 @intel.com) X-ZM-MESSAGEID: 1715064357521100008 Content-Type: text/plain; charset="utf-8" Local pointer name is allocated before vfio_attach_device() call and freed after the call. Same for tmp when calling realpath(). Use 'g_autofree' to avoid the g_free() calls. Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater --- hw/vfio/pci.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 64780d1b79..576b21e2bb 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2946,12 +2946,13 @@ static void vfio_realize(PCIDevice *pdev, Error **e= rrp) ERRP_GUARD(); VFIOPCIDevice *vdev =3D VFIO_PCI(pdev); VFIODevice *vbasedev =3D &vdev->vbasedev; - char *tmp, *subsys; + char *subsys; Error *err =3D NULL; int i, ret; bool is_mdev; char uuid[UUID_STR_LEN]; - char *name; + g_autofree char *name =3D NULL; + g_autofree char *tmp =3D NULL; =20 if (vbasedev->fd < 0 && !vbasedev->sysfsdev) { if (!(~vdev->host.domain || ~vdev->host.bus || @@ -2982,7 +2983,6 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) */ tmp =3D g_strdup_printf("%s/subsystem", vbasedev->sysfsdev); subsys =3D realpath(tmp, NULL); - g_free(tmp); is_mdev =3D subsys && (strcmp(subsys, "/sys/bus/mdev") =3D=3D 0); free(subsys); =20 @@ -3003,7 +3003,6 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) =20 ret =3D vfio_attach_device(name, vbasedev, pci_device_iommu_address_space(pdev), errp); - g_free(name); if (ret) { goto error; } --=20 2.34.1 From nobody Sat Feb 7 03:51:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; 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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1715064355; cv=none; d=zohomail.com; s=zohoarc; b=CkdLXoMlP9YS6+HswtB4vOmSzGNK5Yn14VcPzUW0KELB7eS9Fg3FJr7c5jt+ojgIrLkBwzjC+s8rYYXqyk7biULYJaJZGNeOtokmiO17v46nvv5eJ3/J99EDPOpsAtrbYga4TsjQcNlYLZ/TvvsCVZ+tY9FQLBPMjA0uGMGdg78= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715064355; h=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=2WyjsbaE4kvDCV702NRlnPJN+YEpcpmLkVCkgYrmsbw=; b=cv3tK5kf9Sio13hSJ0/o9zOaYm/7bYkAWiMSzW46hcFH3sBOzXgAL6NTpiYDfzhC4r0ddyZlPllBW8zyDwckLR1FQstN3gZRXahkTg0ASYmDVhOv2hQuy89Mt60zqBAKxJrnRVpiMHNcFk7xk7jr77+tqlfSznQhJEZwrF6z5lc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; 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 1715064355700667.5444386430048; Mon, 6 May 2024 23:45:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4EZp-00038s-8A; Tue, 07 May 2024 02:45:25 -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 1s4EZi-00036S-B4 for qemu-devel@nongnu.org; Tue, 07 May 2024 02:45:20 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4EZg-0005Ee-IH for qemu-devel@nongnu.org; Tue, 07 May 2024 02:45:17 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 23:45:15 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 23:45:13 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715064316; x=1746600316; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=m/kP6uLbI6sW/eoQnViDBe/hAuFiVrL6IoViZA7EnZI=; b=OBU+3Up/li8POf+/SdpLwwFVTHLL2nqqvjVBlOSfp3DNSFmujekhNYyl JAub5zhY2SlSYzoUBuPN6cLGljlei0NeoU2XYxLc+HMIDK+kVe8FNu3Tv k46fhxueLqSA/HVDTZtFG7BpdzRY5rQSwrHHqQJ9VPjY9pEh7XJysF8hZ inB28GvWSZZgEn66PmUTC6XdHbwgWwUsNM8m68EVXvDNY9YTVMn/kERzg 4dDcj8Jw7COirsM3CDMq0zCe6wwPs77CpE4QHaSQ8zdz8eAFVMAGSTQye c/3QS0+wcZrjGCklNFbdBJWWICHW52Gkqc58zFHgDsiCvVWt6Cm+p+ZX8 g==; X-CSE-ConnectionGUID: YoRV2eHtSyC42T2BmjGHsQ== X-CSE-MsgGUID: bQ7gJEKQQoCn53xk6xIbuw== X-IronPort-AV: E=McAfee;i="6600,9927,11065"; a="22240225" X-IronPort-AV: E=Sophos;i="6.07,260,1708416000"; d="scan'208";a="22240225" X-CSE-ConnectionGUID: A85EBLSHSg2Augsdg1I/8A== X-CSE-MsgGUID: mLwk8lxNSZiLWluvmTyuqA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,260,1708416000"; d="scan'208";a="28407510" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v2 02/11] vfio/pci: Use g_autofree in iommufd_cdev_get_info_iova_range() Date: Tue, 7 May 2024 14:42:43 +0800 Message-Id: <20240507064252.457884-3-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240507064252.457884-1-zhenzhong.duan@intel.com> References: <20240507064252.457884-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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 @intel.com) X-ZM-MESSAGEID: 1715064357512100007 Content-Type: text/plain; charset="utf-8" Local pointer info is freed before return from iommufd_cdev_get_info_iova_range(). Use 'g_autofree' to avoid the g_free() calls. Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater --- hw/vfio/iommufd.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 8827ffe636..c644127972 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -258,7 +258,7 @@ static int iommufd_cdev_get_info_iova_range(VFIOIOMMUFD= Container *container, uint32_t ioas_id, Error **errp) { VFIOContainerBase *bcontainer =3D &container->bcontainer; - struct iommu_ioas_iova_ranges *info; + g_autofree struct iommu_ioas_iova_ranges *info =3D NULL; struct iommu_iova_range *iova_ranges; int ret, sz, fd =3D container->be->fd; =20 @@ -291,12 +291,10 @@ static int iommufd_cdev_get_info_iova_range(VFIOIOMMU= FDContainer *container, } bcontainer->pgsizes =3D info->out_iova_alignment; =20 - g_free(info); return 0; =20 error: ret =3D -errno; - g_free(info); error_setg_errno(errp, errno, "Cannot get IOVA ranges"); return ret; } --=20 2.34.1 From nobody Sat Feb 7 03:51:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; 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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1715064377; cv=none; d=zohomail.com; s=zohoarc; b=OAQrPuIfsorQWFdqVeadMXnup+D3YShD42Sdv1qv2vSOSIbHdvWjZExFoJYL77jqBXMxBT5u/ghW9GjgOMaYV/2hlt5+ETwQ4tPHzLBbGAln+NCYgmZH7BjM9BaOm1OWSYefljEpU2tMhPIGB8yTzOe1IhUENRlBOBJJKcIFhBQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715064377; 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=cljZOeFNaYfLuBEnfepBxR9AUGmvySs3xlraPsqUJVQ=; b=cJ5wwBED9S14TU90arbYcyAIQFoHVzLExAE+C+H6gVaAsSJC6yuwxRMrdBZh3yIhIupG47RECyTWi9ezCNIe24d0p6OyYpDuibxArFlkYe9CR3hRyXHfnASfIRO5gfmQHvFnYSXJtTw6+63lrYMO1VvN9WGnRplkX0f3qF9kX/E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; 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 1715064377159659.5622107573718; Mon, 6 May 2024 23:46:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4EZr-0003Fs-5j; Tue, 07 May 2024 02:45:27 -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 1s4EZm-000383-J3; Tue, 07 May 2024 02:45:22 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4EZk-0005Ee-Fc; Tue, 07 May 2024 02:45:22 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 23:45:19 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 23:45:15 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715064320; x=1746600320; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5cQPtcKfaO9UpvWTYK5rExp5df6ULGsuIWA8AIyNnbE=; b=OF/D7SQBvy++j1kwjXkXy3TUE8uvGZFWAoqOZFQp92n6maXWrZ35uIx2 GqOVwucKXGrpeJGMYMEXA2CwGwqo7cPxrmZD3LyCtFIwFMfJ24iRc9Cgl l16PGqhY7FugZBWT72b1625GZUb9NezlJ5mnxayvbHj6pxyE367WJRNFI 5dHzLqRelqHOAjmY91OsmvWTkB2QsBwBsqCvRrXr9avcUXw46uBJjuRvm QwPdpOlKATFYWu//QgudHI09yERA+CQKlbmUf0tnPnXb39uHn+RNgr2rJ 9AzDb9uh1ULgRP1iDcFGi1+k3NWs+bfUJ63O85c8o4qZy/JN/EICc2rEh Q==; X-CSE-ConnectionGUID: 82wW0BC2Sz2auyVnj8ie3w== X-CSE-MsgGUID: EmOkPpIbTzS07twskU9/zg== X-IronPort-AV: E=McAfee;i="6600,9927,11065"; a="22240234" X-IronPort-AV: E=Sophos;i="6.07,260,1708416000"; d="scan'208";a="22240234" X-CSE-ConnectionGUID: l1jsHjvkTayT6KTDm3I47w== X-CSE-MsgGUID: izKXVY8ZQemlfRWWH1Dzbw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,260,1708416000"; d="scan'208";a="28407515" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, chao.p.peng@intel.com, Zhenzhong Duan , Tony Krowiak , Halil Pasic , Jason Herne , Thomas Huth , Eric Farman , Matthew Rosato , qemu-s390x@nongnu.org (open list:vfio-ap) Subject: [PATCH v2 03/11] vfio: Make VFIOIOMMUClass::attach_device() and its wrapper return bool Date: Tue, 7 May 2024 14:42:44 +0800 Message-Id: <20240507064252.457884-4-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240507064252.457884-1-zhenzhong.duan@intel.com> References: <20240507064252.457884-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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 @intel.com) X-ZM-MESSAGEID: 1715064377616100001 Make VFIOIOMMUClass::attach_device() and its wrapper function vfio_attach_device() return bool. This is to follow the coding standand to return bool if 'Error **' is used to pass error. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-common.h | 4 ++-- include/hw/vfio/vfio-container-base.h | 4 ++-- hw/vfio/ap.c | 6 ++---- hw/vfio/ccw.c | 6 ++---- hw/vfio/common.c | 4 ++-- hw/vfio/container.c | 14 +++++++------- hw/vfio/iommufd.c | 11 +++++------ hw/vfio/pci.c | 5 ++--- hw/vfio/platform.c | 7 +++---- 9 files changed, 27 insertions(+), 34 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index b9da6c08ef..a7b6fc8f46 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -198,8 +198,8 @@ void vfio_region_exit(VFIORegion *region); void vfio_region_finalize(VFIORegion *region); void vfio_reset_handler(void *opaque); struct vfio_device_info *vfio_get_device_info(int fd); -int vfio_attach_device(char *name, VFIODevice *vbasedev, - AddressSpace *as, Error **errp); +bool vfio_attach_device(char *name, VFIODevice *vbasedev, + AddressSpace *as, Error **errp); void vfio_detach_device(VFIODevice *vbasedev); =20 int vfio_kvm_device_add_fd(int fd, Error **errp); diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index 3582d5f97a..c839cfd9cb 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -118,8 +118,8 @@ struct VFIOIOMMUClass { int (*dma_unmap)(const VFIOContainerBase *bcontainer, hwaddr iova, ram_addr_t size, IOMMUTLBEntry *iotlb); - int (*attach_device)(const char *name, VFIODevice *vbasedev, - AddressSpace *as, Error **errp); + bool (*attach_device)(const char *name, VFIODevice *vbasedev, + AddressSpace *as, Error **errp); void (*detach_device)(VFIODevice *vbasedev); /* migration feature */ int (*set_dirty_page_tracking)(const VFIOContainerBase *bcontainer, diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c index 7c4caa5938..d50600b702 100644 --- a/hw/vfio/ap.c +++ b/hw/vfio/ap.c @@ -156,7 +156,6 @@ static void vfio_ap_unregister_irq_notifier(VFIOAPDevic= e *vapdev, static void vfio_ap_realize(DeviceState *dev, Error **errp) { ERRP_GUARD(); - int ret; Error *err =3D NULL; VFIOAPDevice *vapdev =3D VFIO_AP_DEVICE(dev); VFIODevice *vbasedev =3D &vapdev->vdev; @@ -165,9 +164,8 @@ static void vfio_ap_realize(DeviceState *dev, Error **e= rrp) return; } =20 - ret =3D vfio_attach_device(vbasedev->name, vbasedev, - &address_space_memory, errp); - if (ret) { + if (!vfio_attach_device(vbasedev->name, vbasedev, + &address_space_memory, errp)) { goto error; } =20 diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index 90e4a53437..782bd4bed7 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -580,7 +580,6 @@ static void vfio_ccw_realize(DeviceState *dev, Error **= errp) S390CCWDeviceClass *cdc =3D S390_CCW_DEVICE_GET_CLASS(cdev); VFIODevice *vbasedev =3D &vcdev->vdev; Error *err =3D NULL; - int ret; =20 /* Call the class init function for subchannel. */ if (cdc->realize) { @@ -594,9 +593,8 @@ static void vfio_ccw_realize(DeviceState *dev, Error **= errp) return; } =20 - ret =3D vfio_attach_device(cdev->mdevid, vbasedev, - &address_space_memory, errp); - if (ret) { + if (!vfio_attach_device(cdev->mdevid, vbasedev, + &address_space_memory, errp)) { goto out_attach_dev_err; } =20 diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 8f9cbdc026..890d30910e 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1492,8 +1492,8 @@ retry: return info; } =20 -int vfio_attach_device(char *name, VFIODevice *vbasedev, - AddressSpace *as, Error **errp) +bool vfio_attach_device(char *name, VFIODevice *vbasedev, + AddressSpace *as, Error **errp) { const VFIOIOMMUClass *ops =3D VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_LEGACY)); diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 77bdec276e..ea3b145913 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -908,8 +908,8 @@ static int vfio_device_groupid(VFIODevice *vbasedev, Er= ror **errp) * @name and @vbasedev->name are likely to be different depending * on the type of the device, hence the need for passing @name */ -static int vfio_legacy_attach_device(const char *name, VFIODevice *vbasede= v, - AddressSpace *as, Error **errp) +static bool vfio_legacy_attach_device(const char *name, VFIODevice *vbased= ev, + AddressSpace *as, Error **errp) { int groupid =3D vfio_device_groupid(vbasedev, errp); VFIODevice *vbasedev_iter; @@ -918,27 +918,27 @@ static int vfio_legacy_attach_device(const char *name= , VFIODevice *vbasedev, int ret; =20 if (groupid < 0) { - return groupid; + return false; } =20 trace_vfio_attach_device(vbasedev->name, groupid); =20 group =3D vfio_get_group(groupid, as, errp); if (!group) { - return -ENOENT; + return false; } =20 QLIST_FOREACH(vbasedev_iter, &group->device_list, next) { if (strcmp(vbasedev_iter->name, vbasedev->name) =3D=3D 0) { error_setg(errp, "device is already attached"); vfio_put_group(group); - return -EBUSY; + return false; } } ret =3D vfio_get_device(group, name, vbasedev, errp); if (ret) { vfio_put_group(group); - return ret; + return false; } =20 bcontainer =3D &group->container->bcontainer; @@ -946,7 +946,7 @@ static int vfio_legacy_attach_device(const char *name, = VFIODevice *vbasedev, QLIST_INSERT_HEAD(&bcontainer->device_list, vbasedev, container_next); QLIST_INSERT_HEAD(&vfio_device_list, vbasedev, global_next); =20 - return ret; + return true; } =20 static void vfio_legacy_detach_device(VFIODevice *vbasedev) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index c644127972..4c6992fca1 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -299,8 +299,8 @@ error: return ret; } =20 -static int iommufd_cdev_attach(const char *name, VFIODevice *vbasedev, - AddressSpace *as, Error **errp) +static bool iommufd_cdev_attach(const char *name, VFIODevice *vbasedev, + AddressSpace *as, Error **errp) { VFIOContainerBase *bcontainer; VFIOIOMMUFDContainer *container; @@ -315,7 +315,7 @@ static int iommufd_cdev_attach(const char *name, VFIODe= vice *vbasedev, if (vbasedev->fd < 0) { devfd =3D iommufd_cdev_getfd(vbasedev->sysfsdev, errp); if (devfd < 0) { - return devfd; + return false; } vbasedev->fd =3D devfd; } else { @@ -392,7 +392,6 @@ static int iommufd_cdev_attach(const char *name, VFIODe= vice *vbasedev, memory_listener_register(&bcontainer->listener, bcontainer->space->as); =20 if (bcontainer->error) { - ret =3D -1; error_propagate_prepend(errp, bcontainer->error, "memory listener initialization failed: "); goto err_listener_register; @@ -431,7 +430,7 @@ found_container: =20 trace_iommufd_cdev_device_info(vbasedev->name, devfd, vbasedev->num_ir= qs, vbasedev->num_regions, vbasedev->flags); - return 0; + return true; =20 err_listener_register: iommufd_cdev_ram_block_discard_disable(false); @@ -444,7 +443,7 @@ err_alloc_ioas: iommufd_cdev_unbind_and_disconnect(vbasedev); err_connect_bind: close(vbasedev->fd); - return ret; + return false; } =20 static void iommufd_cdev_detach(VFIODevice *vbasedev) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 576b21e2bb..d3beb15514 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3001,9 +3001,8 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) name =3D g_strdup(vbasedev->name); } =20 - ret =3D vfio_attach_device(name, vbasedev, - pci_device_iommu_address_space(pdev), errp); - if (ret) { + if (!vfio_attach_device(name, vbasedev, + pci_device_iommu_address_space(pdev), errp)) { goto error; } =20 diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index dcd2365fb3..2bd16096bb 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -552,10 +552,9 @@ static int vfio_base_device_init(VFIODevice *vbasedev,= Error **errp) return ret; } =20 - ret =3D vfio_attach_device(vbasedev->name, vbasedev, - &address_space_memory, errp); - if (ret) { - return ret; + if (!vfio_attach_device(vbasedev->name, vbasedev, + &address_space_memory, errp)) { + return -EINVAL; } =20 ret =3D vfio_populate_device(vbasedev, errp); --=20 2.34.1 From nobody Sat Feb 7 03:51:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; 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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1715064377; cv=none; d=zohomail.com; s=zohoarc; b=B/Ch1XvviCSlLz4zJDxUEsFlTeUEy2R8OlBbOEu71J/YqYygnSsZcw29zbN89MavJ3nsKwI1JOBqYvEoS85sHngdeuutnSCqRcxFHOUgB2muvmWs+0N0+g6DerW+NWhpKHWMxhR3gLtplrnsLsfIRxN68avvl7vuCazdHjcZm7s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715064377; 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=5pd6bWJihPXX25Sjt7Era8+PP2lkM+xcS6PRco4eBHM=; b=KVd2keaOxpSvYr24+5Mgvw5i77hqQoimuwWrV7rQvJNO18qx9x75WB8NCiLHljw33h4clk+2XLgHwXYDPnZnAeOcah6FB30V8T0evyz43C5hOULcTHApyipsyDhuEBBrmgc3nN23HuM87GjYQ2A05QE3apqYmgYTNxdxC6bGdKQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; 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 171506437734052.699416052045194; Mon, 6 May 2024 23:46:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4EZt-0003MR-FA; Tue, 07 May 2024 02:45:29 -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 1s4EZp-0003Ai-Nm; Tue, 07 May 2024 02:45:25 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4EZn-0005Ee-Q9; Tue, 07 May 2024 02:45:25 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 23:45:22 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 23:45:20 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715064323; x=1746600323; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rWCmMnV1q1IK9J8/rklP7DJaZKe+3/GfmS6fjHmvrBA=; b=JId9YO+/RPhknLbN823AyIwejXWl6x+E5C+laLOEMA2eeAuDrpihZpA2 r5WRdZcUnYy7RU/dC4vRV0dxKnAdnIMlO6OpBR3Z8tVP2dIsq0d1WXu0q zPml6da38RD0z4kaFvf7j45GUB1+FTFmk5Izz45P8Mw37eivdRXJypxwC J5Jk5xM25zgCVPtcUOYJ96XNVCYGeEOtCuN20SOW+2IIiVkbth7Pmv42q ldAvcaBrEioUxhF8y9zIayZxYJOp0aNikOfAsvjyk56+0E0Gpyt4p19uw j/j4LV99Zs76oeDbSJj7uIHtNa948qDyT+r5uj8740SfEkIpoIStIpVFQ w==; X-CSE-ConnectionGUID: J5tzOFWfRTyoSFEoVIrsMQ== X-CSE-MsgGUID: 5RLh7t2aQR2WqIPK9+CZfg== X-IronPort-AV: E=McAfee;i="6600,9927,11065"; a="22240241" X-IronPort-AV: E=Sophos;i="6.07,260,1708416000"; d="scan'208";a="22240241" X-CSE-ConnectionGUID: vqfwdyJnR8iKgsyowHcRHw== X-CSE-MsgGUID: yKzcCdkRQ6yK5DQh3X1Nyw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,260,1708416000"; d="scan'208";a="28407522" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, chao.p.peng@intel.com, Zhenzhong Duan , Nicholas Piggin , Daniel Henrique Barboza , David Gibson , Harsh Prateek Bora , qemu-ppc@nongnu.org (open list:sPAPR (pseries)) Subject: [PATCH v2 04/11] vfio: Make VFIOIOMMUClass::setup() return bool Date: Tue, 7 May 2024 14:42:45 +0800 Message-Id: <20240507064252.457884-5-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240507064252.457884-1-zhenzhong.duan@intel.com> References: <20240507064252.457884-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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 @intel.com) X-ZM-MESSAGEID: 1715064377671100003 This is to follow the coding standand to return bool if 'Error **' is used to pass error. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-container-base.h | 2 +- hw/vfio/container.c | 10 +++++----- hw/vfio/spapr.c | 12 +++++------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index c839cfd9cb..68539e3bed 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -111,7 +111,7 @@ struct VFIOIOMMUClass { InterfaceClass parent_class; =20 /* basic feature */ - int (*setup)(VFIOContainerBase *bcontainer, Error **errp); + bool (*setup)(VFIOContainerBase *bcontainer, Error **errp); int (*dma_map)(const VFIOContainerBase *bcontainer, hwaddr iova, ram_addr_t size, void *vaddr, bool readonly); diff --git a/hw/vfio/container.c b/hw/vfio/container.c index ea3b145913..85a8a369dc 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -505,7 +505,7 @@ static void vfio_get_iommu_info_migration(VFIOContainer= *container, } } =20 -static int vfio_legacy_setup(VFIOContainerBase *bcontainer, Error **errp) +static bool vfio_legacy_setup(VFIOContainerBase *bcontainer, Error **errp) { VFIOContainer *container =3D container_of(bcontainer, VFIOContainer, bcontainer); @@ -515,7 +515,7 @@ static int vfio_legacy_setup(VFIOContainerBase *bcontai= ner, Error **errp) ret =3D vfio_get_iommu_info(container, &info); if (ret) { error_setg_errno(errp, -ret, "Failed to get VFIO IOMMU info"); - return ret; + return false; } =20 if (info->flags & VFIO_IOMMU_INFO_PGSIZES) { @@ -531,7 +531,7 @@ static int vfio_legacy_setup(VFIOContainerBase *bcontai= ner, Error **errp) vfio_get_info_iova_range(info, bcontainer); =20 vfio_get_iommu_info_migration(container, info); - return 0; + return true; } =20 static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, @@ -633,8 +633,8 @@ static int vfio_connect_container(VFIOGroup *group, Add= ressSpace *as, =20 assert(bcontainer->ops->setup); =20 - ret =3D bcontainer->ops->setup(bcontainer, errp); - if (ret) { + if (!bcontainer->ops->setup(bcontainer, errp)) { + ret =3D -EINVAL; goto enable_discards_exit; } =20 diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c index 0d949bb728..148b257c9c 100644 --- a/hw/vfio/spapr.c +++ b/hw/vfio/spapr.c @@ -458,8 +458,8 @@ static void vfio_spapr_container_release(VFIOContainerB= ase *bcontainer) } } =20 -static int vfio_spapr_container_setup(VFIOContainerBase *bcontainer, - Error **errp) +static bool vfio_spapr_container_setup(VFIOContainerBase *bcontainer, + Error **errp) { VFIOContainer *container =3D container_of(bcontainer, VFIOContainer, bcontainer); @@ -480,7 +480,7 @@ static int vfio_spapr_container_setup(VFIOContainerBase= *bcontainer, ret =3D ioctl(fd, VFIO_IOMMU_ENABLE); if (ret) { error_setg_errno(errp, errno, "failed to enable container"); - return -errno; + return false; } } else { scontainer->prereg_listener =3D vfio_prereg_listener; @@ -488,7 +488,6 @@ static int vfio_spapr_container_setup(VFIOContainerBase= *bcontainer, memory_listener_register(&scontainer->prereg_listener, &address_space_memory); if (bcontainer->error) { - ret =3D -1; error_propagate_prepend(errp, bcontainer->error, "RAM memory listener initialization failed: "); goto listener_unregister_exit; @@ -500,7 +499,6 @@ static int vfio_spapr_container_setup(VFIOContainerBase= *bcontainer, if (ret) { error_setg_errno(errp, errno, "VFIO_IOMMU_SPAPR_TCE_GET_INFO failed"); - ret =3D -errno; goto listener_unregister_exit; } =20 @@ -527,13 +525,13 @@ static int vfio_spapr_container_setup(VFIOContainerBa= se *bcontainer, 0x1000); } =20 - return 0; + return true; =20 listener_unregister_exit: if (v2) { memory_listener_unregister(&scontainer->prereg_listener); } - return ret; + return false; } =20 static void vfio_iommu_spapr_class_init(ObjectClass *klass, void *data) --=20 2.34.1 From nobody Sat Feb 7 03:51:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; 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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1715064401; cv=none; d=zohomail.com; s=zohoarc; b=AxIDwZZ55tNmCkS+gCxFNjpac932D4mpZHip4GghdyF28PkQ+l2LJkoCQ4LYslfklIz4DMe2F5t5EOp6rDCao36ERVLFCx8+0bEGgd+Zv1fMWcmbIzKCqVdJfvAJZZ8o8OUWVolDAIVFmI1TmXkwDwaZh6yY6oLPlcoJaxS7RqY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715064401; 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=zk7l8RrmFbNj2vWYKvez2hpistvC0XU0HzBq9GCrxsg=; b=jWz4SlNunaOOahJGhfSVSSLsSt8NHDkmrDc4XriLeNUUkYQV5h8f1mZEHSYoEjUXw4zegXE77kZLowKN7Z+eWW1LeF+tHu03xZ52Jb1FlvXLabMF+aT0LG3vprvm6TLHhZ06JgfhZyWrbXlQ+pcT9/GWTkGC0PkHVcDXqwKC360= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; 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 1715064401632598.3333389746932; Mon, 6 May 2024 23:46:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4EZw-0003Nf-8x; Tue, 07 May 2024 02:45:32 -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 1s4EZt-0003MS-2q; Tue, 07 May 2024 02:45:29 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4EZr-0005Ee-1S; Tue, 07 May 2024 02:45:28 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 23:45:25 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 23:45:23 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715064327; x=1746600327; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Fr2V/QTY5Uvx5YftWpQRTt6S3xGiOTCE5jGwZtbQdsU=; b=fiidDAv9+HykJmFHcnfnh69OL21pG8JjPmYhZ8UmTiEavxCjKq4qOyPU JravKaMoaCFBmNZLI/lWoCbYP/drn1Hymnpoqc28tXm3v6nKchlA4R3EV QLxdVta7uCewkngzzEGxEFpOEQorYuyornpqOma3j6qlv7YnMeVYUuwkC EJTsY36e2nzKAaIQxulefDfaT4pFkLx32Py1q+uDje2WSRTiOktfvHX85 gsewzf+SBccZTK3vgeweO5pw9WOYUFMbVdki2BMpFoIsHvuvwnCcLnxxh zyBZMHs9P851EWwNjYxDk7nPNCakUixFh8PxDwYFovInf0n6S7NH5ozG5 w==; X-CSE-ConnectionGUID: 1bSqa3PaSXmWWyyHGpUb3g== X-CSE-MsgGUID: t7AG60xSQHeusECym9lPMg== X-IronPort-AV: E=McAfee;i="6600,9927,11065"; a="22240250" X-IronPort-AV: E=Sophos;i="6.07,260,1708416000"; d="scan'208";a="22240250" X-CSE-ConnectionGUID: IhIgOb1yRqumB+oXQPqczg== X-CSE-MsgGUID: 9S4wHYRaQpauabDbvHWNXg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,260,1708416000"; d="scan'208";a="28407526" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, chao.p.peng@intel.com, Zhenzhong Duan , Nicholas Piggin , Daniel Henrique Barboza , David Gibson , Harsh Prateek Bora , qemu-ppc@nongnu.org (open list:sPAPR (pseries)) Subject: [PATCH v2 05/11] vfio: Make VFIOIOMMUClass::add_window() and its wrapper return bool Date: Tue, 7 May 2024 14:42:46 +0800 Message-Id: <20240507064252.457884-6-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240507064252.457884-1-zhenzhong.duan@intel.com> References: <20240507064252.457884-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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 @intel.com) X-ZM-MESSAGEID: 1715064403757100003 Make VFIOIOMMUClass::add_window() and its wrapper function vfio_container_add_section_window() return bool. This is to follow the coding standand to return bool if 'Error **' is used to pass error. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-container-base.h | 12 ++++++------ hw/vfio/common.c | 2 +- hw/vfio/container-base.c | 8 ++++---- hw/vfio/spapr.c | 16 ++++++++-------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index 68539e3bed..e96cda78c8 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -76,9 +76,9 @@ int vfio_container_dma_map(VFIOContainerBase *bcontainer, int vfio_container_dma_unmap(VFIOContainerBase *bcontainer, hwaddr iova, ram_addr_t size, IOMMUTLBEntry *iotlb); -int vfio_container_add_section_window(VFIOContainerBase *bcontainer, - MemoryRegionSection *section, - Error **errp); +bool vfio_container_add_section_window(VFIOContainerBase *bcontainer, + MemoryRegionSection *section, + Error **errp); void vfio_container_del_section_window(VFIOContainerBase *bcontainer, MemoryRegionSection *section); int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, @@ -131,9 +131,9 @@ struct VFIOIOMMUClass { int (*pci_hot_reset)(VFIODevice *vbasedev, bool single); =20 /* SPAPR specific */ - int (*add_window)(VFIOContainerBase *bcontainer, - MemoryRegionSection *section, - Error **errp); + bool (*add_window)(VFIOContainerBase *bcontainer, + MemoryRegionSection *section, + Error **errp); void (*del_window)(VFIOContainerBase *bcontainer, MemoryRegionSection *section); void (*release)(VFIOContainerBase *bcontainer); diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 890d30910e..9f1f2e19f7 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -585,7 +585,7 @@ static void vfio_listener_region_add(MemoryListener *li= stener, return; } =20 - if (vfio_container_add_section_window(bcontainer, section, &err)) { + if (!vfio_container_add_section_window(bcontainer, section, &err)) { goto fail; } =20 diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c index 913ae49077..98d71b3144 100644 --- a/hw/vfio/container-base.c +++ b/hw/vfio/container-base.c @@ -31,12 +31,12 @@ int vfio_container_dma_unmap(VFIOContainerBase *bcontai= ner, return bcontainer->ops->dma_unmap(bcontainer, iova, size, iotlb); } =20 -int vfio_container_add_section_window(VFIOContainerBase *bcontainer, - MemoryRegionSection *section, - Error **errp) +bool vfio_container_add_section_window(VFIOContainerBase *bcontainer, + MemoryRegionSection *section, + Error **errp) { if (!bcontainer->ops->add_window) { - return 0; + return true; } =20 return bcontainer->ops->add_window(bcontainer, section, errp); diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c index 148b257c9c..47b040f1bc 100644 --- a/hw/vfio/spapr.c +++ b/hw/vfio/spapr.c @@ -323,7 +323,7 @@ static int vfio_spapr_create_window(VFIOContainer *cont= ainer, return 0; } =20 -static int +static bool vfio_spapr_container_add_section_window(VFIOContainerBase *bcontainer, MemoryRegionSection *section, Error **errp) @@ -351,13 +351,13 @@ vfio_spapr_container_add_section_window(VFIOContainer= Base *bcontainer, error_setg(errp, "Container %p can't map guest IOVA region" " 0x%"HWADDR_PRIx"..0x%"HWADDR_PRIx, container, iova, end); - return -EINVAL; + return false; } - return 0; + return true; } =20 if (container->iommu_type !=3D VFIO_SPAPR_TCE_v2_IOMMU) { - return 0; + return true; } =20 /* For now intersections are not allowed, we may relax this later */ @@ -373,14 +373,14 @@ vfio_spapr_container_add_section_window(VFIOContainer= Base *bcontainer, section->offset_within_address_space + int128_get64(section->size) - 1, hostwin->min_iova, hostwin->max_iova); - return -EINVAL; + return false; } } =20 ret =3D vfio_spapr_create_window(container, section, &pgsize); if (ret) { error_setg_errno(errp, -ret, "Failed to create SPAPR window"); - return ret; + return false; } =20 vfio_host_win_add(scontainer, section->offset_within_address_space, @@ -406,14 +406,14 @@ vfio_spapr_container_add_section_window(VFIOContainer= Base *bcontainer, "vfio: failed GROUP_SET_SPAPR_TCE for= " "KVM VFIO device %d and group fd %d", param.tablefd, param.groupfd); - return -errno; + return false; } trace_vfio_spapr_group_attach(param.groupfd, param.tablefd= ); } } } #endif - return 0; + return true; } =20 static void --=20 2.34.1 From nobody Sat Feb 7 03:51:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; 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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1715064415; cv=none; d=zohomail.com; s=zohoarc; b=gcNCd6h6XV3wKZiJpvA2kql7qB0CdLAKz6Jarm/WIFpGCbA6DHAo26vBJ+EId1x4aEhTEcT02NqEe37ryQZVqwO7YzpX9R2+qA6zV9Eox3DW/3eKjU4+/P4kRZJNIFg9wqYQ+hOENUJzdfj1BWsZYpLeDHfYoHyv48T8AtP5mxw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715064415; 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=y4CgFU2S2jef858VXXBmbEyyEdEqnus7SRS+Beh3e8k=; b=hJjzsjMGv5jBgw8WSZJtnu/AjlSsc5FS4vumLEgQNqBPz6vyq/vqPL5khytudcPy5BpR9koS14OiEtvSgBFxMrny/7/CVdVl5ZvXd4xCDsK9ByAlZU0BgmvxNh9VDpL6t+meFWImJ8jCf2Ykb9BK8TywkxEHcU1qdXuk5dzwkDM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; 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 1715064415008735.7305723821133; Mon, 6 May 2024 23:46:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4EZx-0003Nr-HD; Tue, 07 May 2024 02:45:33 -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 1s4EZv-0003N0-2I for qemu-devel@nongnu.org; Tue, 07 May 2024 02:45:31 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4EZt-0005qh-B4 for qemu-devel@nongnu.org; Tue, 07 May 2024 02:45:30 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 23:45:27 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 23:45:26 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715064329; x=1746600329; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gUo9UnxPu2YspFGKVJBIbNBdn4MV8we3p89WumCBSx0=; b=bKLdJzvgk6IP/mOk3XG2vIMrniri4AmCAQsvBnnp2mNeaiJNYfEdg/vZ TWnCiCDQr1oU/xg8whD0OcavmkETS5AVDlal90StSXi+0ki1yxZWbiYjq JaNsGuYkut7pgJLUScl9WSZy3znn5KeiSEKWV4a2DlcJsBnVzRf7xM7FR cmeSGICbQxjr/KHhnbKW9E6GEgRttfsKUokPR94U38w05wmEW0SDM7eFB 6ogpH3c8SLPVpikXZh+010G4f2DRZONpzNz+I6APN/VVpXycIsqBzSxyD ZRlhksVqorTePCHP9FnvZl2g6wI/bM8Ss2QRhXwU9cN3pxhU4oGVr2T+7 g==; X-CSE-ConnectionGUID: hL/w8o9PQ+KlRyU2DSb9qg== X-CSE-MsgGUID: OYjOV0DhQmS7dGgC1/FfDA== X-IronPort-AV: E=McAfee;i="6600,9927,11065"; a="22240256" X-IronPort-AV: E=Sophos;i="6.07,260,1708416000"; d="scan'208";a="22240256" X-CSE-ConnectionGUID: waK3lt3FRuur++r3cRc0sA== X-CSE-MsgGUID: TspUgYM+RYeh0SuUNOnFCw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,260,1708416000"; d="scan'208";a="28407529" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v2 06/11] vfio/container: Make vfio_connect_container() return bool Date: Tue, 7 May 2024 14:42:47 +0800 Message-Id: <20240507064252.457884-7-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240507064252.457884-1-zhenzhong.duan@intel.com> References: <20240507064252.457884-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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 @intel.com) X-ZM-MESSAGEID: 1715064415712100001 This is to follow the coding standand to return bool if 'Error **' is used to pass error. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater --- hw/vfio/container.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 85a8a369dc..0a7edfcc43 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -534,8 +534,8 @@ static bool vfio_legacy_setup(VFIOContainerBase *bconta= iner, Error **errp) return true; } =20 -static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, - Error **errp) +static bool vfio_connect_container(VFIOGroup *group, AddressSpace *as, + Error **errp) { VFIOContainer *container; VFIOContainerBase *bcontainer; @@ -587,19 +587,18 @@ static int vfio_connect_container(VFIOGroup *group, A= ddressSpace *as, error_report("vfio: error disconnecting group %d from" " container", group->groupid); } - return ret; + return false; } group->container =3D container; QLIST_INSERT_HEAD(&container->group_list, group, container_nex= t); vfio_kvm_device_add_group(group); - return 0; + return true; } } =20 fd =3D qemu_open_old("/dev/vfio/vfio", O_RDWR); if (fd < 0) { error_setg_errno(errp, errno, "failed to open /dev/vfio/vfio"); - ret =3D -errno; goto put_space_exit; } =20 @@ -607,7 +606,6 @@ static int vfio_connect_container(VFIOGroup *group, Add= ressSpace *as, if (ret !=3D VFIO_API_VERSION) { error_setg(errp, "supported vfio version: %d, " "reported version: %d", VFIO_API_VERSION, ret); - ret =3D -EINVAL; goto close_fd_exit; } =20 @@ -634,7 +632,6 @@ static int vfio_connect_container(VFIOGroup *group, Add= ressSpace *as, assert(bcontainer->ops->setup); =20 if (!bcontainer->ops->setup(bcontainer, errp)) { - ret =3D -EINVAL; goto enable_discards_exit; } =20 @@ -650,7 +647,6 @@ static int vfio_connect_container(VFIOGroup *group, Add= ressSpace *as, memory_listener_register(&bcontainer->listener, bcontainer->space->as); =20 if (bcontainer->error) { - ret =3D -1; error_propagate_prepend(errp, bcontainer->error, "memory listener initialization failed: "); goto listener_release_exit; @@ -658,7 +654,7 @@ static int vfio_connect_container(VFIOGroup *group, Add= ressSpace *as, =20 bcontainer->initialized =3D true; =20 - return 0; + return true; listener_release_exit: QLIST_REMOVE(group, container_next); QLIST_REMOVE(bcontainer, next); @@ -683,7 +679,7 @@ close_fd_exit: put_space_exit: vfio_put_address_space(space); =20 - return ret; + return false; } =20 static void vfio_disconnect_container(VFIOGroup *group) @@ -770,7 +766,7 @@ static VFIOGroup *vfio_get_group(int groupid, AddressSp= ace *as, Error **errp) group->groupid =3D groupid; QLIST_INIT(&group->device_list); =20 - if (vfio_connect_container(group, as, errp)) { + if (!vfio_connect_container(group, as, errp)) { error_prepend(errp, "failed to setup container for group %d: ", groupid); goto close_fd_exit; --=20 2.34.1 From nobody Sat Feb 7 03:51:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; 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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1715064422; cv=none; d=zohomail.com; s=zohoarc; b=j94MV8p22pi1OI9d4EP6noYnzzwg/16qmEhb9gE4OH5irwiA1LyxS53C8GCSPODX92YP+/IVwDEjA6Z1mPHPga2xbrcmrvUoDsNz9eMnzRW5U/ZnQN684f1cr3eJLTccZGDjstrVEwMcEp+kO1WUalWrXpG2sJr1fRLUlIPjpGY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715064422; 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=h2TrbUSgSz8hc483vUT2klMhITPwhk0xtCubT7IcFZk=; b=FlS38G5sjYMjxh3Onqen7+OyzBUaMPyAvTfjp2UMlKB3mzNsa/ox0M05WL9mJA23S3h2oFcYfgMgx+qVY6HFSFB4HpgMsH9NQ8mEaRgggXKNFT0CNmTuEPaiPTl62LR/DQqXrx4dt5dXxC21XDyahkOumIJXuuKC+sTTG8QM/eg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; 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 1715064422713979.7657068382136; Mon, 6 May 2024 23:47:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4EZy-0003OH-CJ; Tue, 07 May 2024 02:45:34 -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 1s4EZw-0003Nh-Ef for qemu-devel@nongnu.org; Tue, 07 May 2024 02:45:32 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4EZu-0005Ee-Lm for qemu-devel@nongnu.org; Tue, 07 May 2024 02:45:32 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 23:45:30 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 23:45:28 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715064330; x=1746600330; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8uhN4/mEpj2+F2/bXHdbPWxUB6o5pfA6i0tofvxnefU=; b=aBqM0PG9xt44gdUI7/e0CRdegEzPiJQ4kGcntA2zs1rpJ76/i7x4GzXd 9UHzYOV4PA7nSfsEfHmwwNVT1a9SBQzPbKfbCaX4vqLveKdXbdyxacGG6 KM3dtkH6T0ViQjMr7XpD+4Fcq7drhq5co2vwp3n8NZTKc5lTwgLTCcx8w eH+QUK2xQzTDUJn/nMO9hCISseE6KyjRVUqHPuItqLd1bHOcqIMLPfDN2 y2PiNLd6g4ItBV7n0x8ouNh9QhmxWJGWIjtngdMZ401gAuSMobXxlaRHA 24YcRtnD7z66PCY63aveCxvKAaFxt/HTBkriHw2NcrxolHuK+m6DtDHzj A==; X-CSE-ConnectionGUID: bfWfwt8xTyK3LInTwFZ4yQ== X-CSE-MsgGUID: zBew0Vk0QdSHyaV/xGc8kg== X-IronPort-AV: E=McAfee;i="6600,9927,11065"; a="22240259" X-IronPort-AV: E=Sophos;i="6.07,260,1708416000"; d="scan'208";a="22240259" X-CSE-ConnectionGUID: AKKcguHGSL6vB/sonc2ziQ== X-CSE-MsgGUID: ng4yOO1iQeWpJWlJnFZ+pg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,260,1708416000"; d="scan'208";a="28407534" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v2 07/11] vfio/container: Make vfio_set_iommu() return bool Date: Tue, 7 May 2024 14:42:48 +0800 Message-Id: <20240507064252.457884-8-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240507064252.457884-1-zhenzhong.duan@intel.com> References: <20240507064252.457884-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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 @intel.com) X-ZM-MESSAGEID: 1715064423745100001 This is to follow the coding standand to return bool if 'Error **' is used to pass error. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater --- hw/vfio/container.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 0a7edfcc43..5fb4bee082 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -391,21 +391,20 @@ static const VFIOIOMMUClass *vfio_get_iommu_class(int= iommu_type, Error **errp) return VFIO_IOMMU_CLASS(klass); } =20 -static int vfio_set_iommu(VFIOContainer *container, int group_fd, - VFIOAddressSpace *space, Error **errp) +static bool vfio_set_iommu(VFIOContainer *container, int group_fd, + VFIOAddressSpace *space, Error **errp) { - int iommu_type, ret; + int iommu_type; const VFIOIOMMUClass *vioc; =20 iommu_type =3D vfio_get_iommu_type(container, errp); if (iommu_type < 0) { - return iommu_type; + return false; } =20 - ret =3D ioctl(group_fd, VFIO_GROUP_SET_CONTAINER, &container->fd); - if (ret) { + if (ioctl(group_fd, VFIO_GROUP_SET_CONTAINER, &container->fd)) { error_setg_errno(errp, errno, "Failed to set group container"); - return -errno; + return false; } =20 while (ioctl(container->fd, VFIO_SET_IOMMU, iommu_type)) { @@ -420,7 +419,7 @@ static int vfio_set_iommu(VFIOContainer *container, int= group_fd, continue; } error_setg_errno(errp, errno, "Failed to set iommu for container"); - return -errno; + return false; } =20 container->iommu_type =3D iommu_type; @@ -428,11 +427,11 @@ static int vfio_set_iommu(VFIOContainer *container, i= nt group_fd, vioc =3D vfio_get_iommu_class(iommu_type, errp); if (!vioc) { error_setg(errp, "No available IOMMU models"); - return -EINVAL; + return false; } =20 vfio_container_init(&container->bcontainer, space, vioc); - return 0; + return true; } =20 static int vfio_get_iommu_info(VFIOContainer *container, @@ -613,8 +612,7 @@ static bool vfio_connect_container(VFIOGroup *group, Ad= dressSpace *as, container->fd =3D fd; bcontainer =3D &container->bcontainer; =20 - ret =3D vfio_set_iommu(container, group->fd, space, errp); - if (ret) { + if (!vfio_set_iommu(container, group->fd, space, errp)) { goto free_container_exit; } =20 --=20 2.34.1 From nobody Sat Feb 7 03:51:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; 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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1715064354; cv=none; d=zohomail.com; s=zohoarc; b=jWv9qjiSJvwmIn2cUalQpQXr4AUTl3vEwWaSxZm4KVvHrVP35JKBbx0xmBE7q7H2pwlovmCQr+bGaM1nbLdmFNe58CzbWgb88NNtFLgYALa/RlAYHF/V37NAV/YBhW+F2FtbKpV+HRCtDL16seFxfxVI0Lmg0kmoGXUUBeqblgk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715064354; 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=48G6obPeTfYl8NUX+fnuhNq+PqzquMsjlprUPc3ZMr4=; b=MJP4p/zPkvlDRpfUMOR4SpJ/0NyGReSlJSE9RBoqajKHWWbv2GBjVemUiey+ngoeOSKxL/ou10CN8zxm0Lo+0J9YGERJo095b80dCOHEmZ9YqaRfIC5EvYvKdqKdaSkWh5h8rh3vcIcLhNLSULwdBIahMxGYSjmgzdKWUfdhf7c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; 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 1715064354505931.6362371647436; Mon, 6 May 2024 23:45:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4Ea0-0003PF-QI; Tue, 07 May 2024 02:45:36 -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 1s4EZz-0003OX-5k for qemu-devel@nongnu.org; Tue, 07 May 2024 02:45:35 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4EZx-00064G-FY for qemu-devel@nongnu.org; Tue, 07 May 2024 02:45:34 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 23:45:32 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 23:45:30 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715064333; x=1746600333; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cYvBAeX/uBwyCnQDxeXOBKmDJDyEp69Jn47l2XHzo/0=; b=hTrG+I/ALZnlV7aTs2/MoWQWCm2Vy0y2yZMgYC4P67Se8DYhtfKXg9Je qgz2ZjwXpj7zclE7KdVAiLOZkcB1MCdvObnIq//bOg4stOVfrRfbGZtSS 3kHNqOgOt+vFAQh3M/KiffqW8LQna5w8/bA5o58rmXLZmvvMj92JwFCuG tDogifSfNnRR8EK10vAQA+Ij8PEJ5d4oNiUNHWs1dUu9GEa2FnIioGHJu Va/tC4iG2AX0wYkQ3d91ikzISVgXdwVX4MXTh985vMSQsDloBXXL0ajA5 L/eKQ/B8oUOgZ2uymcH/ExaTrMTGybojW9Dt/Pv9JiGwUQPtFtoN0nCJr w==; X-CSE-ConnectionGUID: CyfBaMmhTcSK3PJpgo6ORw== X-CSE-MsgGUID: /nOCcclNSregmn+74jGXtg== X-IronPort-AV: E=McAfee;i="6600,9927,11065"; a="22240266" X-IronPort-AV: E=Sophos;i="6.07,260,1708416000"; d="scan'208";a="22240266" X-CSE-ConnectionGUID: P06yk2QcTaSkJVA5GRJyUw== X-CSE-MsgGUID: 6/APm0E3QyuAxnh29+dGqA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,260,1708416000"; d="scan'208";a="28407538" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v2 08/11] vfio/container: Make vfio_get_device() return bool Date: Tue, 7 May 2024 14:42:49 +0800 Message-Id: <20240507064252.457884-9-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240507064252.457884-1-zhenzhong.duan@intel.com> References: <20240507064252.457884-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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 @intel.com) X-ZM-MESSAGEID: 1715064355566100001 This is to follow the coding standand to return bool if 'Error **' is used to pass error. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater --- hw/vfio/container.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 5fb4bee082..b02583ea16 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -800,8 +800,8 @@ static void vfio_put_group(VFIOGroup *group) g_free(group); } =20 -static int vfio_get_device(VFIOGroup *group, const char *name, - VFIODevice *vbasedev, Error **errp) +static bool vfio_get_device(VFIOGroup *group, const char *name, + VFIODevice *vbasedev, Error **errp) { g_autofree struct vfio_device_info *info =3D NULL; int fd; @@ -813,14 +813,14 @@ static int vfio_get_device(VFIOGroup *group, const ch= ar *name, error_append_hint(errp, "Verify all devices in group %d are bound to vfio- " "or pci-stub and not already in use\n", group->group= id); - return fd; + return false; } =20 info =3D vfio_get_device_info(fd); if (!info) { error_setg_errno(errp, errno, "error getting device info"); close(fd); - return -1; + return false; } =20 /* @@ -835,7 +835,7 @@ static int vfio_get_device(VFIOGroup *group, const char= *name, error_setg(errp, "Inconsistent setting of support for discardi= ng " "RAM (e.g., balloon) within group"); close(fd); - return -1; + return false; } =20 if (!group->ram_block_discard_allowed) { @@ -856,7 +856,7 @@ static int vfio_get_device(VFIOGroup *group, const char= *name, =20 vbasedev->reset_works =3D !!(info->flags & VFIO_DEVICE_FLAGS_RESET); =20 - return 0; + return true; } =20 static void vfio_put_base_device(VFIODevice *vbasedev) @@ -909,7 +909,6 @@ static bool vfio_legacy_attach_device(const char *name,= VFIODevice *vbasedev, VFIODevice *vbasedev_iter; VFIOGroup *group; VFIOContainerBase *bcontainer; - int ret; =20 if (groupid < 0) { return false; @@ -929,8 +928,7 @@ static bool vfio_legacy_attach_device(const char *name,= VFIODevice *vbasedev, return false; } } - ret =3D vfio_get_device(group, name, vbasedev, errp); - if (ret) { + if (!vfio_get_device(group, name, vbasedev, errp)) { vfio_put_group(group); return false; } --=20 2.34.1 From nobody Sat Feb 7 03:51:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; 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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1715064405; cv=none; d=zohomail.com; s=zohoarc; b=GFf4ad7iOYa7KnFHSiuFb6R8pC1KOX6AeUv6FZfe0Ogk4MC+9dlYnWeeIT/438WXPOYVi8It80L60iCsaxcNd6BxRM1Ttc5VEtMtrpBb5tivtr9BAMGHUR/lw/c3UsFTiIUrlcpG9/QjlpA59ntP96K65rsthOz3KUn55lBQRlA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715064405; 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=SbKqdxXS/0N8JWYnvdYc+3AVsawUlCW+IbDteHvObJg=; b=Ws+cXOn0mtsamozCilqzA0y+nlbdXHidbmw6GBvqvOYcsN1CvOSp7m5DyZfAsdw1nq4YOP3/8QREzX08p+CDsKE7QzStv7FAlTWGT42vLPf565isRE0uvcwiH63uDQXIQaMGsgTOlIF/uA5LSvTRXZpzan9hJO8znkTz8nVRPWc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; 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 17150644054671014.6662913461475; Mon, 6 May 2024 23:46:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4EaU-00046O-Sd; Tue, 07 May 2024 02:46:06 -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 1s4Ea3-0003Pc-27 for qemu-devel@nongnu.org; Tue, 07 May 2024 02:45:42 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4Ea0-00064P-39 for qemu-devel@nongnu.org; Tue, 07 May 2024 02:45:38 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 23:45:34 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 23:45:32 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715064336; x=1746600336; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YuEjad/QSOPspcVfj2yLb1aBm53LwZcTA/VVfm+isMg=; b=BNFGvSLwJqvEFatzYUPccETOg84ZOsUfBc+24oasP5m0EUZ+TnRFBjvS 10vazDpaHH07yxqHC3MzC9j0mbyLcVqI8XLDnxOjAXcMA4NKDrIcrvIQt XCPLDpXP5oCt4DnqOki2AyQ8eImAesmWlbkn6h6co572nrtRGuYZ045GO kb9nsdEFQIUcvxk+v/9lmYX0S2rdzzfDfHQafWh19bDGQvTE4FX6UOLmB ZuLmuZkLzpu1KQ2AB6nglo7XdroxzbGWnvCa8Kn5M7iN6vX5x5X/YPs+1 A4KBGUq3ztaHIk0wI7KNFFEqjZmSF1Su72RucwC7HgrX4uTrCcO4wdvKC A==; X-CSE-ConnectionGUID: fOlNLZgVSCqndYruf66xjg== X-CSE-MsgGUID: 1JtEDd0uQka9ijDCCXG6MQ== X-IronPort-AV: E=McAfee;i="6600,9927,11065"; a="22240270" X-IronPort-AV: E=Sophos;i="6.07,260,1708416000"; d="scan'208";a="22240270" X-CSE-ConnectionGUID: /mUK/NehTcmHpqs7zRtX4Q== X-CSE-MsgGUID: W0bmYEPuQNKQD4U7kMa9yQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,260,1708416000"; d="scan'208";a="28407542" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v2 09/11] vfio/iommufd: Make iommufd_cdev_*() return bool Date: Tue, 7 May 2024 14:42:50 +0800 Message-Id: <20240507064252.457884-10-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240507064252.457884-1-zhenzhong.duan@intel.com> References: <20240507064252.457884-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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 @intel.com) X-ZM-MESSAGEID: 1715064405797100005 This is to follow the coding standand to return bool if 'Error **' is used to pass error. The changed functions include: iommufd_cdev_kvm_device_add iommufd_cdev_connect_and_bind iommufd_cdev_attach_ioas_hwpt iommufd_cdev_detach_ioas_hwpt iommufd_cdev_attach_container iommufd_cdev_get_info_iova_range After the change, all functions in hw/vfio/iommufd.c follows the standand. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater --- hw/vfio/iommufd.c | 88 +++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 49 deletions(-) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 4c6992fca1..84c86b970e 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -49,9 +49,9 @@ static int iommufd_cdev_unmap(const VFIOContainerBase *bc= ontainer, container->ioas_id, iova, size); } =20 -static int iommufd_cdev_kvm_device_add(VFIODevice *vbasedev, Error **errp) +static bool iommufd_cdev_kvm_device_add(VFIODevice *vbasedev, Error **errp) { - return vfio_kvm_device_add_fd(vbasedev->fd, errp); + return !vfio_kvm_device_add_fd(vbasedev->fd, errp); } =20 static void iommufd_cdev_kvm_device_del(VFIODevice *vbasedev) @@ -63,18 +63,16 @@ static void iommufd_cdev_kvm_device_del(VFIODevice *vba= sedev) } } =20 -static int iommufd_cdev_connect_and_bind(VFIODevice *vbasedev, Error **err= p) +static bool iommufd_cdev_connect_and_bind(VFIODevice *vbasedev, Error **er= rp) { IOMMUFDBackend *iommufd =3D vbasedev->iommufd; struct vfio_device_bind_iommufd bind =3D { .argsz =3D sizeof(bind), .flags =3D 0, }; - int ret; =20 - ret =3D iommufd_backend_connect(iommufd, errp); - if (ret) { - return ret; + if (iommufd_backend_connect(iommufd, errp)) { + return false; } =20 /* @@ -82,15 +80,13 @@ static int iommufd_cdev_connect_and_bind(VFIODevice *vb= asedev, Error **errp) * in KVM. Especially for some emulated devices, it requires * to have kvm information in the device open. */ - ret =3D iommufd_cdev_kvm_device_add(vbasedev, errp); - if (ret) { + if (!iommufd_cdev_kvm_device_add(vbasedev, errp)) { goto err_kvm_device_add; } =20 /* Bind device to iommufd */ bind.iommufd =3D iommufd->fd; - ret =3D ioctl(vbasedev->fd, VFIO_DEVICE_BIND_IOMMUFD, &bind); - if (ret) { + if (ioctl(vbasedev->fd, VFIO_DEVICE_BIND_IOMMUFD, &bind)) { error_setg_errno(errp, errno, "error bind device fd=3D%d to iommuf= d=3D%d", vbasedev->fd, bind.iommufd); goto err_bind; @@ -99,12 +95,12 @@ static int iommufd_cdev_connect_and_bind(VFIODevice *vb= asedev, Error **errp) vbasedev->devid =3D bind.out_devid; trace_iommufd_cdev_connect_and_bind(bind.iommufd, vbasedev->name, vbasedev->fd, vbasedev->devid); - return ret; + return true; err_bind: iommufd_cdev_kvm_device_del(vbasedev); err_kvm_device_add: iommufd_backend_disconnect(iommufd); - return ret; + return false; } =20 static void iommufd_cdev_unbind_and_disconnect(VFIODevice *vbasedev) @@ -176,10 +172,10 @@ out: return ret; } =20 -static int iommufd_cdev_attach_ioas_hwpt(VFIODevice *vbasedev, uint32_t id, +static bool iommufd_cdev_attach_ioas_hwpt(VFIODevice *vbasedev, uint32_t i= d, Error **errp) { - int ret, iommufd =3D vbasedev->iommufd->fd; + int iommufd =3D vbasedev->iommufd->fd; struct vfio_device_attach_iommufd_pt attach_data =3D { .argsz =3D sizeof(attach_data), .flags =3D 0, @@ -187,38 +183,38 @@ static int iommufd_cdev_attach_ioas_hwpt(VFIODevice *= vbasedev, uint32_t id, }; =20 /* Attach device to an IOAS or hwpt within iommufd */ - ret =3D ioctl(vbasedev->fd, VFIO_DEVICE_ATTACH_IOMMUFD_PT, &attach_dat= a); - if (ret) { + if (ioctl(vbasedev->fd, VFIO_DEVICE_ATTACH_IOMMUFD_PT, &attach_data)) { error_setg_errno(errp, errno, "[iommufd=3D%d] error attach %s (%d) to id=3D%d", iommufd, vbasedev->name, vbasedev->fd, id); - } else { - trace_iommufd_cdev_attach_ioas_hwpt(iommufd, vbasedev->name, - vbasedev->fd, id); + return false; } - return ret; + + trace_iommufd_cdev_attach_ioas_hwpt(iommufd, vbasedev->name, + vbasedev->fd, id); + return true; } =20 -static int iommufd_cdev_detach_ioas_hwpt(VFIODevice *vbasedev, Error **err= p) +static bool iommufd_cdev_detach_ioas_hwpt(VFIODevice *vbasedev, Error **er= rp) { - int ret, iommufd =3D vbasedev->iommufd->fd; + int iommufd =3D vbasedev->iommufd->fd; struct vfio_device_detach_iommufd_pt detach_data =3D { .argsz =3D sizeof(detach_data), .flags =3D 0, }; =20 - ret =3D ioctl(vbasedev->fd, VFIO_DEVICE_DETACH_IOMMUFD_PT, &detach_dat= a); - if (ret) { + if (ioctl(vbasedev->fd, VFIO_DEVICE_DETACH_IOMMUFD_PT, &detach_data)) { error_setg_errno(errp, errno, "detach %s failed", vbasedev->name); - } else { - trace_iommufd_cdev_detach_ioas_hwpt(iommufd, vbasedev->name); + return false; } - return ret; + + trace_iommufd_cdev_detach_ioas_hwpt(iommufd, vbasedev->name); + return true; } =20 -static int iommufd_cdev_attach_container(VFIODevice *vbasedev, - VFIOIOMMUFDContainer *container, - Error **errp) +static bool iommufd_cdev_attach_container(VFIODevice *vbasedev, + VFIOIOMMUFDContainer *container, + Error **errp) { return iommufd_cdev_attach_ioas_hwpt(vbasedev, container->ioas_id, err= p); } @@ -228,7 +224,7 @@ static void iommufd_cdev_detach_container(VFIODevice *v= basedev, { Error *err =3D NULL; =20 - if (iommufd_cdev_detach_ioas_hwpt(vbasedev, &err)) { + if (!iommufd_cdev_detach_ioas_hwpt(vbasedev, &err)) { error_report_err(err); } } @@ -254,20 +250,19 @@ static int iommufd_cdev_ram_block_discard_disable(boo= l state) return ram_block_uncoordinated_discard_disable(state); } =20 -static int iommufd_cdev_get_info_iova_range(VFIOIOMMUFDContainer *containe= r, - uint32_t ioas_id, Error **errp) +static bool iommufd_cdev_get_info_iova_range(VFIOIOMMUFDContainer *contain= er, + uint32_t ioas_id, Error **err= p) { VFIOContainerBase *bcontainer =3D &container->bcontainer; g_autofree struct iommu_ioas_iova_ranges *info =3D NULL; struct iommu_iova_range *iova_ranges; - int ret, sz, fd =3D container->be->fd; + int sz, fd =3D container->be->fd; =20 info =3D g_malloc0(sizeof(*info)); info->size =3D sizeof(*info); info->ioas_id =3D ioas_id; =20 - ret =3D ioctl(fd, IOMMU_IOAS_IOVA_RANGES, info); - if (ret && errno !=3D EMSGSIZE) { + if (ioctl(fd, IOMMU_IOAS_IOVA_RANGES, info) && errno !=3D EMSGSIZE) { goto error; } =20 @@ -275,8 +270,7 @@ static int iommufd_cdev_get_info_iova_range(VFIOIOMMUFD= Container *container, info =3D g_realloc(info, sizeof(*info) + sz); info->allowed_iovas =3D (uintptr_t)(info + 1); =20 - ret =3D ioctl(fd, IOMMU_IOAS_IOVA_RANGES, info); - if (ret) { + if (ioctl(fd, IOMMU_IOAS_IOVA_RANGES, info)) { goto error; } =20 @@ -291,12 +285,11 @@ static int iommufd_cdev_get_info_iova_range(VFIOIOMMU= FDContainer *container, } bcontainer->pgsizes =3D info->out_iova_alignment; =20 - return 0; + return true; =20 error: - ret =3D -errno; error_setg_errno(errp, errno, "Cannot get IOVA ranges"); - return ret; + return false; } =20 static bool iommufd_cdev_attach(const char *name, VFIODevice *vbasedev, @@ -322,8 +315,7 @@ static bool iommufd_cdev_attach(const char *name, VFIOD= evice *vbasedev, devfd =3D vbasedev->fd; } =20 - ret =3D iommufd_cdev_connect_and_bind(vbasedev, errp); - if (ret) { + if (!iommufd_cdev_connect_and_bind(vbasedev, errp)) { goto err_connect_bind; } =20 @@ -336,7 +328,7 @@ static bool iommufd_cdev_attach(const char *name, VFIOD= evice *vbasedev, vbasedev->iommufd !=3D container->be) { continue; } - if (iommufd_cdev_attach_container(vbasedev, container, &err)) { + if (!iommufd_cdev_attach_container(vbasedev, container, &err)) { const char *msg =3D error_get_pretty(err); =20 trace_iommufd_cdev_fail_attach_existing_container(msg); @@ -369,8 +361,7 @@ static bool iommufd_cdev_attach(const char *name, VFIOD= evice *vbasedev, vfio_container_init(bcontainer, space, iommufd_vioc); QLIST_INSERT_HEAD(&space->containers, bcontainer, next); =20 - ret =3D iommufd_cdev_attach_container(vbasedev, container, errp); - if (ret) { + if (!iommufd_cdev_attach_container(vbasedev, container, errp)) { goto err_attach_container; } =20 @@ -379,8 +370,7 @@ static bool iommufd_cdev_attach(const char *name, VFIOD= evice *vbasedev, goto err_discard_disable; } =20 - ret =3D iommufd_cdev_get_info_iova_range(container, ioas_id, &err); - if (ret) { + if (!iommufd_cdev_get_info_iova_range(container, ioas_id, &err)) { error_append_hint(&err, "Fallback to default 64bit IOVA range and 4K page size\= n"); warn_report_err(err); --=20 2.34.1 From nobody Sat Feb 7 03:51:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; 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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1715064390; cv=none; d=zohomail.com; s=zohoarc; b=Cp39iox4jx2Sjhg9Stm7AOme2jZoC4sF4k/P8Jt4DEifCzzlJ1YoCY0Y7dwQjp0H8hmGvgmm4cQt4Zok4NdnqOLPtiEavMGDhhXfHr/uxnL1PjNALQhDuiNVwOAQFg3KUGia3q36izyrdlEkuNEVgf+6qYJomjQCUR/4eqjDFb8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715064390; 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=uonSrOt/eNVpoxfZbMk2BS5o5x/CXrfdaG0sCRlSJwE=; b=iqDxENVHTkPLbrCvN2+5xYKjwuZY//BUlIniBpSNVgfM/c5bGg044vmWTtxUU+tGM7Bp1J8Li2LDxeBp/pilr8/sBeYVQducfZSeGZYMTsuHJZuPUC2uk9UvWd/adr6PawdUvetftZnrz3I8YvbBbOG50LecvW8DoXgEaw35E/c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; 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 1715064390781278.8392699197914; Mon, 6 May 2024 23:46:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4EaS-0003ol-G2; Tue, 07 May 2024 02:46:04 -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 1s4Ea3-0003Pd-60 for qemu-devel@nongnu.org; Tue, 07 May 2024 02:45:42 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4Ea1-00064G-GA for qemu-devel@nongnu.org; Tue, 07 May 2024 02:45:38 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 23:45:36 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 23:45:34 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715064337; x=1746600337; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3kz+HnMU3OELL9Qs0ND9eLNaakr4SnZrzRGavmQaJdM=; b=hciNUrFNNt/XrSuk0o3V46h+MmHK+IXtoFnzRib9BbK9TVHLf7tB0Kei 7mXfSfKOpVfrxDyUuUwl4xyr7XTsMw28dEQ5usBlYmEZCG6YWdEMSOrce 2e5nokDJw8kL+QAcYjRKNPcoVfi1N6GRXvG2Q4RgFakt/j1WrDU7L8Q5o i2m34o+e/0Oc614Pt0QcyPAewUmUdhX6qwHzzPWqEiXGCvTZlVf20jJes 3mNFV8YHx9LuapdxPiQwVoMKilHlNLjwsywPnTGsseyzVYuFkYKNOY5aZ 6zAJYFLlLu3kPZegt4qdQ3Njad5SA0lHKPc2ezoN2BkZVl6bYDbt+hu/g w==; X-CSE-ConnectionGUID: RnEC3rbWQHKECvWgZGng+Q== X-CSE-MsgGUID: 7UL7lI7GQqWXo+8AqAp9Jw== X-IronPort-AV: E=McAfee;i="6600,9927,11065"; a="22240272" X-IronPort-AV: E=Sophos;i="6.07,260,1708416000"; d="scan'208";a="22240272" X-CSE-ConnectionGUID: DlwC+QZFTuy/X3WwkaPPxA== X-CSE-MsgGUID: 6l7kCiThRtWj2aIdmPEEKQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,260,1708416000"; d="scan'208";a="28407545" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, chao.p.peng@intel.com, Zhenzhong Duan Subject: [PATCH v2 10/11] vfio/cpr: Make vfio_cpr_register_container() return bool Date: Tue, 7 May 2024 14:42:51 +0800 Message-Id: <20240507064252.457884-11-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240507064252.457884-1-zhenzhong.duan@intel.com> References: <20240507064252.457884-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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 @intel.com) X-ZM-MESSAGEID: 1715064391681100001 This is to follow the coding standand to return bool if 'Error **' is used to pass error. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-common.h | 2 +- hw/vfio/container.c | 3 +-- hw/vfio/cpr.c | 4 ++-- hw/vfio/iommufd.c | 3 +-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index a7b6fc8f46..e4c60374fa 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -205,7 +205,7 @@ void vfio_detach_device(VFIODevice *vbasedev); int vfio_kvm_device_add_fd(int fd, Error **errp); int vfio_kvm_device_del_fd(int fd, Error **errp); =20 -int vfio_cpr_register_container(VFIOContainerBase *bcontainer, Error **err= p); +bool vfio_cpr_register_container(VFIOContainerBase *bcontainer, Error **er= rp); void vfio_cpr_unregister_container(VFIOContainerBase *bcontainer); =20 extern const MemoryRegionOps vfio_region_ops; diff --git a/hw/vfio/container.c b/hw/vfio/container.c index b02583ea16..86266f3b83 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -616,8 +616,7 @@ static bool vfio_connect_container(VFIOGroup *group, Ad= dressSpace *as, goto free_container_exit; } =20 - ret =3D vfio_cpr_register_container(bcontainer, errp); - if (ret) { + if (!vfio_cpr_register_container(bcontainer, errp)) { goto free_container_exit; } =20 diff --git a/hw/vfio/cpr.c b/hw/vfio/cpr.c index 392c2dd95d..87e51fcee1 100644 --- a/hw/vfio/cpr.c +++ b/hw/vfio/cpr.c @@ -25,12 +25,12 @@ static int vfio_cpr_reboot_notifier(NotifierWithReturn = *notifier, return 0; } =20 -int vfio_cpr_register_container(VFIOContainerBase *bcontainer, Error **err= p) +bool vfio_cpr_register_container(VFIOContainerBase *bcontainer, Error **er= rp) { migration_add_notifier_mode(&bcontainer->cpr_reboot_notifier, vfio_cpr_reboot_notifier, MIG_MODE_CPR_REBOOT); - return 0; + return true; } =20 void vfio_cpr_unregister_container(VFIOContainerBase *bcontainer) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 84c86b970e..6a446b16dc 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -396,8 +396,7 @@ found_container: goto err_listener_register; } =20 - ret =3D vfio_cpr_register_container(bcontainer, errp); - if (ret) { + if (!vfio_cpr_register_container(bcontainer, errp)) { goto err_listener_register; } =20 --=20 2.34.1 From nobody Sat Feb 7 03:51:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; 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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1715064392; cv=none; d=zohomail.com; s=zohoarc; b=IPNelpfyY//OFcmZjA1jQhl3zZOKpUke6tfvvR0rxbSrMQWA/WpMYrmGbhfjk7XZ/spNadZI6QvMmadLGzQumTQgyU9ljHV60TUMgzswj/QOu3LcklEOC4xmAF0r/EOCRAXqXuFCwA6bxbal3KTyZe0PoE5aaSZ+7zVI1BlLao4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715064392; 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=UYWB0X7mRe1zyTxHC7j9bXRvzEfTqzv1jTYilWOG9Jg=; b=R+KyowI189pn7Aw34tC8/kLx8mLjL5tph7UAMEKRvrdZOXASnP2FU7Q+423qLka5CCPl8lkFEsqCRROpkFttVGSY4mYhCdnfnSNwyzq6694QVaqY8/B5Z9ubiZAR8dxc/ErLx3N+kchOvVRZL0xla30xYzfa+bRSmsRYoLt3yu4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; 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 1715064392218507.7030331389369; Mon, 6 May 2024 23:46:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4EaT-0003yv-R1; Tue, 07 May 2024 02:46:05 -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 1s4EaF-0003TP-7h for qemu-devel@nongnu.org; Tue, 07 May 2024 02:45:56 -0400 Received: from mgamail.intel.com ([192.198.163.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s4Ea4-0006Fm-Dt for qemu-devel@nongnu.org; Tue, 07 May 2024 02:45:42 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 23:45:39 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 23:45:37 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715064340; x=1746600340; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rF9oBa+R0BwJduQ/QAasFeC7MzXwWFAzTS3CIvFpW0Y=; b=HmE1DIv9AK++njcnK8qM7fh4V/MexgAjVzqLpHth4jnskyqsy404KQYM x2j/lbZzDjS3KOvPOdl7RAuZKHPYVQNnl/1Y0aU1SwaCBvJ+NWj1z8m1o ySm2hlgtaUXxbBCKWkH1xFGgHTKFDWzZwzlDwVmhT+I+2lnJfVXHEXKXa antxpi0QFrC4YYD+NmvFEdqDdtgldOlswqB9LA5qiB6xNZU17UGz8rm5b OVkUoZS9F+CeawII1ixlK6Ugvw2kjgcnJTAcCqolzPAZDYHXIqILt0m8a Yyxtk7AZfIinE0J/KXi+EfatMdQ617KiKlYGKuVv3AmljctJzf3Y+HWDN A==; X-CSE-ConnectionGUID: kSM5jSlZTRujTil8MSlz5Q== X-CSE-MsgGUID: JVOd62ofQeCyKlU9B2pdsQ== X-IronPort-AV: E=McAfee;i="6600,9927,11065"; a="22240276" X-IronPort-AV: E=Sophos;i="6.07,260,1708416000"; d="scan'208";a="22240276" X-CSE-ConnectionGUID: YTxkEJVMQXid0kFclLTVGw== X-CSE-MsgGUID: GFu1zj/bTnqUO3MtIZqhkA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,260,1708416000"; d="scan'208";a="28407548" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, chao.p.peng@intel.com, Zhenzhong Duan , Yi Liu Subject: [PATCH v2 11/11] backends/iommufd: Make iommufd_backend_*() return bool Date: Tue, 7 May 2024 14:42:52 +0800 Message-Id: <20240507064252.457884-12-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240507064252.457884-1-zhenzhong.duan@intel.com> References: <20240507064252.457884-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=192.198.163.10; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.581, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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 @intel.com) X-ZM-MESSAGEID: 1715064393728100007 This is to follow the coding standand to return bool if 'Error **' is used to pass error. The changed functions include: iommufd_backend_connect iommufd_backend_alloc_ioas By this chance, simplify the functions a bit by avoiding duplicate recordings, e.g., log through either error interface or trace, not both. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater --- include/sysemu/iommufd.h | 6 +++--- backends/iommufd.c | 29 +++++++++++++---------------- hw/vfio/iommufd.c | 5 ++--- backends/trace-events | 4 ++-- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/include/sysemu/iommufd.h b/include/sysemu/iommufd.h index 9af27ebd6c..293bfbe967 100644 --- a/include/sysemu/iommufd.h +++ b/include/sysemu/iommufd.h @@ -23,11 +23,11 @@ struct IOMMUFDBackend { /*< public >*/ }; =20 -int iommufd_backend_connect(IOMMUFDBackend *be, Error **errp); +bool iommufd_backend_connect(IOMMUFDBackend *be, Error **errp); void iommufd_backend_disconnect(IOMMUFDBackend *be); =20 -int iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id, - Error **errp); +bool iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id, + Error **errp); void iommufd_backend_free_id(IOMMUFDBackend *be, uint32_t id); int iommufd_backend_map_dma(IOMMUFDBackend *be, uint32_t ioas_id, hwaddr i= ova, ram_addr_t size, void *vaddr, bool readonly); diff --git a/backends/iommufd.c b/backends/iommufd.c index 76a0204852..c506afbdac 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -72,24 +72,22 @@ static void iommufd_backend_class_init(ObjectClass *oc,= void *data) object_class_property_add_str(oc, "fd", NULL, iommufd_backend_set_fd); } =20 -int iommufd_backend_connect(IOMMUFDBackend *be, Error **errp) +bool iommufd_backend_connect(IOMMUFDBackend *be, Error **errp) { - int fd, ret =3D 0; + int fd; =20 if (be->owned && !be->users) { fd =3D qemu_open_old("/dev/iommu", O_RDWR); if (fd < 0) { error_setg_errno(errp, errno, "/dev/iommu opening failed"); - ret =3D fd; - goto out; + return false; } be->fd =3D fd; } be->users++; -out: - trace_iommufd_backend_connect(be->fd, be->owned, - be->users, ret); - return ret; + + trace_iommufd_backend_connect(be->fd, be->owned, be->users); + return true; } =20 void iommufd_backend_disconnect(IOMMUFDBackend *be) @@ -106,25 +104,24 @@ out: trace_iommufd_backend_disconnect(be->fd, be->users); } =20 -int iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id, - Error **errp) +bool iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id, + Error **errp) { - int ret, fd =3D be->fd; + int fd =3D be->fd; struct iommu_ioas_alloc alloc_data =3D { .size =3D sizeof(alloc_data), .flags =3D 0, }; =20 - ret =3D ioctl(fd, IOMMU_IOAS_ALLOC, &alloc_data); - if (ret) { + if (ioctl(fd, IOMMU_IOAS_ALLOC, &alloc_data)) { error_setg_errno(errp, errno, "Failed to allocate ioas"); - return ret; + return false; } =20 *ioas_id =3D alloc_data.out_ioas_id; - trace_iommufd_backend_alloc_ioas(fd, *ioas_id, ret); + trace_iommufd_backend_alloc_ioas(fd, *ioas_id); =20 - return ret; + return true; } =20 void iommufd_backend_free_id(IOMMUFDBackend *be, uint32_t id) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 6a446b16dc..554f9a6292 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -71,7 +71,7 @@ static bool iommufd_cdev_connect_and_bind(VFIODevice *vba= sedev, Error **errp) .flags =3D 0, }; =20 - if (iommufd_backend_connect(iommufd, errp)) { + if (!iommufd_backend_connect(iommufd, errp)) { return false; } =20 @@ -346,8 +346,7 @@ static bool iommufd_cdev_attach(const char *name, VFIOD= evice *vbasedev, } =20 /* Need to allocate a new dedicated container */ - ret =3D iommufd_backend_alloc_ioas(vbasedev->iommufd, &ioas_id, errp); - if (ret < 0) { + if (!iommufd_backend_alloc_ioas(vbasedev->iommufd, &ioas_id, errp)) { goto err_alloc_ioas; } =20 diff --git a/backends/trace-events b/backends/trace-events index d45c6e31a6..211e6f374a 100644 --- a/backends/trace-events +++ b/backends/trace-events @@ -7,11 +7,11 @@ dbus_vmstate_loading(const char *id) "id: %s" dbus_vmstate_saving(const char *id) "id: %s" =20 # iommufd.c -iommufd_backend_connect(int fd, bool owned, uint32_t users, int ret) "fd= =3D%d owned=3D%d users=3D%d (%d)" +iommufd_backend_connect(int fd, bool owned, uint32_t users) "fd=3D%d owned= =3D%d users=3D%d" iommufd_backend_disconnect(int fd, uint32_t users) "fd=3D%d users=3D%d" iommu_backend_set_fd(int fd) "pre-opened /dev/iommu fd=3D%d" iommufd_backend_map_dma(int iommufd, uint32_t ioas, uint64_t iova, uint64_= t size, void *vaddr, bool readonly, int ret) " iommufd=3D%d ioas=3D%d iova= =3D0x%"PRIx64" size=3D0x%"PRIx64" addr=3D%p readonly=3D%d (%d)" iommufd_backend_unmap_dma_non_exist(int iommufd, uint32_t ioas, uint64_t i= ova, uint64_t size, int ret) " Unmap nonexistent mapping: iommufd=3D%d ioas= =3D%d iova=3D0x%"PRIx64" size=3D0x%"PRIx64" (%d)" iommufd_backend_unmap_dma(int iommufd, uint32_t ioas, uint64_t iova, uint6= 4_t size, int ret) " iommufd=3D%d ioas=3D%d iova=3D0x%"PRIx64" size=3D0x%"P= RIx64" (%d)" -iommufd_backend_alloc_ioas(int iommufd, uint32_t ioas, int ret) " iommufd= =3D%d ioas=3D%d (%d)" +iommufd_backend_alloc_ioas(int iommufd, uint32_t ioas) " iommufd=3D%d ioas= =3D%d" iommufd_backend_free_id(int iommufd, uint32_t id, int ret) " iommufd=3D%d = id=3D%d (%d)" --=20 2.34.1