From patchwork Fri Sep 8 12:42:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Staikov, Andrii" X-Patchwork-Id: 13377440 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0103C1FCA for ; Fri, 8 Sep 2023 12:42:11 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A3E01BFF for ; Fri, 8 Sep 2023 05:42:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694176928; x=1725712928; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=1czcaAl8T7Va4mnRKKmDlySznPqbIwwcEkzNzmrbZDw=; b=iww6Il0uJtLBfaqpmUTenfLjtv6d0wJce8zoYD3GD8QZiJuFPOCePiUN kiLCbiXJ9IXuOS+yZfjm49wWZ3AUFLnYdIx3izP5pfFyRiYljGMoTyGw5 XH7qBhrWhFZ8n3YUIOzYHkYf+LY2fjXcC+nzA0Qi5wKkPFL0+xNYZoeAR eDt/t7TAKhwOIlqUZ8LyKMIzNvNzk+U5T8iZMP6oEwW3CtdIeGBGvUYgH XXNZcwi9zAQOYpOxpjXA8pLyXX/BfqF47SyobDaGf2j5gPHUYvpri5P7T AAiECuhSxaLJDdfKUSRlY9axCx7APngBDSrFCCGlIsZDwDwCNWXEsOcPy A==; X-IronPort-AV: E=McAfee;i="6600,9927,10827"; a="357940410" X-IronPort-AV: E=Sophos;i="6.02,237,1688454000"; d="scan'208";a="357940410" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Sep 2023 05:42:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10827"; a="745601965" X-IronPort-AV: E=Sophos;i="6.02,237,1688454000"; d="scan'208";a="745601965" Received: from amlin-019-225.igk.intel.com ([10.102.19.225]) by fmsmga007.fm.intel.com with ESMTP; 08 Sep 2023 05:42:03 -0700 From: Andrii Staikov To: intel-wired-lan@lists.osuosl.org Cc: netdev@vger.kernel.org, Andrii Staikov , Aleksandr Loktionov Subject: [PATCH iwl-net v4] i40e: fix potential memory leaks in i40e_remove() Date: Fri, 8 Sep 2023 14:42:01 +0200 Message-Id: <20230908124201.1836101-1-andrii.staikov@intel.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org 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 Signed-off-by: Aleksandr Loktionov Reviewed-by: Simon Horman --- 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(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c index 29ad1797adce..a368a190a22e 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -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);