From nobody Mon Feb 9 05:10:45 2026 Received: from mail-m49198.qiye.163.com (mail-m49198.qiye.163.com [45.254.49.198]) (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 B07C43254BD; Tue, 30 Dec 2025 14:59:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.254.49.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767106754; cv=none; b=hIRmn04Mq4+7L/JZV04QVIEaJBpDuFTnBCGkPKMO6iF3VSySiViYI8IhpaWdkk0Ed04gpsaI/IQ29m6jpjMGnMBZlaxlq8psUy6adHxyVe47V9RZXcodhvfjCiABOpt3J58IKINtv9r9IidfJ8o3H8BMfMOJvjS2xhZRb1NvrLw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767106754; c=relaxed/simple; bh=ZIvQDxZDetnQ0xfwwElweUFce4vC+1SpEyM58qQ/cB0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kRlQD5B905C5Hy0eGdFSWz128byP7zm6XGRZaAjve+aSmySUriorw9Fa9ejm9luN02XQbNbRBZYyxHx3JyOe+qQkvvNfN5ghnTgc7b9omdxINonMded7E/MuW3pplye5r7WS9Y5Y56Bge2zgOCmndE7hpU0AQ+0wQrzDR7eSQCo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn; spf=pass smtp.mailfrom=seu.edu.cn; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b=nG1Ki6N+; arc=none smtp.client-ip=45.254.49.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b="nG1Ki6N+" Received: from LAPTOP-N070L597.localdomain (unknown [223.112.146.162]) by smtp.qiye.163.com (Hmail) with ESMTP id 2f0b66557; Tue, 30 Dec 2025 22:59:06 +0800 (GMT+08:00) From: Zilin Guan To: justin.tee@broadcom.com Cc: paul.ely@broadcom.com, James.Bottomley@HansenPartnership.com, martin.petersen@oracle.com, Markus.Elfring@web.de, jianhao.xu@seu.edu.cn, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Zilin Guan Subject: [PATCH v2 1/3] scsi: lpfc: Fix memory leak in lpfc_config_port_post() Date: Tue, 30 Dec 2025 14:58:56 +0000 Message-Id: <20251230145858.1356864-2-zilin@seu.edu.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251230145858.1356864-1-zilin@seu.edu.cn> References: <20251230145858.1356864-1-zilin@seu.edu.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-HM-Tid: 0a9b6fc5185e03a1kunmc44e99e11660b8 X-HM-MType: 10 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVkZTkNIVhgaGk4ZSBgfSkIYH1YeHw5VEwETFhoSFy QUDg9ZV1kYEgtZQVlJSUhVSkpJVUpPTVVKTUlZV1kWGg8SFR0UWUFZT0tIVUpLSUJDQ0xVSktLVU tZBg++ DKIM-Signature: a=rsa-sha256; b=nG1Ki6N+7NLN1idebOGNRsE9TU0PdjrziNOCNQT4wNpOoKHxV7g2bPlg52/ppneFdGSpKNZ5cSagReJlN3WO8Nd8bPk1w3hkKLpiZnJAPqo56eDYV8CU+N5MMEKu1E3m/oJSRwX/hmEGp5pYuWsYFZUjBF4HGY2NLozSUJ7iaKU=; s=default; c=relaxed/relaxed; d=seu.edu.cn; v=1; bh=1yQ2WTZI2O8HROjoaf/lEGkd9+VlSDWeeazkE0xc8GM=; h=date:mime-version:subject:message-id:from; Content-Type: text/plain; charset="utf-8" In lpfc_config_port_post(), pmb is allocated via mempool_alloc() but is not freed when lpfc_readl() fails. Instead of simply adding the missing free, refactor the error handling to use a goto label. This unifies the cleanup logic and ensures pmb is freed in all error paths. Fixes: 9940b97bb30d ("[SCSI] lpfc 8.3.22: Add support for PCI Adapter Failu= re") Suggested-by: Markus Elfring Co-developed-by: Jianhao Xu Signed-off-by: Jianhao Xu Signed-off-by: Zilin Guan --- v2: - Refactor error handling to use a goto label for cleanup. drivers/scsi/lpfc/lpfc_init.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c index b1460b16dd91..1390d2b5095d 100644 --- a/drivers/scsi/lpfc/lpfc_init.c +++ b/drivers/scsi/lpfc/lpfc_init.c @@ -511,8 +511,7 @@ lpfc_config_port_post(struct lpfc_hba *phba) "READ_CONFIG, mbxStatus x%x\n", mb->mbxCommand, mb->mbxStatus); phba->link_state =3D LPFC_HBA_ERROR; - mempool_free( pmb, phba->mbox_mem_pool); - return -EIO; + goto out_free; } =20 /* Check if the port is disabled */ @@ -550,8 +549,7 @@ lpfc_config_port_post(struct lpfc_hba *phba) if (phba->intr_type =3D=3D MSIX) { rc =3D lpfc_config_msi(phba, pmb); if (rc) { - mempool_free(pmb, phba->mbox_mem_pool); - return -EIO; + goto out_free; } rc =3D lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); if (rc !=3D MBX_SUCCESS) { @@ -560,8 +558,7 @@ lpfc_config_port_post(struct lpfc_hba *phba) "failed, mbxCmd x%x, mbxStatus x%x\n", pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); - mempool_free(pmb, phba->mbox_mem_pool); - return -EIO; + goto out_free; } } =20 @@ -572,7 +569,7 @@ lpfc_config_port_post(struct lpfc_hba *phba) /* Enable appropriate host interrupts */ if (lpfc_readl(phba->HCregaddr, &status)) { spin_unlock_irq(&phba->hbalock); - return -EIO; + goto out_free; } status |=3D HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; if (psli->num_rings > 0) @@ -616,9 +613,7 @@ lpfc_config_port_post(struct lpfc_hba *phba) lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, "2599 Adapter failed to issue DOWN_LINK" " mbox command rc 0x%x\n", rc); - - mempool_free(pmb, phba->mbox_mem_pool); - return -EIO; + goto out_free; } } else if (phba->cfg_suppress_link_up =3D=3D LPFC_INITIALIZE_LINK) { mempool_free(pmb, phba->mbox_mem_pool); @@ -666,6 +661,10 @@ lpfc_config_port_post(struct lpfc_hba *phba) } =20 return 0; + +out_free: + mempool_free(pmb, phba->mbox_mem_pool); + return -EIO; } =20 /** --=20 2.34.1 From nobody Mon Feb 9 05:10:45 2026 Received: from mail-m155101.qiye.163.com (mail-m155101.qiye.163.com [101.71.155.101]) (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 22566325705; Tue, 30 Dec 2025 14:59:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=101.71.155.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767106755; cv=none; b=sFCaF4yREixv83tbrStVWNxeYmV3Rzer2nDberplbwsUPuVk2oDGErj09aKnNBpQCrLdn/qGgS44VNllVEPAakxr0dcSVj37RehGD8Ojznu1oJ61ZqTRqL07KKBFBxHMsEwMVy1jw50tCTMU8nS1/gXUI4u+LNBq5EFeqvsjNag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767106755; c=relaxed/simple; bh=Wt+mIuYGopcVWGXs5VLcPZ9XeS7veaE5oh4v1RZV/b8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AB0WcxcHDI/xAAVxS0lXGprPG5P9e3txk/XXPnBSAsg4d+PMr2CwQIjxDd1MavEQAmBnsygiNynUBdHKhKOpx3X+XNNcv7rnyAzRHlxBKPQYKf7kovTx1XD63a+X1Tqm2j6O+L2+tOcMJQj2BB2N0YDDv7PCK45hynzV+FYTdA8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn; spf=pass smtp.mailfrom=seu.edu.cn; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b=d4IsFeZN; arc=none smtp.client-ip=101.71.155.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b="d4IsFeZN" Received: from LAPTOP-N070L597.localdomain (unknown [223.112.146.162]) by smtp.qiye.163.com (Hmail) with ESMTP id 2f0b6655b; Tue, 30 Dec 2025 22:59:08 +0800 (GMT+08:00) From: Zilin Guan To: justin.tee@broadcom.com Cc: paul.ely@broadcom.com, James.Bottomley@HansenPartnership.com, martin.petersen@oracle.com, Markus.Elfring@web.de, jianhao.xu@seu.edu.cn, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Zilin Guan Subject: [PATCH v2 2/3] scsi: lpfc: Fix memory leak in lpfc_sli4_driver_resource_setup() Date: Tue, 30 Dec 2025 14:58:57 +0000 Message-Id: <20251230145858.1356864-3-zilin@seu.edu.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251230145858.1356864-1-zilin@seu.edu.cn> References: <20251230145858.1356864-1-zilin@seu.edu.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-HM-Tid: 0a9b6fc5222603a1kunmc44e99e11660bf X-HM-MType: 10 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVlCHU8dVkMaT05CSRhLSB1ITVYeHw5VEwETFhoSFy QUDg9ZV1kYEgtZQVlJSUhVSkpJVUpPTVVKTUlZV1kWGg8SFR0UWUFZT0tIVUpLSUJDQ0xVSktLVU tZBg++ DKIM-Signature: a=rsa-sha256; b=d4IsFeZNWIZkG+JVnAlEQ696nL4TEZRibq5ax3wq+0PHJnV4L7MxxsNqfsIw7opoB1At+lViDbam4SeloFqAeT4i90hrG2JVyqJPNvIil57O3Sgwuf3jRXuQu+rNhpA82zxq+f9VyaenLPrwcnkGPtteYn8ppW14Dxpnrn1+KKQ=; s=default; c=relaxed/relaxed; d=seu.edu.cn; v=1; bh=5XWe7wnospZyX+YNXUD8i5AYsnEWhI919NVPHOmDrsQ=; h=date:mime-version:subject:message-id:from; Content-Type: text/plain; charset="utf-8" In lpfc_sli4_driver_resource_setup(), mboxq is allocated via mempool_alloc() but is not freed when the allocation of phba->lpfc_sg_dma_buf_pool or phba->lpfc_cmd_rsp_buf_pool fails. Fix this by adding mempool_free() in the error paths. Fixes: d79c9e9d4b3d ("scsi: lpfc: Support dynamic unbounded SGL lists on G7= hardware.") Co-developed-by: Jianhao Xu Signed-off-by: Jianhao Xu Signed-off-by: Zilin Guan --- drivers/scsi/lpfc/lpfc_init.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c index 1390d2b5095d..54a8d290c2e1 100644 --- a/drivers/scsi/lpfc/lpfc_init.c +++ b/drivers/scsi/lpfc/lpfc_init.c @@ -8295,6 +8295,7 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) i, 0); if (!phba->lpfc_sg_dma_buf_pool) { rc =3D -ENOMEM; + mempool_free(mboxq, phba->mbox_mem_pool); goto out_free_bsmbx; } =20 @@ -8306,6 +8307,7 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) i, 0); if (!phba->lpfc_cmd_rsp_buf_pool) { rc =3D -ENOMEM; + mempool_free(mboxq, phba->mbox_mem_pool); goto out_free_sg_dma_buf; } =20 --=20 2.34.1 From nobody Mon Feb 9 05:10:45 2026 Received: from mail-m49197.qiye.163.com (mail-m49197.qiye.163.com [45.254.49.197]) (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 63D6F325737; Tue, 30 Dec 2025 14:59:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.254.49.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767106757; cv=none; b=bbM70Io/SwrPksVFk61Q/UIO3iPFTVMMjO4ry5XLtbXQNxD31VzBTBvuVZAsNhqalBr3Hb53Ud/MfDp1qcuZTwZI5TAr7gC7RiuoRSyW+QyvfOn+lY2dJiJzF4s/oeb+QUc27t+llCwwO87MPPfaLzpjVy761XhrsMeYyasSTSM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767106757; c=relaxed/simple; bh=F1Zd7PK5qv/Q3FCmkouzGY2//UDeMu1s9JuoGaeqCTM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=afgsCEbA9dvCcLTjFjEk6DYplJ9lM4eAj/u2mhJWqy4nCY/kbvDNY4OR25FPxnhu3Qh8m7SQK2VhKVQFxgCFY59yFEvwxpeBF7umDlp33t5s/k6jOLkOTmrrNDL5oTmljMEORwD8eZM47/SPUpf5ExQBgcl3gEJkEekh/OIQpOQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn; spf=pass smtp.mailfrom=seu.edu.cn; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b=gr1PBs1T; arc=none smtp.client-ip=45.254.49.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b="gr1PBs1T" Received: from LAPTOP-N070L597.localdomain (unknown [223.112.146.162]) by smtp.qiye.163.com (Hmail) with ESMTP id 2f0b6655c; Tue, 30 Dec 2025 22:59:10 +0800 (GMT+08:00) From: Zilin Guan To: justin.tee@broadcom.com Cc: paul.ely@broadcom.com, James.Bottomley@HansenPartnership.com, martin.petersen@oracle.com, Markus.Elfring@web.de, jianhao.xu@seu.edu.cn, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Zilin Guan Subject: [PATCH v2 3/3] scsi: lpfc: Fix memory leak in lpfc_cmpl_plogi_plogi_issue() Date: Tue, 30 Dec 2025 14:58:58 +0000 Message-Id: <20251230145858.1356864-4-zilin@seu.edu.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251230145858.1356864-1-zilin@seu.edu.cn> References: <20251230145858.1356864-1-zilin@seu.edu.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-HM-Tid: 0a9b6fc529cb03a1kunmc44e99e11660c0 X-HM-MType: 10 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVlDTEMZVkkYH00ZHxodHh8dGlYeHw5VEwETFhoSFy QUDg9ZV1kYEgtZQVlJSUhVSkpJVUpPTVVKTUlZV1kWGg8SFR0UWUFZT0tIVUpLSUJDQ0xVSktLVU tZBg++ DKIM-Signature: a=rsa-sha256; b=gr1PBs1TpK6EUikSViUrU6qiJJEYGEDa8QtIRiCPZF40//EkauNOubT8ZK+81oLoqAziEa/dEYAv0yO+/j/JRC/OA+PnapmB9FIdWFDQfRRgl0RUotmaMPC3LmdEc1ZiwYhz5+Z5XX0QvYuT2IdQy/PLjKqiVyVYAjR5+lWwHDI=; s=default; c=relaxed/relaxed; d=seu.edu.cn; v=1; bh=sDdO+nwO8UMsubRHt9hljG4K4gbAZAqcwzGsSX6eUh4=; h=date:mime-version:subject:message-id:from; Content-Type: text/plain; charset="utf-8" In lpfc_cmpl_plogi_plogi_issue(), mbox is allocated via mempool_alloc() and initialized. However, if lpfc_nlp_get() fails, the mbox and its resources are not freed. Fix this by using lpfc_mbox_rsrc_cleanup() to free the mailbox and its associated resources. Fixes: 4430f7fd09ec ("scsi: lpfc: Rework locations of ndlp reference taking= ") Co-developed-by: Jianhao Xu Signed-off-by: Jianhao Xu Signed-off-by: Zilin Guan --- drivers/scsi/lpfc/lpfc_nportdisc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/lpfc/lpfc_nportdisc.c b/drivers/scsi/lpfc/lpfc_np= ortdisc.c index 8240d59f4120..e81640223276 100644 --- a/drivers/scsi/lpfc/lpfc_nportdisc.c +++ b/drivers/scsi/lpfc/lpfc_nportdisc.c @@ -1505,8 +1505,10 @@ lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport, } =20 mbox->ctx_ndlp =3D lpfc_nlp_get(ndlp); - if (!mbox->ctx_ndlp) + if (!mbox->ctx_ndlp) { + lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED); goto out; + } =20 mbox->vport =3D vport; if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) --=20 2.34.1