Skip to contentSkip to conversation

net/ark: fix null dereference on allocation failure

PATCH Superseded Denis Sergeev 2 participants 4 messages Jun 3 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/ark: fix null dereference on allocation failure

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 bf73ee28f4 ("net/ark: support single function with multiple port")
---
 drivers/net/ark/ark_ethdev.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/ark/ark_ethdev.c +6 -0
index 8b25ed948f..546a44704f 100644
@@ -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));
Signature · 1 line
2.50.1
#1 lore raw

PATCH v2 1/1 net/ark: fix null dereference on allocation failure

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")

---
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(+)
drivers/net/ark/ark_ethdev.c +6 -0
index 8b25ed948f..546a44704f 100644
@@ -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));
Signature · 1 line
2.50.1
#2 lore raw

PATCH v3 1/1 net/ark: fix null dereference on allocation failure

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")

---
v3:
* Use a single-line error message without "!" and "Exiting"
v2:
* Fix Fixes: tag to use 12-char sha1 (checkpatch BAD_FIXES_TAG)

 drivers/net/ark/ark_ethdev.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/ark/ark_ethdev.c +4 -0
index 8b25ed948f..546a44704f 100644
@@ -445,6 +445,10 @@ 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\n");
+			goto error;
+		}
 
 		memcpy(eth_dev->data->dev_private, ark,
 		       sizeof(struct ark_adapter));
Signature · 1 line
2.50.1
#3 lore raw
In reply to Denis Sergeev

drivers/net/ark/ark_ethdev.c ark_dev_init(struct rte_eth_dev *dev) · line 451

Quoted 4 lines · On Wed, 3 Jun 2026 08:21:54 +0300 Denis Sergeev <[email protected]> wrote:
drivers/net/ark/ark_ethdev.c +4 -0
+		if (eth_dev->data->dev_private == NULL) {
+			ARK_PMD_LOG(ERR,
+				    "Memory allocation for dev_private failed!"
+				    " Exiting.\n");

Do not split error messages across lines. And no need for ! and the Exiting part.