From patchwork Thu Oct 15 08:42:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunjian Wang X-Patchwork-Id: 80841 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 69222A04DB; Thu, 15 Oct 2020 10:42:58 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4E72B1DD43; Thu, 15 Oct 2020 10:42:57 +0200 (CEST) Received: from huawei.com (szxga07-in.huawei.com [45.249.212.35]) by dpdk.org (Postfix) with ESMTP id 2922C1DD3E; Thu, 15 Oct 2020 10:42:55 +0200 (CEST) Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 1EA65FFFE87AD2CB15DE; Thu, 15 Oct 2020 16:42:51 +0800 (CST) Received: from localhost (10.174.187.156) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Thu, 15 Oct 2020 16:42:41 +0800 From: wangyunjian To: CC: , , , , , , Yunjian Wang , Date: Thu, 15 Oct 2020 16:42:30 +0800 Message-ID: <1602751350-2808-1-git-send-email-wangyunjian@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1600511670-27576-1-git-send-email-wangyunjian@huawei.com> References: <1600511670-27576-1-git-send-email-wangyunjian@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.156] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH v2] eal: fix dereference after null check X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" From: Yunjian Wang This patch fixes (dereference after null check) coverity issue. For this reason, we should add null check at the beginning of the function and return error directly if the 'intr_handle' is null. Coverity issue: 357695, 357751 Fixes: 05c4105738d8 ("trace: add interrupt tracepoints") Cc: stable@dpdk.org Signed-off-by: Yunjian Wang Reviewed-by: Harman Kalra --- v2: fix code styles suggested by Ferruh Yigit --- lib/librte_eal/freebsd/eal_interrupts.c | 16 ++++++++++------ lib/librte_eal/linux/eal_interrupts.c | 16 ++++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/librte_eal/freebsd/eal_interrupts.c b/lib/librte_eal/freebsd/eal_interrupts.c index 6d53d33c8..211fd4f8d 100644 --- a/lib/librte_eal/freebsd/eal_interrupts.c +++ b/lib/librte_eal/freebsd/eal_interrupts.c @@ -350,13 +350,15 @@ rte_intr_enable(const struct rte_intr_handle *intr_handle) { int rc = 0; - if (intr_handle && intr_handle->type == RTE_INTR_HANDLE_VDEV) { + if (intr_handle == NULL) + return -1; + + if (intr_handle->type == RTE_INTR_HANDLE_VDEV) { rc = 0; goto out; } - if (!intr_handle || intr_handle->fd < 0 || - intr_handle->uio_cfg_fd < 0) { + if (intr_handle->fd < 0 || intr_handle->uio_cfg_fd < 0) { rc = -1; goto out; } @@ -389,13 +391,15 @@ rte_intr_disable(const struct rte_intr_handle *intr_handle) { int rc = 0; - if (intr_handle && intr_handle->type == RTE_INTR_HANDLE_VDEV) { + if (intr_handle == NULL) + return -1; + + if (intr_handle->type == RTE_INTR_HANDLE_VDEV) { rc = 0; goto out; } - if (!intr_handle || intr_handle->fd < 0 || - intr_handle->uio_cfg_fd < 0) { + if (intr_handle->fd < 0 || intr_handle->uio_cfg_fd < 0) { rc = -1; goto out; } diff --git a/lib/librte_eal/linux/eal_interrupts.c b/lib/librte_eal/linux/eal_interrupts.c index 13db5c4e8..f1bd0356c 100644 --- a/lib/librte_eal/linux/eal_interrupts.c +++ b/lib/librte_eal/linux/eal_interrupts.c @@ -667,13 +667,15 @@ rte_intr_enable(const struct rte_intr_handle *intr_handle) { int rc = 0; - if (intr_handle && intr_handle->type == RTE_INTR_HANDLE_VDEV) { + if (intr_handle == NULL) + return -1; + + if (intr_handle->type == RTE_INTR_HANDLE_VDEV) { rc = 0; goto out; } - if (!intr_handle || intr_handle->fd < 0 || - intr_handle->uio_cfg_fd < 0) { + if (intr_handle->fd < 0 || intr_handle->uio_cfg_fd < 0) { rc = -1; goto out; } @@ -794,13 +796,15 @@ rte_intr_disable(const struct rte_intr_handle *intr_handle) { int rc = 0; - if (intr_handle && intr_handle->type == RTE_INTR_HANDLE_VDEV) { + if (intr_handle == NULL) + return -1; + + if (intr_handle->type == RTE_INTR_HANDLE_VDEV) { rc = 0; goto out; } - if (!intr_handle || intr_handle->fd < 0 || - intr_handle->uio_cfg_fd < 0) { + if (intr_handle->fd < 0 || intr_handle->uio_cfg_fd < 0) { rc = -1; goto out; }