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 4A0D5A0547; Wed, 21 Apr 2021 04:08:21 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 06872418A3; Wed, 21 Apr 2021 04:08:12 +0200 (CEST) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by mails.dpdk.org (Postfix) with ESMTP id ACADD41894 for ; Wed, 21 Apr 2021 04:08:07 +0200 (CEST) Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4FQ3m04cN3zpZlB for ; Wed, 21 Apr 2021 10:05:04 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.498.0; Wed, 21 Apr 2021 10:08:03 +0800 From: "Min Hu (Connor)" To: CC: , , Date: Wed, 21 Apr 2021 10:08:16 +0800 Message-ID: <1618970896-37852-3-git-send-email-humin29@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1618970896-37852-1-git-send-email-humin29@huawei.com> References: <1618970896-37852-1-git-send-email-humin29@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH 2/2] raw/ntb: check malloc result 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" From: Chengwen Feng This patch adds checking for rte_zmalloc() result when init intel ntb device, also fix the same bug when start ntb device. Fixes: 034c328eb025 ("raw/ntb: support Intel NTB") Fixes: c39d1e082a4b ("raw/ntb: setup queues") Cc: stable@dpdk.org Signed-off-by: Chengwen Feng Signed-off-by: Min Hu (Connor) --- drivers/raw/ntb/ntb.c | 5 +++++ drivers/raw/ntb/ntb_hw_intel.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/drivers/raw/ntb/ntb.c b/drivers/raw/ntb/ntb.c index 0f0e3f2..6703bb5 100644 --- a/drivers/raw/ntb/ntb.c +++ b/drivers/raw/ntb/ntb.c @@ -923,6 +923,11 @@ ntb_dev_start(struct rte_rawdev *dev) hw->peer_mw_base = rte_zmalloc("ntb_peer_mw_base", hw->mw_cnt * sizeof(uint64_t), 0); + if (hw->peer_mw_base == NULL) { + NTB_LOG(ERR, "Cannot allocate memory for peer mw base."); + ret = -ENOMEM; + goto err_q_init; + } if (hw->ntb_ops->spad_read == NULL) { ret = -ENOTSUP; diff --git a/drivers/raw/ntb/ntb_hw_intel.c b/drivers/raw/ntb/ntb_hw_intel.c index 4427e11..a742e8f 100644 --- a/drivers/raw/ntb/ntb_hw_intel.c +++ b/drivers/raw/ntb/ntb_hw_intel.c @@ -148,6 +148,11 @@ intel_ntb_dev_init(const struct rte_rawdev *dev) hw->mw_size = rte_zmalloc("ntb_mw_size", hw->mw_cnt * sizeof(uint64_t), 0); + if (hw->mw_size == NULL) { + NTB_LOG(ERR, "Cannot allocate memory for mw size."); + return -ENOMEM; + } + for (i = 0; i < hw->mw_cnt; i++) { bar = intel_ntb_bar[i]; hw->mw_size[i] = hw->pci_dev->mem_resource[bar].len; -- 2.7.4