Intel-Wired-Lan Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Intel-wired-lan] [PATCH iwl-net v2] i40e: fix potential memory leaks in i40e_remove()
@ 2023-08-09 11:55 Andrii Staikov
  2023-08-10 21:31 ` Tony Nguyen
  0 siblings, 1 reply; 2+ messages in thread
From: Andrii Staikov @ 2023-08-09 11:55 UTC (permalink / raw)
  To: intel-wired-lan; +Cc: Aleksandr Loktionov, 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
mumber 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>
---
v1 -> v2: Changed commit message.
---
 drivers/net/ethernet/intel/i40e/i40e_main.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
index 29ad1797adce..1c892b14a337 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_main.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
@@ -16326,8 +16326,14 @@ static void i40e_remove(struct pci_dev *pdev)
 	/* Now we can shutdown the PF's VSI, 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_free_q_vectors(pf->vsi[i]);
+			i40e_vsi_release(pf->vsi[i]);
+			kfree(pf->vsi[i]);
+			pf->vsi[i] = NULL;
+		}
 
 	i40e_cloud_filter_exit(pf);
 
-- 
2.25.1

_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan@osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Intel-wired-lan] [PATCH iwl-net v2] i40e: fix potential memory leaks in i40e_remove()
  2023-08-09 11:55 [Intel-wired-lan] [PATCH iwl-net v2] i40e: fix potential memory leaks in i40e_remove() Andrii Staikov
@ 2023-08-10 21:31 ` Tony Nguyen
  0 siblings, 0 replies; 2+ messages in thread
From: Tony Nguyen @ 2023-08-10 21:31 UTC (permalink / raw)
  To: Andrii Staikov, intel-wired-lan; +Cc: Aleksandr Loktionov



On 8/9/2023 4:55 AM, Andrii Staikov wrote:
> 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
> mumber equal to the number of allocated VSIs.

WARNING: 'mumber' may be misspelled - perhaps 'number'?

> 
> Fixes: 41c445ff0f48 ("i40e: main driver core")
> Signed-off-by: Andrii Staikov <andrii.staikov@intel.com>
> Signed-off-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
> ---
> v1 -> v2: Changed commit message.
> ---
>   drivers/net/ethernet/intel/i40e/i40e_main.c | 10 ++++++++--
>   1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
> index 29ad1797adce..1c892b14a337 100644
> --- a/drivers/net/ethernet/intel/i40e/i40e_main.c
> +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
> @@ -16326,8 +16326,14 @@ static void i40e_remove(struct pci_dev *pdev)
>   	/* Now we can shutdown the PF's VSI, 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_free_q_vectors(pf->vsi[i]);
> +			i40e_vsi_release(pf->vsi[i]);
> +			kfree(pf->vsi[i]);
> +			pf->vsi[i] = NULL;
> +		}
>   
>   	i40e_cloud_filter_exit(pf);
>   
_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan@osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-10 21:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-09 11:55 [Intel-wired-lan] [PATCH iwl-net v2] i40e: fix potential memory leaks in i40e_remove() Andrii Staikov
2023-08-10 21:31 ` Tony Nguyen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox