Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH 0/3] scsi: lpfc: Fix multiple memory leaks in error paths
@ 2025-12-29  7:15 Zilin Guan
  2025-12-29  7:15 ` [PATCH 1/3] scsi: lpfc: Fix memory leak in lpfc_config_port_post() Zilin Guan
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Zilin Guan @ 2025-12-29  7:15 UTC (permalink / raw)
  To: justin.tee
  Cc: paul.ely, James.Bottomley, martin.petersen, linux-scsi,
	linux-kernel, jianhao.xu, Zilin Guan

This series fixes three independent memory leaks in the lpfc driver.
All of them occur in error handling paths where allocated memory
was not properly freed before returning.

These issues were identified during static analysis.

Zilin Guan (3):
  scsi: lpfc: Fix memory leak in lpfc_config_port_post()
  scsi: lpfc: Fix memory leak in lpfc_sli4_driver_resource_setup()
  scsi: lpfc: Fix memory leak in lpfc_cmpl_plogi_plogi_issue()

 drivers/scsi/lpfc/lpfc_init.c      | 3 +++
 drivers/scsi/lpfc/lpfc_nportdisc.c | 4 +++-
 2 files changed, 6 insertions(+), 1 deletion(-)

-- 
2.34.1


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

* [PATCH 1/3] scsi: lpfc: Fix memory leak in lpfc_config_port_post()
  2025-12-29  7:15 [PATCH 0/3] scsi: lpfc: Fix multiple memory leaks in error paths Zilin Guan
@ 2025-12-29  7:15 ` Zilin Guan
  2025-12-29  9:09   ` Markus Elfring
  2025-12-29  7:15 ` [PATCH 2/3] scsi: lpfc: Fix memory leak in lpfc_sli4_driver_resource_setup() Zilin Guan
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 14+ messages in thread
From: Zilin Guan @ 2025-12-29  7:15 UTC (permalink / raw)
  To: justin.tee
  Cc: paul.ely, James.Bottomley, martin.petersen, linux-scsi,
	linux-kernel, jianhao.xu, Zilin Guan

In lpfc_config_port_post(), pmb is allocated via mempool_alloc() but
is not freed when lpfc_readl() fails.

Fix this by adding mempool_free() in the error path.

Fixes: 9940b97bb30d ("[SCSI] lpfc 8.3.22: Add support for PCI Adapter Failure")
Co-developed-by: Jianhao Xu <jianhao.xu@seu.edu.cn>
Signed-off-by: Jianhao Xu <jianhao.xu@seu.edu.cn>
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
---
 drivers/scsi/lpfc/lpfc_init.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index b1460b16dd91..bc2e55f6a50f 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -572,6 +572,7 @@ lpfc_config_port_post(struct lpfc_hba *phba)
 	/* Enable appropriate host interrupts */
 	if (lpfc_readl(phba->HCregaddr, &status)) {
 		spin_unlock_irq(&phba->hbalock);
+		mempool_free(pmb, phba->mbox_mem_pool);
 		return -EIO;
 	}
 	status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
-- 
2.34.1


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

* [PATCH 2/3] scsi: lpfc: Fix memory leak in lpfc_sli4_driver_resource_setup()
  2025-12-29  7:15 [PATCH 0/3] scsi: lpfc: Fix multiple memory leaks in error paths Zilin Guan
  2025-12-29  7:15 ` [PATCH 1/3] scsi: lpfc: Fix memory leak in lpfc_config_port_post() Zilin Guan
@ 2025-12-29  7:15 ` Zilin Guan
  2025-12-29  7:15 ` [PATCH 3/3] scsi: lpfc: Fix memory leak in lpfc_cmpl_plogi_plogi_issue() Zilin Guan
  2025-12-30  2:04 ` [PATCH 0/3] scsi: lpfc: Fix multiple memory leaks in error paths Justin Tee
  3 siblings, 0 replies; 14+ messages in thread
