[dpdk-dev,v3,23/27] net/ena: check pointer before memset
diff mbox series

Message ID 20180607094322.14312-23-mk@semihalf.com
State Accepted, archived
Delegated to: Ferruh Yigit
Headers show
Series
  • net/ena: new features and fixes
Related show

Checks

Context Check Description
ci/Intel-compilation fail Compilation issues
ci/checkpatch success coding style OK

Commit Message

Michał Krawczyk June 7, 2018, 9:43 a.m. UTC
From: Rafal Kozik <rk@semihalf.com>

Need to check if memory allocation succeed before using it.
Using memset on NULL pointer cause segfault.

Fixes: 9ba7981ec992 ("ena: add communication layer for DPDK")

Signed-off-by: Rafal Kozik <rk@semihalf.com>
Acked-by: Michal Krawczyk <mk@semihalf.com>
---
 drivers/net/ena/base/ena_plat_dpdk.h | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

Patch
diff mbox series

diff --git a/drivers/net/ena/base/ena_plat_dpdk.h b/drivers/net/ena/base/ena_plat_dpdk.h
index e2af4ee2c..d30153e92 100644
--- a/drivers/net/ena/base/ena_plat_dpdk.h
+++ b/drivers/net/ena/base/ena_plat_dpdk.h
@@ -210,10 +210,15 @@  extern uint32_t ena_alloc_cnt;
 				"ena_alloc_%d", ena_alloc_cnt++);	\
 		mz = rte_memzone_reserve(z_name, size, SOCKET_ID_ANY,	\
 				RTE_MEMZONE_IOVA_CONTIG);		\
-		memset(mz->addr, 0, size);				\
-		virt = mz->addr;					\
-		phys = mz->iova;					\
 		handle = mz;						\
+		if (mz == NULL) {					\
+			virt = NULL;					\
+			phys = 0;					\
+		} else {						\
+			memset(mz->addr, 0, size);			\
+			virt = mz->addr;				\
+			phys = mz->iova;				\
+		}							\
 	} while (0)
 #define ENA_MEM_FREE_COHERENT(dmadev, size, virt, phys, handle) 	\
 		({ ENA_TOUCH(size); ENA_TOUCH(phys);			\
@@ -230,9 +235,14 @@  extern uint32_t ena_alloc_cnt;
 				"ena_alloc_%d", ena_alloc_cnt++);	\
 		mz = rte_memzone_reserve(z_name, size, node,		\
 				RTE_MEMZONE_IOVA_CONTIG);		\
-		memset(mz->addr, 0, size);				\
-		virt = mz->addr;					\
-		phys = mz->iova;					\
+		if (mz == NULL) {					\
+			virt = NULL;					\
+			phys = 0;					\
+		} else {						\
+			memset(mz->addr, 0, size);			\
+			virt = mz->addr;				\
+			phys = mz->iova;				\
+		}							\
 		(void)mem_handle;					\
 	} while (0)