From patchwork Fri Sep 11 11:08:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunjian Wang X-Patchwork-Id: 77374 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id CCA4CA04B5; Fri, 11 Sep 2020 13:08:15 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A86741C0CE; Fri, 11 Sep 2020 13:08:15 +0200 (CEST) Received: from huawei.com (szxga06-in.huawei.com [45.249.212.32]) by dpdk.org (Postfix) with ESMTP id C3BC8E07; Fri, 11 Sep 2020 13:08:13 +0200 (CEST) Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 1BE24E24009D78D146B4; Fri, 11 Sep 2020 19:08:12 +0800 (CST) Received: from localhost (10.174.185.168) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Fri, 11 Sep 2020 19:08:06 +0800 From: wangyunjian To: CC: , , , , , Yunjian Wang , Date: Fri, 11 Sep 2020 19:08:04 +0800 Message-ID: <1599822484-19100-1-git-send-email-wangyunjian@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <20200621090800.1AE521C00D@dpdk.org> References: <20200621090800.1AE521C00D@dpdk.org> MIME-Version: 1.0 X-Originating-IP: [10.174.185.168] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH v2 RESEND] vfio: fix resource leak when mapping fails X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Yunjian Wang Currently, only the 'vfio_dev_fd' is closed in failure path, so some resources are not released(such as 'vfio_group_fd'). The rte_vfio_release_device() should be used to avoid this problem. Fixes: 33604c31354a ("vfio: refactor PCI BAR mapping") Cc: stable@dpdk.org Signed-off-by: Yunjian Wang Reviewed-by: Anatoly Burakov Reviewed-by: Anatoly Burakov --- v2: Update email address --- drivers/bus/pci/linux/pci_vfio.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c index c15ed3bad..17350f34d 100644 --- a/drivers/bus/pci/linux/pci_vfio.c +++ b/drivers/bus/pci/linux/pci_vfio.c @@ -826,7 +826,8 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev) err_vfio_res: rte_free(vfio_res); err_vfio_dev_fd: - close(vfio_dev_fd); + rte_vfio_release_device(rte_pci_get_sysfs_path(), + pci_addr, vfio_dev_fd); return -1; } @@ -894,7 +895,8 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev) return 0; err_vfio_dev_fd: - close(vfio_dev_fd); + rte_vfio_release_device(rte_pci_get_sysfs_path(), + pci_addr, vfio_dev_fd); return -1; }