DPDK patches and discussions
 help / color / mirror / Atom feed
From: Harman Kalra <hkalra@marvell.com>
To: <dev@dpdk.org>, Anatoly Burakov <anatoly.burakov@intel.com>,
	"Jakub Grajciar" <jgrajcia@cisco.com>,
	Keith Wiles <keith.wiles@intel.com>
Cc: <david.marchand@redhat.com>, <john.mcnamara@intel.com>,
	Harman Kalra <hkalra@marvell.com>
Subject: [dpdk-dev] [PATCH 5/6] drivers: fix improper use of negative value
Date: Mon, 1 Nov 2021 23:23:36 +0530	[thread overview]
Message-ID: <20211101175337.83358-5-hkalra@marvell.com> (raw)
In-Reply-To: <20211101175337.83358-1-hkalra@marvell.com>

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 --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;
 }
-- 
2.18.0


  parent reply	other threads:[~2021-11-01 17:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-01 17:53 [dpdk-dev] [PATCH 1/6] interrupts: fix argument cannot be negative Harman Kalra
2021-11-01 17:53 ` [dpdk-dev] [PATCH 2/6] lib: " Harman Kalra
2021-11-01 17:53 ` [dpdk-dev] [PATCH 3/6] drivers: fix bad bit shift operation Harman Kalra
2021-11-02  1:22   ` Wang, Haiyue
2021-11-01 17:53 ` [dpdk-dev] [PATCH 4/6] drivers: fix argument cannot be negative Harman Kalra
2021-11-01 17:53 ` Harman Kalra [this message]
2021-11-01 17:53 ` [dpdk-dev] [PATCH 6/6] net/mlx4: fix dereference after null check Harman Kalra
2021-11-02  7:34   ` Slava Ovsiienko
2021-11-08 16:32     ` David Marchand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211101175337.83358-5-hkalra@marvell.com \
    --to=hkalra@marvell.com \
    --cc=anatoly.burakov@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=jgrajcia@cisco.com \
    --cc=john.mcnamara@intel.com \
    --cc=keith.wiles@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).