From: Zilin Guan @ 2025-12-29  7:15 UTC (permalink / raw)
  To: justin.tee
  Cc: paul.ely, James.Bottomley, martin.petersen, linux-scsi,
	linux-kernel, jianhao.xu, Zilin Guan

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 <jianhao.xu@seu.edu.cn>
Signed-off-by: Jianhao Xu <jianhao.xu@seu.edu.cn>
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
---
 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 bc2e55f6a50f..760e38b778fb 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -8297,6 +8297,7 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
 					i, 0);
 	if (!phba->lpfc_sg_dma_buf_pool) {
 		rc = -ENOMEM;
+		mempool_free(mboxq, phba->mbox_mem_pool);
 		goto out_free_bsmbx;
 	}
 
@@ -8308,6 +8309,7 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
 					i, 0);
 	if (!phba->lpfc_cmd_rsp_buf_pool) {
 		rc = -ENOMEM;
+		mempool_free(mboxq, phba->mbox_mem_pool);
 		goto out_free_sg_dma_buf;
 	}
 
-- 
2.34.1


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

* [PATCH 3/3] scsi: lpfc: Fix memory leak in lpfc_cmpl_plogi_plogi_issue()
  2025-12-29  7:15 [PATCH 0/3] scsi: lpfc: Fix multiple memory leaks in error paths Zilin Guan
  2025-12-29  7:15 ` [PATCH 1/3] scsi: lpfc: Fix memory leak in lpfc_config_port_post() Zilin Guan
  2025-12-29  7:15 ` [PATCH 2/3] scsi: lpfc: Fix memory leak in lpfc_sli4_driver_resource_setup() Zilin Guan
@ 2025-12-29  7:15 ` Zilin Guan
  2025-12-30  2:04 ` [PATCH 0/3] scsi: lpfc: Fix multiple memory leaks in error paths Justin Tee
  3 siblings, 0 replies; 14+ messages in thread
From: Zilin Guan @ 2025-12-29  7:15 UTC (permalink / raw)
  To: justin.tee
  Cc: paul.ely, James.Bottomley, martin.petersen, linux-scsi,
	linux-kernel, jianhao.xu, Zilin Guan

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 <jianhao.xu@seu.edu.cn>
Signed-off-by: Jianhao Xu <jianhao.xu@seu.edu.cn>
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
---
 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_nportdisc.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,
 		}
 
 		mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
-		if (!mbox->ctx_ndlp)
+		if (!mbox->ctx_ndlp) {
+			lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
 			goto out;
+		}
 
 		mbox->vport = vport;
 		if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
-- 
2.34.1


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

* Re: [PATCH 1/3] scsi: lpfc: Fix memory leak in lpfc_config_port_post()
  2025-12-29  7:15 ` [PATCH 1/3] scsi: lpfc: Fix memory leak in lpfc_config_port_post() Zilin Guan
@ 2025-12-29  9:09   ` Markus Elfring
  2025-12-30  6:20     ` Zilin Guan
  0 siblings, 1 reply; 14+ messages in thread
From: Markus Elfring @ 2025-12-29  9:09 UTC (permalink / raw)
  To: Jianhao Xu, Zilin Guan, linux-scsi, Justin Tee
  Cc: LKML, kernel-janitors, James Bottomley, Martin K. Petersen,
	Paul Ely

…
> Fix this by adding mempool_free() in the error path.

Please avoid duplicate source code here.
https://elixir.bootlin.com/linux/v6.19-rc2/source/drivers/scsi/lpfc/lpfc_init.c#L563-L564


See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc3#n262

Regards,
Markus

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

* Re: [PATCH 0/3] scsi: lpfc: Fix multiple memory leaks in error paths
  2025-12-29  7:15 [PATCH 0/3] scsi: lpfc: Fix multiple memory leaks in error paths Zilin Guan
                   ` (2 preceding siblings ...)
  2025-12-29  7:15 ` [PATCH 3/3] scsi: lpfc: Fix memory leak in lpfc_cmpl_plogi_plogi_issue() Zilin Guan
@ 2025-12-30  2:04 ` Justin Tee
  2025-12-30  3:05   ` Zilin Guan
  2026-01-05  9:56   ` Dan Carpenter
  3 siblings, 2 replies; 14+ messages in thread
