From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9FCBE42C92; Mon, 12 Jun 2023 07:37:20 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 715B44300E; Mon, 12 Jun 2023 07:37:20 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id 098C343000 for ; Mon, 12 Jun 2023 07:37:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686548239; x=1718084239; h=from:to:cc:subject:date:message-id; bh=D5T0bJBrC1k0yG+zYDQqVN/gR5tNQ9xHLsX5AYG7T/Q=; b=FRUmR5kQhINfA0qiWGDI7z/2668pGjp3Bwe+1S5k79lF5SatBQh6Wzlm FArQ4o8vfh9nDpdU9nAg/ZEWpm5cGAN/tzgeHeQfC0lx4+yvzOTzwraik 3fgwGuNDj5un4vf8EQXXQYzgvdoCcBNACiAy3/6HNe/0NLwU+MDAyVGMN kP31FrTdavPq+rpLoyAgUB99b5Qv+Zy7pwixrBtqopUnjLsbnFJiihSuP v0Fnp/oShiw8yPjWDiNiiGkcWCbu23ABM2NgwJC7rmHeL7ykeTiH1YaAX oVge9+Ha4yt++MWjzKsBjL+nHhwNGcmwrm6vgztLuvCJMiNs1Ejwdkrfs g==; X-IronPort-AV: E=McAfee;i="6600,9927,10738"; a="357944799" X-IronPort-AV: E=Sophos;i="6.00,236,1681196400"; d="scan'208";a="357944799" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jun 2023 22:37:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10738"; a="776221107" X-IronPort-AV: E=Sophos;i="6.00,236,1681196400"; d="scan'208";a="776221107" Received: from npg-dpdk-virtio-xiachenbo-nw.sh.intel.com ([10.67.119.79]) by fmsmga008.fm.intel.com with ESMTP; 11 Jun 2023 22:37:07 -0700 From: Chenbo Xia To: dev@dpdk.org Cc: anatoly.burakov@intel.com Subject: [PATCH] bus/pci: fix return value check of device FD Date: Mon, 12 Jun 2023 13:11:27 +0800 Message-Id: <20230612051127.44418-1-chenbo.xia@intel.com> X-Mailer: git-send-email 2.17.1 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Fixing return value check of rte_intr_dev_fd_get() to make sure negative device FD will not be used later. Coverity issue: 385380, 385373 Fixes: 095cf6e68b28 ("bus/pci: introduce MMIO read/write") Fixes: 4b741542ecde ("bus/pci: avoid depending on private kernel value") Signed-off-by: Chenbo Xia --- drivers/bus/pci/linux/pci_vfio.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c index ef8f9f4197..e634de8322 100644 --- a/drivers/bus/pci/linux/pci_vfio.c +++ b/drivers/bus/pci/linux/pci_vfio.c @@ -71,6 +71,8 @@ pci_vfio_read_config(const struct rte_pci_device *dev, int fd; fd = rte_intr_dev_fd_get(dev->intr_handle); + if (fd < 0) + return -1; if (pci_vfio_get_region(dev, VFIO_PCI_CONFIG_REGION_INDEX, &size, &offset) != 0) @@ -90,6 +92,8 @@ pci_vfio_write_config(const struct rte_pci_device *dev, int fd; fd = rte_intr_dev_fd_get(dev->intr_handle); + if (fd < 0) + return -1; if (pci_vfio_get_region(dev, VFIO_PCI_CONFIG_REGION_INDEX, &size, &offset) != 0) @@ -1369,6 +1373,8 @@ pci_vfio_mmio_read(const struct rte_pci_device *dev, int bar, int fd; fd = rte_intr_dev_fd_get(dev->intr_handle); + if (fd < 0) + return -1; if (pci_vfio_get_region(dev, bar, &size, &offset) != 0) return -1; @@ -1387,6 +1393,8 @@ pci_vfio_mmio_write(const struct rte_pci_device *dev, int bar, int fd; fd = rte_intr_dev_fd_get(dev->intr_handle); + if (fd < 0) + return -1; if (pci_vfio_get_region(dev, bar, &size, &offset) != 0) return -1; -- 2.17.1