diff mbox series

[2/6] lib: fix argument cannot be negative

Message ID 20211101175337.83358-2-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: 373711,373694
Fixes: c2bd9367e18f ("lib: remove direct access to interrupt handle")

Signed-off-by: Harman Kalra <hkalra@marvell.com>
---
 lib/eal/linux/eal_dev.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/lib/eal/linux/eal_dev.c b/lib/eal/linux/eal_dev.c
index 06820a3666..607f18ebc2 100644
--- a/lib/eal/linux/eal_dev.c
+++ b/lib/eal/linux/eal_dev.c
@@ -217,8 +217,10 @@  static void
 dev_delayed_unregister(void *param)
 {
 	rte_intr_callback_unregister(intr_handle, dev_uev_handler, param);
-	close(rte_intr_fd_get(intr_handle));
-	rte_intr_fd_set(intr_handle, -1);
+	if (rte_intr_fd_get(intr_handle) >= 0) {
+		close(rte_intr_fd_get(intr_handle));
+		rte_intr_fd_set(intr_handle, -1);
+	}
 }
 
 static void
@@ -234,6 +236,9 @@  dev_uev_handler(__rte_unused void *param)
 	memset(&uevent, 0, sizeof(struct rte_dev_event));
 	memset(buf, 0, EAL_UEV_MSG_LEN);
 
+	if (rte_intr_fd_get(intr_handle) < 0)
+		return;
+
 	ret = recv(rte_intr_fd_get(intr_handle), buf, EAL_UEV_MSG_LEN,
 		   MSG_DONTWAIT);
 	if (ret < 0 && errno == EAGAIN)