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 5EA65A0548; Mon, 1 Nov 2021 18:54:26 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D81B7410FC; Mon, 1 Nov 2021 18:54:25 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 4B52940DF6 for ; Mon, 1 Nov 2021 18:54:24 +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 1A1AY2TU010091; Mon, 1 Nov 2021 10:54:22 -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=N3HnrPppzdcNlW/QM2teEuBgei1ahuGQmyHnjqgs1BM=; b=BaCvLy/3gzEJoVrrv9BTbp58t3L8VYOQsSxaw7gApCmYxBzqVK9Aj3qj+Bb6OD+EPn9K Tn4bSxunIrafweeZvT7UlyTqQh42G+KtTCoBndJ/JKzR3ObXJ/ZNUgHd7pzFwZQAatUS BWGOG77FIGK4Rcj7pbjVlUFxFE64UC76utxI7IzqNDVj+oyVTIYIhecc835YecR4yPoK TDIAOuYEY4DAke16kh396UIaZej/bp56eHXJk8aOleJAAN/EKNJSepJlSkfc3anAL5s2 pDPq3TjAONtnT1z19rAk1lx2KGtPDZ8yewfDl7MtJ9DoSvAvXh281RUxJUyzvmADTHhv 8w== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3c2ekn1yg0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 01 Nov 2021 10:54:22 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) 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:20 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Mon, 1 Nov 2021 10:54:20 -0700 Received: from localhost.marvell.com (unknown [10.29.52.211]) by maili.marvell.com (Postfix) with ESMTP id 74B803F70BB; Mon, 1 Nov 2021 10:54:18 -0700 (PDT) From: Harman Kalra To: , Anatoly Burakov , "Jakub Grajciar" , Keith Wiles CC: , , Harman Kalra Date: Mon, 1 Nov 2021 23:23:36 +0530 Message-ID: <20211101175337.83358-5-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: cnIldcPd9upwztEPcwAEFnNlT1zPyj0s X-Proofpoint-ORIG-GUID: cnIldcPd9upwztEPcwAEFnNlT1zPyj0s 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 5/6] drivers: fix improper use of negative value 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: 373722,373721,373709,373702,373696 Fixes: d61138d4f0e2 ("drivers: remove direct access to interrupt handle") Signed-off-by: Harman Kalra --- drivers/bus/pci/linux/pci_vfio.c | 6 ++++++ drivers/net/memif/memif_socket.c | 3 +++ drivers/net/tap/rte_eth_tap.c | 11 +++++++---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c index 779525aa3e..1a5e7c2d2a 100644 --- a/drivers/bus/pci/linux/pci_vfio.c +++ b/drivers/bus/pci/linux/pci_vfio.c @@ -1028,6 +1028,9 @@ pci_vfio_unmap_resource_primary(struct rte_pci_device *dev) } vfio_dev_fd = rte_intr_dev_fd_get(dev->intr_handle); + if (vfio_dev_fd < 0) + return -1; + if (pci_vfio_set_bus_master(vfio_dev_fd, false)) { RTE_LOG(ERR, EAL, "%s cannot unset bus mastering for PCI device!\n", pci_addr); @@ -1071,6 +1074,9 @@ pci_vfio_unmap_resource_secondary(struct rte_pci_device *dev) loc->domain, loc->bus, loc->devid, loc->function); vfio_dev_fd = rte_intr_dev_fd_get(dev->intr_handle); + if (vfio_dev_fd < 0) + return -1; + ret = rte_vfio_release_device(rte_pci_get_sysfs_path(), pci_addr, vfio_dev_fd); if (ret < 0) { diff --git a/drivers/net/memif/memif_socket.c b/drivers/net/memif/memif_socket.c index c845c20ccf..079cf01269 100644 --- a/drivers/net/memif/memif_socket.c +++ b/drivers/net/memif/memif_socket.c @@ -65,6 +65,9 @@ memif_msg_send_from_queue(struct memif_control_channel *cc) if (e == NULL) return 0; + if (rte_intr_fd_get(cc->intr_handle) < 0) + return -1; + size = memif_msg_send(rte_intr_fd_get(cc->intr_handle), &e->msg, e->fd); if (size != sizeof(memif_msg_t)) { diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index a9a7658147..1b7d34e8a0 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -1663,8 +1663,9 @@ tap_dev_intr_handler(void *cb_arg) struct rte_eth_dev *dev = cb_arg; struct pmd_internals *pmd = dev->data->dev_private; - tap_nl_recv(rte_intr_fd_get(pmd->intr_handle), - tap_nl_msg_handler, dev); + if (rte_intr_fd_get(pmd->intr_handle) >= 0) + tap_nl_recv(rte_intr_fd_get(pmd->intr_handle), + tap_nl_msg_handler, dev); } static int @@ -1703,8 +1704,10 @@ tap_lsc_intr_handle_set(struct rte_eth_dev *dev, int set) } } while (true); - tap_nl_final(rte_intr_fd_get(pmd->intr_handle)); - rte_intr_fd_set(pmd->intr_handle, -1); + if (rte_intr_fd_get(pmd->intr_handle) >= 0) { + tap_nl_final(rte_intr_fd_get(pmd->intr_handle)); + rte_intr_fd_set(pmd->intr_handle, -1); + } return 0; } -- 2.18.0