From: Justin Tee @ 2025-12-30  2:04 UTC (permalink / raw)
  To: Zilin Guan
  Cc: justin.tee, paul.ely, James.Bottomley, martin.petersen,
	linux-scsi, linux-kernel, jianhao.xu

Hi Zilin,

For this patch set, please see and attend to Markus’ comments.

Regards,
Justin

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

* Re: [PATCH 0/3] scsi: lpfc: Fix multiple memory leaks in error paths
  2025-12-30  2:04 ` [PATCH 0/3] scsi: lpfc: Fix multiple memory leaks in error paths Justin Tee
@ 2025-12-30  3:05   ` Zilin Guan
  2026-01-05  9:56   ` Dan Carpenter
  1 sibling, 0 replies; 14+ messages in thread
From: Zilin Guan @ 2025-12-30  3:05 UTC (permalink / raw)
  To: justintee8345
  Cc: James.Bottomley, jianhao.xu, justin.tee, linux-kernel, linux-scsi,
	martin.petersen, paul.ely, zilin

On Mon, Dec 29, 2025 at 06:04:01PM -0800, Justin Tee wrote:
> Hi Zilin,
> 
> For this patch set, please see and attend to Markus’ comments.
> 
> Regards,
> Justin

Hi Justin,

Thanks for the reminder.

It seems Markus' email was accidentally filtered as spam by my mail 
server, which is why I missed it. I have retrieved it now and will 
address his comments shortly.

Best regards,
Zilin Guan

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

* Re: [PATCH 1/3] scsi: lpfc: Fix memory leak in lpfc_config_port_post()
  2025-12-29  9:09   ` Markus Elfring
@ 2025-12-30  6:20     ` Zilin Guan
  2025-12-30  7:28       ` [1/3] " Markus Elfring
  2026-01-05  9:53       ` [PATCH 1/3] " Dan Carpenter
  0 siblings, 2 replies; 14+ messages in thread
From: Zilin Guan @ 2025-12-30  6:20 UTC (permalink / raw)
  To: markus.elfring
  Cc: James.Bottomley, jianhao.xu, justin.tee, kernel-janitors,
	linux-kernel, linux-scsi, martin.petersen, paul.ely, zilin

On Mon, Dec 29, 2025 at 10:09:04AM +0100, Markus Elfring wrote:
> …
> > Fix this by adding mempool_free() in the error path.
> 
> Please avoid duplicate source code here.
> https://elixir.bootlin.com/linux/v6.19-rc2/source/drivers/scsi/lpfc/lpfc_init.c#L563-L564

Thanks for pointing this out. I will use a goto label to unify the error 
handling logic and avoid code duplication in v2.

> See also:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc3#n262
> 
> Regards,
> Markus

Regarding the stable kernel rules, do you consider this bug severe enough 
to warrant a Cc: stable tag? Since this error path is unlikely to be 
triggered during normal operation and the leak is small, I didn't think 
it was critical enough to bother the stable maintainers.

Thanks,
Zilin Guan

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

* Re: [1/3] scsi: lpfc: Fix memory leak in lpfc_config_port_post()
  2025-12-30  6:20     ` Zilin Guan
@ 2025-12-30  7:28       ` Markus Elfring
  2025-12-30  9:05         ` Zilin Guan
  2026-01-05  9:53       ` [PATCH 1/3] " Dan Carpenter
  1 sibling, 1 reply; 14+ messages in thread
From: Markus Elfring @ 2025-12-30  7:28 UTC (permalink / raw)
  To: Zilin Guan, linux-scsi
  Cc: kernel-janitors, LKML, James Bottomley, Jianhao Xu, Justin Tee,
	Martin K. Petersen, Paul Ely

>> See also:
>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc3#n262
> Regarding the stable kernel rules, do you consider this bug severe enough 
> to warrant a Cc: stable tag?

I suggest to take another look at information from previous discussions on
severity filters.


>                              Since this error path is unlikely to be 
> triggered during normal operation and the leak is small,

It seems that basic data processing was not hindered so far by the affected
function implementation.


>                                                          I didn't think 
> it was critical enough to bother the stable maintainers.

The tag “Fixes” is also an indication for related development considerations,
isn't it?

Regards,
Markus

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

* Re: [1/3] scsi: lpfc: Fix memory leak in lpfc_config_port_post()
  2025-12-30  7:28       ` [1/3] " Markus Elfring
