diff mbox series

[2/2] raw/ntb: check malloc result

Message ID 1618970896-37852-3-git-send-email-humin29@huawei.com (mailing list archive)
State Accepted
Delegated to: Thomas Monjalon
Headers show
Series bugfix for raw ntb | expand

Checks

Context Check Description
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/github-robot success github build: passed
ci/travis-robot success travis build: passed
ci/intel-Testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Min Hu (Connor) April 21, 2021, 2:08 a.m. UTC
From: Chengwen Feng <fengchengwen@huawei.com>

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 <fengchengwen@huawei.com>
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
 drivers/raw/ntb/ntb.c          | 5 +++++
 drivers/raw/ntb/ntb_hw_intel.c | 5 +++++
 2 files changed, 10 insertions(+)

Comments

Li, Xiaoyun April 21, 2021, 3:33 a.m. UTC | #1
Hi

> -----Original Message-----
> From: Min Hu (Connor) <humin29@huawei.com>
> Sent: Wednesday, April 21, 2021 10:08
> To: dev@dpdk.org
> Cc: Yigit, Ferruh <ferruh.yigit@intel.com>; Li, Xiaoyun <xiaoyun.li@intel.com>;
> Wu, Jingjing <jingjing.wu@intel.com>
> Subject: [PATCH 2/2] raw/ntb: check malloc result
> 
> From: Chengwen Feng <fengchengwen@huawei.com>
> 
> 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 <fengchengwen@huawei.com>
> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
> ---
>  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

Acked-by: Xiaoyun Li <xiaoyun.li@intel.com>
diff mbox series

Patch

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;