bus/pci: fix return value check of device FD

Message ID 20230612051127.44418-1-chenbo.xia@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series bus/pci: fix return value check of device FD |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-aarch-unit-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS

Commit Message

Chenbo Xia June 12, 2023, 5:11 a.m. UTC
  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 <chenbo.xia@intel.com>
---
 drivers/bus/pci/linux/pci_vfio.c | 8 ++++++++
 1 file changed, 8 insertions(+)
  

Comments

Anatoly Burakov June 12, 2023, 9:47 a.m. UTC | #1
On 6/12/2023 6:11 AM, Chenbo Xia wrote:
> 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 <chenbo.xia@intel.com>
> ---

Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
  
Thomas Monjalon June 12, 2023, 4:36 p.m. UTC | #2
12/06/2023 11:47, Burakov, Anatoly:
> On 6/12/2023 6:11 AM, Chenbo Xia wrote:
> > 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 <chenbo.xia@intel.com>
> > ---
> 
> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>

Applied, thanks.
  

Patch

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;