eal/linux: check interrupt file descriptor validity
[dpdk.git] / lib / eal / linux / eal_dev.c
index 6aaeffb..bde55a3 100644 (file)
@@ -220,8 +220,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
@@ -237,6 +239,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)
@@ -320,10 +325,12 @@ rte_dev_event_monitor_start(void)
                goto exit;
        }
 
-       if (rte_intr_type_set(intr_handle, RTE_INTR_HANDLE_DEV_EVENT))
+       ret = rte_intr_type_set(intr_handle, RTE_INTR_HANDLE_DEV_EVENT);
+       if (ret)
                goto exit;
 
-       if (rte_intr_fd_set(intr_handle, -1))
+       ret = rte_intr_fd_set(intr_handle, -1);
+       if (ret)
                goto exit;
 
        ret = dev_uev_socket_fd_create();
@@ -342,7 +349,10 @@ rte_dev_event_monitor_start(void)
        monitor_refcount++;
 
 exit:
-       rte_intr_instance_free(intr_handle);
+       if (ret) {
+               rte_intr_instance_free(intr_handle);
+               intr_handle = NULL;
+       }
        rte_rwlock_write_unlock(&monitor_lock);
        return ret;
 }
@@ -373,6 +383,7 @@ rte_dev_event_monitor_stop(void)
 
        close(rte_intr_fd_get(intr_handle));
        rte_intr_instance_free(intr_handle);
+       intr_handle = NULL;
 
        monitor_refcount--;