Skip to contentSkip to conversation

i40e: fix potential memory leaks in i40e_remove()

PATCH In review Andrii Staikov 2 participants 2 messages Sep 8, 2023 – Sep 10, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 i40e: fix potential memory leaks in i40e_remove()

Instead of freeing memory of a single VSI, make sure the memory for all VSIs is cleared before releasing VSIs. Add releasing of their resources in a loop with the iteration number equal to the number of allocated VSIs.

Fixes 41c445ff0f48 ("i40e: main driver core")

---
v1 -> v2: Changed commit message.
v2 -> v3: Fixed mistakes in the commit message.
v3 -> v4: Remove redundant i40e_vsi_free_q_vectors() and kfree() calls.

---
 drivers/net/ethernet/intel/i40e/i40e_main.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_main.c +7 -3
index 29ad1797adce..a368a190a22e 100644
@@ -16323,11 +16323,15 @@ static void i40e_remove(struct pci_dev *pdev)
 			i40e_switch_branch_release(pf->veb[i]);
 	}
 
-	/* Now we can shutdown the PF's VSI, just before we kill
+	/* Now we can shutdown the PF's VSIs, just before we kill
 	 * adminq and hmc.
 	 */
-	if (pf->vsi[pf->lan_vsi])
-		i40e_vsi_release(pf->vsi[pf->lan_vsi]);
+	for (i = pf->num_alloc_vsi; i--;)
+		if (pf->vsi[i]) {
+			i40e_vsi_close(pf->vsi[i]);
+			i40e_vsi_release(pf->vsi[i]);
+			pf->vsi[i] = NULL;
+		}
 
 	i40e_cloud_filter_exit(pf);
 
Signature · 1 line
2.25.1
reviewer Reviewed-by on v4 1/1
#1 lore raw
Quoted 8 lines · Andrii Staikov

Instead of freeing memory of a single VSI, make sure the memory for all VSIs is cleared before releasing VSIs. Add releasing of their resources in a loop with the iteration number equal to the number of allocated VSIs.

Fixes 41c445ff0f48 ("i40e: main driver core")