raw/ntb: check memory allocations
authorChengwen Feng <fengchengwen@huawei.com>
Wed, 21 Apr 2021 02:08:16 +0000 (10:08 +0800)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 5 May 2021 20:53:04 +0000 (22:53 +0200)
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>
Acked-by: Xiaoyun Li <xiaoyun.li@intel.com>
drivers/raw/ntb/ntb.c
drivers/raw/ntb/ntb_hw_intel.c

index 0f0e3f2..6703bb5 100644 (file)
@@ -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;
index 4427e11..a742e8f 100644 (file)
@@ -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;