rte_intr_fd_set() can fail and replace rte_errno. Check the call
when clearing an interrupt fd, and restore the error that caused
handler creation to fail.

Coverity issue: 912881
Coverity issue: 912878
Fixes: d770ee9caed0 ("interrupts: warn on leaked FDs")
Cc: [email protected]

Signed-off-by: Maayan Kashani <[email protected]>
Acked-by: Bing Zhao <[email protected]>
---
 drivers/common/mlx5/linux/mlx5_common_os.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/common/mlx5/linux/mlx5_common_os.c 
b/drivers/common/mlx5/linux/mlx5_common_os.c
index b8a7c53e5f3..71d67b71e17 100644
--- a/drivers/common/mlx5/linux/mlx5_common_os.c
+++ b/drivers/common/mlx5/linux/mlx5_common_os.c
@@ -1108,7 +1108,13 @@ mlx5_os_interrupt_handler_create(int mode, bool 
set_fd_nonblock, int fd,
        }
        return tmp_intr_handle;
 err:
-       rte_intr_fd_set(tmp_intr_handle, -1);
+       if (tmp_intr_handle != NULL) {
+               int saved_errno = rte_errno;
+
+               if (rte_intr_fd_set(tmp_intr_handle, -1) != 0)
+                       DRV_LOG(DEBUG, "failed to reset interrupt fd");
+               rte_errno = saved_errno;
+       }
        rte_intr_instance_free(tmp_intr_handle);
        return NULL;
 }
@@ -1185,7 +1191,8 @@ mlx5_os_interrupt_handler_destroy(struct rte_intr_handle 
*intr_handle,
        if (rte_intr_fd_get(intr_handle) >= 0) {
                mlx5_intr_callback_unregister(intr_handle, cb, cb_arg);
                /* fd is not owned by the driver, only clear reference here. */
-               rte_intr_fd_set(intr_handle, -1);
+               if (rte_intr_fd_set(intr_handle, -1) != 0)
+                       DRV_LOG(DEBUG, "failed to reset interrupt fd");
        }
        rte_intr_instance_free(intr_handle);
 }
-- 
2.25.1

Reply via email to