From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9413CA0548; Mon, 1 Nov 2021 18:54:19 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8337A410E8; Mon, 1 Nov 2021 18:54:19 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id CFECA40DF6 for ; Mon, 1 Nov 2021 18:54:17 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 1A1AY4FX010134; Mon, 1 Nov 2021 10:54:16 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=pfpt0220; bh=S56iaZR7ckUIv6kP9T1SXcN0Es71bDXgDPnGnGJ+g1g=; b=ePgefjEINri0T/cO7Rmjl+9I7BUZFoEbNjRkmP9W1OzcGByQEVLgIO9OwoyOOVpyjoAH 3Q8QQOsr84c2MAGBM4Oh22iGgHSXSeTffJxkaLTXhDGS/fuIP95o+jy5LdTIFsuqdF7t Ol0veA+aT2oLRA341W+NFg3zCDVzRB/o2BK3s11CgA2qCkprgrWbXteOlOPHx4hgQfpy IRl6RANS1UL6kZf/Zd8UMje3wbl2O6RdGJybMAahU2Ra2pURje/irbA4W5ilJiLGzwWO ug74NsDKBQgbKAGl5lj//vVF/J+p4k8fL1qDXjFJKyLFrVpBL9XnxDY5W4PIudlVhqEz Dw== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3c2ekn1yfn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 01 Nov 2021 10:54:16 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 1 Nov 2021 10:54:14 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Mon, 1 Nov 2021 10:54:14 -0700 Received: from localhost.marvell.com (unknown [10.29.52.211]) by maili.marvell.com (Postfix) with ESMTP id F1CEF3F70B3; Mon, 1 Nov 2021 10:54:09 -0700 (PDT) From: Harman Kalra To: , Ferruh Yigit , Anatoly Burakov , Stephen Hemminger , "Long Li" , Hemant Agrawal , "Sachin Saxena" , Jakub Grajciar , Matan Azrad , Viacheslav Ovsiienko CC: , , Harman Kalra Date: Mon, 1 Nov 2021 23:23:35 +0530 Message-ID: <20211101175337.83358-4-hkalra@marvell.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20211101175337.83358-1-hkalra@marvell.com> References: <20211101175337.83358-1-hkalra@marvell.com> MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-GUID: iLLN4HiEqpHBjtkCIXesMSsjjb9Lt8JB X-Proofpoint-ORIG-GUID: iLLN4HiEqpHBjtkCIXesMSsjjb9Lt8JB X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-01_06,2021-11-01_01,2020-04-07_01 Subject: [dpdk-dev] [PATCH 4/6] drivers: fix argument cannot be negative X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch fixes coverity issue by adding a check for negative event fd value. Coverity issue: 373723,373720,373719,373718,373715,373714,373713,373710, 373707,373706,373705,373704,373701,373700,373698,373695, 373692,373690,373689 Fixes: d61138d4f0e2 ("drivers: remove direct access to interrupt handle") Signed-off-by: Harman Kalra --- drivers/bus/pci/linux/pci_uio.c | 6 ++++++ drivers/bus/pci/linux/pci_vfio.c | 15 +++++++++++++++ drivers/bus/pci/pci_common_uio.c | 3 ++- drivers/bus/vmbus/linux/vmbus_uio.c | 6 +++++- drivers/bus/vmbus/vmbus_common_uio.c | 4 +++- drivers/net/dpaa/dpaa_ethdev.c | 3 +++ drivers/net/memif/memif_socket.c | 6 +++++- drivers/net/memif/rte_eth_memif.c | 12 +++++++++--- drivers/vdpa/mlx5/mlx5_vdpa_virtq.c | 3 +++ 9 files changed, 51 insertions(+), 7 deletions(-) diff --git a/drivers/bus/pci/linux/pci_uio.c b/drivers/bus/pci/linux/pci_uio.c index 2ee5d04672..d52125e49b 100644 --- a/drivers/bus/pci/linux/pci_uio.c +++ b/drivers/bus/pci/linux/pci_uio.c @@ -37,6 +37,9 @@ pci_uio_read_config(const struct rte_intr_handle *intr_handle, { int uio_cfg_fd = rte_intr_dev_fd_get(intr_handle); + if (uio_cfg_fd < 0) + return -1; + return pread(uio_cfg_fd, buf, len, offset); } @@ -46,6 +49,9 @@ pci_uio_write_config(const struct rte_intr_handle *intr_handle, { int uio_cfg_fd = rte_intr_dev_fd_get(intr_handle); + if (uio_cfg_fd < 0) + return -1; + return pwrite(uio_cfg_fd, buf, len, offset); } diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c index edcee92556..779525aa3e 100644 --- a/drivers/bus/pci/linux/pci_vfio.c +++ b/drivers/bus/pci/linux/pci_vfio.c @@ -49,6 +49,9 @@ pci_vfio_read_config(const struct rte_intr_handle *intr_handle, { int vfio_dev_fd = rte_intr_dev_fd_get(intr_handle); + if (vfio_dev_fd < 0) + return -1; + return pread64(vfio_dev_fd, buf, len, VFIO_GET_REGION_ADDR(VFIO_PCI_CONFIG_REGION_INDEX) + offs); } @@ -59,6 +62,9 @@ pci_vfio_write_config(const struct rte_intr_handle *intr_handle, { int vfio_dev_fd = rte_intr_dev_fd_get(intr_handle); + if (vfio_dev_fd < 0) + return -1; + return pwrite64(vfio_dev_fd, buf, len, VFIO_GET_REGION_ADDR(VFIO_PCI_CONFIG_REGION_INDEX) + offs); } @@ -1012,6 +1018,9 @@ pci_vfio_unmap_resource_primary(struct rte_pci_device *dev) } #endif + if (rte_intr_fd_get(dev->intr_handle) < 0) + return -1; + if (close(rte_intr_fd_get(dev->intr_handle)) < 0) { RTE_LOG(INFO, EAL, "Error when closing eventfd file descriptor for %s\n", pci_addr); @@ -1114,6 +1123,9 @@ pci_vfio_ioport_read(struct rte_pci_ioport *p, const struct rte_intr_handle *intr_handle = p->dev->intr_handle; int vfio_dev_fd = rte_intr_dev_fd_get(intr_handle); + if (vfio_dev_fd < 0) + return; + if (pread64(vfio_dev_fd, data, len, p->base + offset) <= 0) RTE_LOG(ERR, EAL, @@ -1128,6 +1140,9 @@ pci_vfio_ioport_write(struct rte_pci_ioport *p, const struct rte_intr_handle *intr_handle = p->dev->intr_handle; int vfio_dev_fd = rte_intr_dev_fd_get(intr_handle); + if (vfio_dev_fd < 0) + return; + if (pwrite64(vfio_dev_fd, data, len, p->base + offset) <= 0) RTE_LOG(ERR, EAL, diff --git a/drivers/bus/pci/pci_common_uio.c b/drivers/bus/pci/pci_common_uio.c index 244c9a8940..76c661f054 100644 --- a/drivers/bus/pci/pci_common_uio.c +++ b/drivers/bus/pci/pci_common_uio.c @@ -233,7 +233,8 @@ pci_uio_unmap_resource(struct rte_pci_device *dev) rte_free(uio_res); /* close fd if in primary process */ - close(rte_intr_fd_get(dev->intr_handle)); + if (rte_intr_fd_get(dev->intr_handle) >= 0) + close(rte_intr_fd_get(dev->intr_handle)); uio_cfg_fd = rte_intr_dev_fd_get(dev->intr_handle); if (uio_cfg_fd >= 0) { close(uio_cfg_fd); diff --git a/drivers/bus/vmbus/linux/vmbus_uio.c b/drivers/bus/vmbus/linux/vmbus_uio.c index 9c5c1aeca3..5db70f8e0d 100644 --- a/drivers/bus/vmbus/linux/vmbus_uio.c +++ b/drivers/bus/vmbus/linux/vmbus_uio.c @@ -30,7 +30,8 @@ static void *vmbus_map_addr; /* Control interrupts */ void vmbus_uio_irq_control(struct rte_vmbus_device *dev, int32_t onoff) { - if (write(rte_intr_fd_get(dev->intr_handle), &onoff, + if ((rte_intr_fd_get(dev->intr_handle) < 0) || + write(rte_intr_fd_get(dev->intr_handle), &onoff, sizeof(onoff)) < 0) { VMBUS_LOG(ERR, "cannot write to %d:%s", rte_intr_fd_get(dev->intr_handle), @@ -43,6 +44,9 @@ int vmbus_uio_irq_read(struct rte_vmbus_device *dev) int32_t count; int cc; + if (rte_intr_fd_get(dev->intr_handle) < 0) + return -1; + cc = read(rte_intr_fd_get(dev->intr_handle), &count, sizeof(count)); if (cc < (int)sizeof(count)) { diff --git a/drivers/bus/vmbus/vmbus_common_uio.c b/drivers/bus/vmbus/vmbus_common_uio.c index 336296d6a8..882a24f869 100644 --- a/drivers/bus/vmbus/vmbus_common_uio.c +++ b/drivers/bus/vmbus/vmbus_common_uio.c @@ -258,7 +258,9 @@ vmbus_uio_unmap_resource(struct rte_vmbus_device *dev) rte_free(uio_res); /* close fd if in primary process */ - close(rte_intr_fd_get(dev->intr_handle)); + if (rte_intr_fd_get(dev->intr_handle) >= 0) + close(rte_intr_fd_get(dev->intr_handle)); + if (rte_intr_dev_fd_get(dev->intr_handle) >= 0) { close(rte_intr_dev_fd_get(dev->intr_handle)); rte_intr_dev_fd_set(dev->intr_handle, -1); diff --git a/drivers/net/dpaa/dpaa_ethdev.c b/drivers/net/dpaa/dpaa_ethdev.c index b9bf9d2966..e49f765434 100644 --- a/drivers/net/dpaa/dpaa_ethdev.c +++ b/drivers/net/dpaa/dpaa_ethdev.c @@ -371,6 +371,9 @@ static void dpaa_interrupt_handler(void *param) dpaa_dev = container_of(rdev, struct rte_dpaa_device, device); intr_handle = dpaa_dev->intr_handle; + if (rte_intr_fd_get(intr_handle) < 0) + return; + bytes_read = read(rte_intr_fd_get(intr_handle), &buf, sizeof(uint64_t)); if (bytes_read < 0) diff --git a/drivers/net/memif/memif_socket.c b/drivers/net/memif/memif_socket.c index d48c3685d9..c845c20ccf 100644 --- a/drivers/net/memif/memif_socket.c +++ b/drivers/net/memif/memif_socket.c @@ -508,7 +508,8 @@ memif_intr_unregister_handler(struct rte_intr_handle *intr_handle, void *arg) struct memif_control_channel *cc = arg; /* close control channel fd */ - close(rte_intr_fd_get(intr_handle)); + if (rte_intr_fd_get(intr_handle) >= 0) + close(rte_intr_fd_get(intr_handle)); /* clear message queue */ while ((elt = TAILQ_FIRST(&cc->msg_queue)) != NULL) { TAILQ_REMOVE(&cc->msg_queue, elt, next); @@ -651,6 +652,9 @@ memif_msg_receive(struct memif_control_channel *cc) mh.msg_control = ctl; mh.msg_controllen = sizeof(ctl); + if (rte_intr_fd_get(cc->intr_handle) < 0) + return -1; + size = recvmsg(rte_intr_fd_get(cc->intr_handle), &mh, 0); if (size != sizeof(memif_msg_t)) { MIF_LOG(DEBUG, "Invalid message size = %zd", size); diff --git a/drivers/net/memif/rte_eth_memif.c b/drivers/net/memif/rte_eth_memif.c index 8cec493ffd..2935ae6ebe 100644 --- a/drivers/net/memif/rte_eth_memif.c +++ b/drivers/net/memif/rte_eth_memif.c @@ -325,7 +325,8 @@ eth_memif_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) } /* consume interrupt */ - if ((ring->flags & MEMIF_RING_FLAG_MASK_INT) == 0) + if (((ring->flags & MEMIF_RING_FLAG_MASK_INT) == 0) && + (rte_intr_fd_get(mq->intr_handle) >= 0)) size = read(rte_intr_fd_get(mq->intr_handle), &b, sizeof(b)); @@ -460,7 +461,8 @@ eth_memif_rx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) } /* consume interrupt */ - if ((ring->flags & MEMIF_RING_FLAG_MASK_INT) == 0) { + if ((rte_intr_fd_get(mq->intr_handle) >= 0) && + ((ring->flags & MEMIF_RING_FLAG_MASK_INT) == 0)) { uint64_t b; ssize_t size __rte_unused; size = read(rte_intr_fd_get(mq->intr_handle), &b, @@ -680,7 +682,8 @@ eth_memif_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) else __atomic_store_n(&ring->tail, slot, __ATOMIC_RELEASE); - if ((ring->flags & MEMIF_RING_FLAG_MASK_INT) == 0) { + if (((ring->flags & MEMIF_RING_FLAG_MASK_INT) == 0) && + (rte_intr_fd_get(mq->intr_handle) >= 0)) { a = 1; size = write(rte_intr_fd_get(mq->intr_handle), &a, sizeof(a)); @@ -835,6 +838,9 @@ eth_memif_tx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) /* Send interrupt, if enabled. */ if ((ring->flags & MEMIF_RING_FLAG_MASK_INT) == 0) { uint64_t a = 1; + if (rte_intr_fd_get(mq->intr_handle) < 0) + return -1; + ssize_t size = write(rte_intr_fd_get(mq->intr_handle), &a, sizeof(a)); if (unlikely(size < 0)) { diff --git a/drivers/vdpa/mlx5/mlx5_vdpa_virtq.c b/drivers/vdpa/mlx5/mlx5_vdpa_virtq.c index cb37ba097c..db971bad48 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa_virtq.c +++ b/drivers/vdpa/mlx5/mlx5_vdpa_virtq.c @@ -24,6 +24,9 @@ mlx5_vdpa_virtq_handler(void *cb_arg) uint64_t buf; int nbytes; + if (rte_intr_fd_get(virtq->intr_handle) < 0) + return; + do { nbytes = read(rte_intr_fd_get(virtq->intr_handle), &buf, 8); -- 2.18.0