Skip to contentSkip to conversation

librte_pmd_bond: remove memory alloc for rte_pci_driver

PATCH Applied Jia Yu 3 participants 3 messages Mar 23, 2015 – Mar 27, 2015 2 messages not in the archive

lore
Share & tools
lore

Jia Yu

author
#0 lore raw

PATCH v2 1/1 librte_pmd_bond: remove memory alloc for rte_pci_driver

eth_driver already contains rte_pci_driver data structure. Allocating rte_pci_driver without referencing it after bond creation causes memory leakage.

Added signed off information.

---
 lib/librte_pmd_bond/rte_eth_bond_api.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
lib/librte_pmd_bond/rte_eth_bond_api.c +2 -9
index 903b7c3..13f3941 100644
@@ -230,11 +230,8 @@ rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id)
 		goto err;
 	}
 
-	pci_drv = rte_zmalloc_socket(name, sizeof(*pci_drv), 0, socket_id);
-	if (pci_drv == NULL) {
-		RTE_BOND_LOG(ERR, "Unable to malloc pci_drv on socket");
-		goto err;
-	}
+	pci_drv = &eth_drv->pci_drv;
+
 	pci_id_table = rte_zmalloc_socket(name, sizeof(*pci_id_table), 0, socket_id);
 	if (pci_id_table == NULL) {
 		RTE_BOND_LOG(ERR, "Unable to malloc pci_id_table on socket");
@@ -266,9 +263,7 @@ rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id)
 	pci_dev->numa_node = socket_id;
 	pci_drv->name = driver_name;
 
-	eth_drv->pci_drv = (struct rte_pci_driver)(*pci_drv);
 	eth_dev->driver = eth_drv;
-
 	eth_dev->data->dev_private = internals;
 	eth_dev->data->nb_rx_queues = (uint16_t)1;
 	eth_dev->data->nb_tx_queues = (uint16_t)1;
@@ -325,8 +320,6 @@ rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id)
 err:
 	if (pci_dev)
 		rte_free(pci_dev);
-	if (pci_drv)
-		rte_free(pci_drv);
 	if (pci_id_table)
 		rte_free(pci_id_table);
 	if (eth_drv)
Signature · 1 line
1.9.1

A message that is not in the archive (sent off-list or not yet received): 1427147636-45003-1-git-send-email-jyu-pghWNbHTmq7QT0dZR+AlfA@public.gmane.org

#2 lore raw
Quoted 41 lines · Jia Yu

eth_driver already contains rte_pci_driver data structure. Allocating rte_pci_driver without referencing it after bond creation causes memory leakage.

Added signed off information.

---
  lib/librte_pmd_bond/rte_eth_bond_api.c | 11 ++---------
  1 file changed, 2 insertions(+), 9 deletions(-)
lib/librte_pmd_bond/rte_eth_bond_api.c +2 -7
index 903b7c3..13f3941 100644
@@ -230,11 +230,8 @@ rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id)
  		goto err;
  	}
 
-	pci_drv = rte_zmalloc_socket(name, sizeof(*pci_drv), 0, socket_id);
-	if (pci_drv == NULL) {
-		RTE_BOND_LOG(ERR, "Unable to malloc pci_drv on socket");
-		goto err;
-	}
+	pci_drv = &eth_drv->pci_drv;
+
  	pci_id_table = rte_zmalloc_socket(name, sizeof(*pci_id_table), 0, socket_id);
  	if (pci_id_table == NULL) {
  		RTE_BOND_LOG(ERR, "Unable to malloc pci_id_table on socket");
@@ -266,9 +263,7 @@ rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id)
  	pci_dev->numa_node = socket_id;
  	pci_drv->name = driver_name;
 
-	eth_drv->pci_drv = (struct rte_pci_driver)(*pci_drv);
  	eth_dev->driver = eth_drv;
-
  	eth_dev->data->dev_private = internals;
  	eth_dev->data->nb_rx_queues = (uint16_t)1;
  	eth_dev->data->nb_tx_queues = (uint16_t)1;

lib/librte_pmd_bond/rte_eth_bond_api.c rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id) · line 325

Quoted 8 lines
lib/librte_pmd_bond/rte_eth_bond_api.c +0 -2
@@ -325,8 +320,6 @@ rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id)
  err:
  	if (pci_dev)
  		rte_free(pci_dev);
-	if (pci_drv)
-		rte_free(pci_drv);
  	if (pci_id_table)
  		rte_free(pci_id_table);
  	if (eth_drv)

A message that is not in the archive (sent off-list or not yet received): [email protected]