[PATCH] bus/pci: fix return value check of device FD
Chenbo Xia
chenbo.xia at intel.com
Mon Jun 12 07:11:27 CEST 2023
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 at intel.com>
---
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
More information about the dev
mailing list