diff mbox series

[1/6] interrupts: fix argument cannot be negative

Message ID 20211101175337.83358-1-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 issues by adding a check for
negative event fd value.

Coverity issue: 373716,373699,373693,373688
Fixes: bbbac4cd6ed2 ("interrupts: remove direct access to interrupt handle")

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

Patch

diff --git a/lib/eal/linux/eal_interrupts.c b/lib/eal/linux/eal_interrupts.c
index f72661e1f0..15a27a2abf 100644
--- a/lib/eal/linux/eal_interrupts.c
+++ b/lib/eal/linux/eal_interrupts.c
@@ -416,7 +416,7 @@  uio_intx_intr_disable(const struct rte_intr_handle *intr_handle)
 
 	/* use UIO config file descriptor for uio_pci_generic */
 	uio_cfg_fd = rte_intr_dev_fd_get(intr_handle);
-	if (pread(uio_cfg_fd, &command_high, 1, 5) != 1) {
+	if (uio_cfg_fd < 0 || pread(uio_cfg_fd, &command_high, 1, 5) != 1) {
 		RTE_LOG(ERR, EAL,
 			"Error reading interrupts status for fd %d\n",
 			uio_cfg_fd);
@@ -442,7 +442,7 @@  uio_intx_intr_enable(const struct rte_intr_handle *intr_handle)
 
 	/* use UIO config file descriptor for uio_pci_generic */
 	uio_cfg_fd = rte_intr_dev_fd_get(intr_handle);
-	if (pread(uio_cfg_fd, &command_high, 1, 5) != 1) {
+	if (uio_cfg_fd < 0 || pread(uio_cfg_fd, &command_high, 1, 5) != 1) {
 		RTE_LOG(ERR, EAL,
 			"Error reading interrupts status for fd %d\n",
 			uio_cfg_fd);
@@ -465,7 +465,8 @@  uio_intr_disable(const struct rte_intr_handle *intr_handle)
 {
 	const int value = 0;
 
-	if (write(rte_intr_fd_get(intr_handle), &value, sizeof(value)) < 0) {
+	if (rte_intr_fd_get(intr_handle) < 0 ||
+	    write(rte_intr_fd_get(intr_handle), &value, sizeof(value)) < 0) {
 		RTE_LOG(ERR, EAL, "Error disabling interrupts for fd %d (%s)\n",
 			rte_intr_fd_get(intr_handle), strerror(errno));
 		return -1;
@@ -478,7 +479,8 @@  uio_intr_enable(const struct rte_intr_handle *intr_handle)
 {
 	const int value = 1;
 
-	if (write(rte_intr_fd_get(intr_handle), &value, sizeof(value)) < 0) {
+	if (rte_intr_fd_get(intr_handle) < 0 ||
+	    write(rte_intr_fd_get(intr_handle), &value, sizeof(value)) < 0) {
 		RTE_LOG(ERR, EAL, "Error enabling interrupts for fd %d (%s)\n",
 			rte_intr_fd_get(intr_handle), strerror(errno));
 		return -1;