rte_zmalloc_socket() can return NULL when memory is exhausted.
The result is passed directly to memcpy() without a NULL check,
leading to undefined behavior. Add a NULL check consistent with
the existing check for mac_addrs allocation in the same function.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: bf73ee28f47b ("net/ark: support single function with multiple port")
Cc: [email protected]

Signed-off-by: Denis Sergeev <[email protected]>
---
v2:
  * Fix Fixes: tag to use 12-char sha1 (checkpatch BAD_FIXES_TAG)

 drivers/net/ark/ark_ethdev.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/ark/ark_ethdev.c b/drivers/net/ark/ark_ethdev.c
index 8b25ed948f..546a44704f 100644
--- a/drivers/net/ark/ark_ethdev.c
+++ b/drivers/net/ark/ark_ethdev.c
@@ -445,6 +445,12 @@ ark_dev_init(struct rte_eth_dev *dev)
                                           sizeof(struct ark_adapter),
                                           RTE_CACHE_LINE_SIZE,
                                           rte_socket_id());
+               if (eth_dev->data->dev_private == NULL) {
+                       ARK_PMD_LOG(ERR,
+                                   "Memory allocation for dev_private failed!"
+                                   " Exiting.\n");
+                       goto error;
+               }
 
                memcpy(eth_dev->data->dev_private, ark,
                       sizeof(struct ark_adapter));
-- 
2.50.1

Reply via email to