diff mbox series

[5/6] drivers: fix improper use of negative value

Message ID 20211101175337.83358-5-hkalra@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers show
Series [1/6] interrupts: fix argument cannot be negative | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Harman Kalra Nov. 1, 2021, 5:53 p.m. UTC
This patch fixes coverity issue by adding a check for negative
event fd value.

Coverity issue: 373722,373721,373709,373702,373696
Fixes: d61138d4f0e2 ("drivers: remove direct access to interrupt handle")

Signed-off-by: Harman Kalra <hkalra@marvell.com>
---
 drivers/bus/pci/linux/pci_vfio.c |  6 ++++++
 drivers/net/memif/memif_socket.c |  3 +++
 drivers/net/tap/rte_eth_tap.c    | 11 +++++++----
 3 files changed, 16 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c
index 779525aa3e..1a5e7c2d2a 100644
--- a/drivers/bus/pci/linux/pci_vfio.c
+++ b/drivers/bus/pci/linux/pci_vfio.c
@@ -1028,6 +1028,9 @@  pci_vfio_unmap_resource_primary(struct rte_pci_device *dev)
 	}
 
 	vfio_dev_fd = rte_intr_dev_fd_get(dev->intr_handle);
+	if (vfio_dev_fd < 0)
+		return -1;
+
 	if (pci_vfio_set_bus_master(vfio_dev_fd, false)) {
 		RTE_LOG(ERR, EAL, "%s cannot unset bus mastering for PCI device!\n",
 				pci_addr);
@@ -1071,6 +1074,9 @@  pci_vfio_unmap_resource_secondary(struct rte_pci_device *dev)
 			loc->domain, loc->bus, loc->devid, loc->function);
 
 	vfio_dev_fd = rte_intr_dev_fd_get(dev->intr_handle);
+	if (vfio_dev_fd < 0)
+		return -1;
+
 	ret = rte_vfio_release_device(rte_pci_get_sysfs_path(), pci_addr,
 				      vfio_dev_fd);
 	if (ret < 0) {
diff --git a/drivers/net/memif/memif_socket.c b/drivers/net/memif/memif_socket.c
index c845c20ccf..079cf01269 100644
--- a/drivers/net/memif/memif_socket.c
+++ b/drivers/net/memif/memif_socket.c
@@ -65,6 +65,9 @@  memif_msg_send_from_queue(struct memif_control_channel *cc)
 	if (e == NULL)
 		return 0;
 
+	if (rte_intr_fd_get(cc->intr_handle) < 0)
+		return -1;
+
 	size = memif_msg_send(rte_intr_fd_get(cc->intr_handle), &e->msg,
 			      e->fd);
 	if (size != sizeof(memif_msg_t)) {
diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index a9a7658147..1b7d34e8a0 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -1663,8 +1663,9 @@  tap_dev_intr_handler(void *cb_arg)
 	struct rte_eth_dev *dev = cb_arg;
 	struct pmd_internals *pmd = dev->data->dev_private;
 
-	tap_nl_recv(rte_intr_fd_get(pmd->intr_handle),
-		    tap_nl_msg_handler, dev);
+	if (rte_intr_fd_get(pmd->intr_handle) >= 0)
+		tap_nl_recv(rte_intr_fd_get(pmd->intr_handle),
+			    tap_nl_msg_handler, dev);
 }
 
 static int
@@ -1703,8 +1704,10 @@  tap_lsc_intr_handle_set(struct rte_eth_dev *dev, int set)
 		}
 	} while (true);
 
-	tap_nl_final(rte_intr_fd_get(pmd->intr_handle));
-	rte_intr_fd_set(pmd->intr_handle, -1);
+	if (rte_intr_fd_get(pmd->intr_handle) >= 0) {
+		tap_nl_final(rte_intr_fd_get(pmd->intr_handle));
+		rte_intr_fd_set(pmd->intr_handle, -1);
+	}
 
 	return 0;
 }