@ 2025-12-30  9:05         ` Zilin Guan
  0 siblings, 0 replies; 14+ messages in thread
From: Zilin Guan @ 2025-12-30  9:05 UTC (permalink / raw)
  To: markus.elfring
  Cc: James.Bottomley, jianhao.xu, justin.tee, kernel-janitors,
	linux-kernel, linux-scsi, martin.petersen, paul.ely, zilin

> I suggest to take another look at information from previous discussions on
> severity filters.
> ...
> It seems that basic data processing was not hindered so far by the affected
> function implementation.
> ...
> The tag “Fixes” is also an indication for related development considerations,
> isn't it?

Thanks for the clarification.

I agree that the "Fixes" tag provides sufficient context for tracking. 
Given that the bug does not impact basic functionality, I will rely 
on the "Fixes" tag and leave the backporting decision to the stable 
maintainers' discretion, rather than explicitly adding the "Cc: stable".

I will send out v2 with the code refactoring (using goto) shortly.

Regards,
Zilin Guan

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

* Re: [PATCH 1/3] scsi: lpfc: Fix memory leak in lpfc_config_port_post()
  2025-12-30  6:20     ` Zilin Guan
  2025-12-30  7:28       ` [1/3] " Markus Elfring
@ 2026-01-05  9:53       ` Dan Carpenter
  2026-01-05 10:17         ` Dan Carpenter
  1 sibling, 1 reply; 14+ messages in thread
From: Dan Carpenter @ 2026-01-05  9:53 UTC (permalink / raw)
  To: Zilin Guan
  Cc: markus.elfring, James.Bottomley, jianhao.xu, justin.tee,
	kernel-janitors, linux-kernel, linux-scsi, martin.petersen,
	paul.ely

On Tue, Dec 30, 2025 at 06:20:08AM +0000, Zilin Guan wrote:
> On Mon, Dec 29, 2025 at 10:09:04AM +0100, Markus Elfring wrote:
> > …
> > > Fix this by adding mempool_free() in the error path.
> > 
> > Please avoid duplicate source code here.
> > https://elixir.bootlin.com/linux/v6.19-rc2/source/drivers/scsi/lpfc/lpfc_init.c#L563-L564
> 
> Thanks for pointing this out. I will use a goto label to unify the error 
> handling logic and avoid code duplication in v2.
> 
> > See also:
> > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc3#n262
> > 
> > Regards,
> > Markus
> 
> Regarding the stable kernel rules, do you consider this bug severe enough 
> to warrant a Cc: stable tag? Since this error path is unlikely to be 
> triggered during normal operation and the leak is small, I didn't think 
> it was critical enough to bother the stable maintainers.

I don't agree with either of Markus's review comments.  People have
asked him to stop reviewing code or at least to stick to pointing out
bugs or complaining about style and grammar issues but he doesn't
listen.

https://lore.kernel.org/all/2025121108-armless-earthling-7a6f@gregkh/

regards,
dan carpenter


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

* Re: [PATCH 0/3] scsi: lpfc: Fix multiple memory leaks in error paths
  2025-12-30  2:04 ` [PATCH 0/3] scsi: lpfc: Fix multiple memory leaks in error paths Justin Tee
  2025-12-30  3:05   ` Zilin Guan
@ 2026-01-05  9:56   ` Dan Carpenter
  1 sibling, 0 replies; 14+ messages in thread
From: Dan Carpenter @ 2026-01-05  9:56 UTC (permalink / raw)
  To: Justin Tee
  Cc: Zilin Guan, justin.tee, paul.ely, James.Bottomley,
	martin.petersen, linux-scsi, linux-kernel, jianhao.xu

On Mon, Dec 29, 2025 at 06:04:01PM -0800, Justin Tee wrote:
> Hi Zilin,
> 
> For this patch set, please see and attend to Markus’ comments.

You should provide a link to lore because a lot of people have blocked
Markus so we don't see it in our inboxes.

regards,
dan carpenter


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

