Skip to contentSkip to conversation

bus/pci: fix return value check of device FD

PATCH Applied Chenbo Xia 3 participants 3 messages Jun 12, 2023

lore
Share & tools
lore

Chenbo Xia

author
#0 lore raw

PATCH 1/1 bus/pci: fix return value check of device FD

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")
---
 drivers/bus/pci/linux/pci_vfio.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/bus/pci/linux/pci_vfio.c +8 -0
index ef8f9f4197..e634de8322 100644
@@ -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;
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Chenbo Xia

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")

---

Signature · 2 lines
Thanks,
Anatoly
#2 lore raw

12/06/2023 11:47, Burakov, Anatoly:

Quoted 12 lines · Chenbo Xia
Quoted 9 lines

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")

---

Applied, thanks.