i40e: fix potential memory leaks in i40e_remove()
authorAndrii Staikov <andrii.staikov@intel.com>
Fri, 8 Sep 2023 12:42:01 +0000 (14:42 +0200)
committerTony Nguyen <anthony.l.nguyen@intel.com>
Mon, 11 Sep 2023 15:53:08 +0000 (08:53 -0700)
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")
Signed-off-by: Andrii Staikov <andrii.staikov@intel.com>
Signed-off-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
drivers/net/ethernet/intel/i40e/i40e_main.c

index de7fd43dc11c8d7b13b0a1ab4a8382e6b1109f23..00ca2b88165cb3ead415cc3eb5502b6419242994 100644 (file)
@@ -16320,11 +16320,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);