use sizeof to avoid double use of a length define
[dpdk.git] / lib / librte_eal / linuxapp / eal / eal_interrupts.c
index 6df63d4..b5bcfc5 100644 (file)
@@ -1,34 +1,5 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2014 Intel Corporation
  */
 
 #include <stdio.h>
@@ -51,7 +22,6 @@
 #include <rte_common.h>
 #include <rte_interrupts.h>
 #include <rte_memory.h>
-#include <rte_memzone.h>
 #include <rte_launch.h>
 #include <rte_eal.h>
 #include <rte_per_lcore.h>
 #include <rte_branch_prediction.h>
 #include <rte_debug.h>
 #include <rte_log.h>
-#include <rte_pci.h>
 #include <rte_malloc.h>
 #include <rte_errno.h>
 #include <rte_spinlock.h>
 #include <rte_pause.h>
-#include <rte_vfio.h>
 
 #include "eal_private.h"
 #include "eal_vfio.h"
@@ -591,6 +559,9 @@ rte_intr_enable(const struct rte_intr_handle *intr_handle)
                        return -1;
                break;
 #endif
+       /* not used at this moment */
+       case RTE_INTR_HANDLE_DEV_EVENT:
+               return -1;
        /* unknown handle type */
        default:
                RTE_LOG(ERR, EAL,
@@ -638,6 +609,9 @@ rte_intr_disable(const struct rte_intr_handle *intr_handle)
                        return -1;
                break;
 #endif
+       /* not used at this moment */
+       case RTE_INTR_HANDLE_DEV_EVENT:
+               return -1;
        /* unknown handle type */
        default:
                RTE_LOG(ERR, EAL,
@@ -706,7 +680,10 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds)
                        bytes_read = 0;
                        call = true;
                        break;
-
+               case RTE_INTR_HANDLE_DEV_EVENT:
+                       bytes_read = 0;
+                       call = true;
+                       break;
                default:
                        bytes_read = 1;
                        break;
@@ -900,7 +877,7 @@ rte_eal_intr_init(void)
                        "Failed to create thread for interrupt handling\n");
        } else {
                /* Set thread_name for aid in debugging. */
-               snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN,
+               snprintf(thread_name, sizeof(thread_name),
                        "eal-intr-thread");
                ret_1 = rte_thread_setname(intr_thread, thread_name);
                if (ret_1 != 0)
@@ -915,7 +892,7 @@ static void
 eal_intr_proc_rxtx_intr(int fd, const struct rte_intr_handle *intr_handle)
 {
        union rte_intr_read_buffer buf;
-       int bytes_read = 1;
+       int bytes_read = 0;
        int nbytes;
 
        switch (intr_handle->type) {
@@ -931,11 +908,9 @@ eal_intr_proc_rxtx_intr(int fd, const struct rte_intr_handle *intr_handle)
                break;
 #endif
        case RTE_INTR_HANDLE_VDEV:
-               /* for vdev, fd points to:
-                * a. eventfd which does not need to read out;
-                * b. datapath fd which needs PMD to read out.
-                */
-               return;
+               bytes_read = intr_handle->efd_counter_size;
+               /* For vdev, number of bytes to read is set by driver */
+               break;
        case RTE_INTR_HANDLE_EXT:
                return;
        default:
@@ -948,6 +923,8 @@ eal_intr_proc_rxtx_intr(int fd, const struct rte_intr_handle *intr_handle)
         * read out to clear the ready-to-be-read flag
         * for epoll_wait.
         */
+       if (bytes_read == 0)
+               return;
        do {
                nbytes = read(fd, &buf, bytes_read);
                if (nbytes < 0) {
@@ -1207,7 +1184,12 @@ rte_intr_efd_enable(struct rte_intr_handle *intr_handle, uint32_t nb_efd)
                intr_handle->nb_efd   = n;
                intr_handle->max_intr = NB_OTHER_INTR + n;
        } else if (intr_handle->type == RTE_INTR_HANDLE_VDEV) {
-               /* do nothing, and let vdev driver to initialize this struct */
+               /* only check, initialization would be done in vdev driver.*/
+               if (intr_handle->efd_counter_size >
+                   sizeof(union rte_intr_read_buffer)) {
+                       RTE_LOG(ERR, EAL, "the efd_counter_size is oversized");
+                       return -EINVAL;
+               }
        } else {
                intr_handle->efds[0]  = intr_handle->fd;
                intr_handle->nb_efd   = RTE_MIN(nb_efd, 1U);