* Re: [PATCH 1/3] scsi: lpfc: Fix memory leak in lpfc_config_port_post()
  2026-01-05  9:53       ` [PATCH 1/3] " Dan Carpenter
@ 2026-01-05 10:17         ` Dan Carpenter
  2026-01-05 10:41           ` [1/3] " Markus Elfring
  0 siblings, 1 reply; 14+ messages in thread
From: Dan Carpenter @ 2026-01-05 10:17 UTC (permalink / raw)
  To: Zilin Guan
  Cc: markus.elfring, James.Bottomley, jianhao.xu, justin.tee,
	kernel-janitors, linux-kernel, linux-scsi, martin.petersen,
	paul.ely

On Mon, Jan 05, 2026 at 12:53:40PM +0300, Dan Carpenter wrote:
> On Tue, Dec 30, 2025 at 06:20:08AM +0000, Zilin Guan wrote:
> > On Mon, Dec 29, 2025 at 10:09:04AM +0100, Markus Elfring wrote:
> > > …
> > > > Fix this by adding mempool_free() in the error path.
> > > 
> > > Please avoid duplicate source code here.
> > > https://elixir.bootlin.com/linux/v6.19-rc2/source/drivers/scsi/lpfc/lpfc_init.c#L563-L564
> > 
> > Thanks for pointing this out. I will use a goto label to unify the error 
> > handling logic and avoid code duplication in v2.
> > 
> > > See also:
> > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc3#n262
> > > 
> > > Regards,
> > > Markus
> > 
> > Regarding the stable kernel rules, do you consider this bug severe enough 
> > to warrant a Cc: stable tag? Since this error path is unlikely to be 
> > triggered during normal operation and the leak is small, I didn't think 
> > it was critical enough to bother the stable maintainers.
> 
> I don't agree with either of Markus's review comments.  People have
> asked him to stop reviewing code or at least to stick to pointing out
> bugs or complaining about style and grammar issues but he doesn't
> listen.

I meant "or at least stop complaining about style and grammar issues".

regards,
dan carpenter


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

* Re: [1/3] scsi: lpfc: Fix memory leak in lpfc_config_port_post()
  2026-01-05 10:17         ` Dan Carpenter
@ 2026-01-05 10:41           ` Markus Elfring
  0 siblings, 0 replies; 14+ messages in thread
From: Markus Elfring @ 2026-01-05 10:41 UTC (permalink / raw)
  To: Dan Carpenter, Jianhao Xu, Zilin Guan, linux-scsi
  Cc: LKML, James Bottomley, Justin Tee, Martin K. Petersen, Paul Ely

> I meant "or at least stop complaining about style and grammar issues".

Do any other contributors occasionally get also into the mood to point similar
adjustment opportunities out?

Regards,
Markus

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

end of thread, other threads:[~2026-01-05 10:41 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-29  7:15 [PATCH 0/3] scsi: lpfc: Fix multiple memory leaks in error paths Zilin Guan
2025-12-29  7:15 ` [PATCH 1/3] scsi: lpfc: Fix memory leak in lpfc_config_port_post() Zilin Guan
2025-12-29  9:09   ` Markus Elfring
2025-12-30  6:20     ` Zilin Guan
2025-12-30  7:28       ` [1/3] " Markus Elfring
2025-12-30  9:05         ` Zilin Guan
2026-01-05  9:53       ` [PATCH 1/3] " Dan Carpenter
2026-01-05 10:17         ` Dan Carpenter
2026-01-05 10:41           ` [1/3] " Markus Elfring
2025-12-29  7:15 ` [PATCH 2/3] scsi: lpfc: Fix memory leak in lpfc_sli4_driver_resource_setup() Zilin Guan
2025-12-29  7:15 ` [PATCH 3/3] scsi: lpfc: Fix memory leak in lpfc_cmpl_plogi_plogi_issue() Zilin Guan
2025-12-30  2:04 ` [PATCH 0/3] scsi: lpfc: Fix multiple memory leaks in error paths Justin Tee
2025-12-30  3:05   ` Zilin Guan
2026-01-05  9:56   ` Dan Carpenter

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