mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] scsi: lpfc: Fix memory leak in lpfc_sli4_driver_resource_setup()
@ 2026-07-07  6:53 Abdun Nihaal
  2026-07-07 17:00 ` Justin Tee
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Abdun Nihaal @ 2026-07-07  6:53 UTC (permalink / raw)
  To: justin.tee
  Cc: Abdun Nihaal, paul.ely, James.Bottomley, martin.petersen,
	linux-scsi, linux-kernel, stable

The memory allocated for mboxq using mempool_alloc() is not freed in
some of the early exit error paths. Fix that by moving the
mempool_free() call to an earlier point after last use.

Fixes: d79c9e9d4b3d ("scsi: lpfc: Support dynamic unbounded SGL lists on G7 hardware.")
Cc: stable@vger.kernel.org
Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in>
---
 drivers/scsi/lpfc/lpfc_init.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 82af59c913e9..23355f12fbff 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -8189,6 +8189,7 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
 		mempool_free(mboxq, phba->mbox_mem_pool);
 		goto out_free_bsmbx;
 	}
+	mempool_free(mboxq, phba->mbox_mem_pool);
 
 	/*
 	 * 1 for cmd, 1 for rsp, NVME adds an extra one
@@ -8311,8 +8312,6 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
 		goto out_free_sg_dma_buf;
 	}
 
-	mempool_free(mboxq, phba->mbox_mem_pool);
-
 	/* Verify OAS is supported */
 	lpfc_sli4_oas_verify(phba);
 
-- 
2.43.0


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

* Re: [PATCH] scsi: lpfc: Fix memory leak in lpfc_sli4_driver_resource_setup()
  2026-07-07  6:53 [PATCH] scsi: lpfc: Fix memory leak in lpfc_sli4_driver_resource_setup() Abdun Nihaal
@ 2026-07-07 17:00 ` Justin Tee
  2026-07-10 18:00 ` Markus Elfring
  2026-07-13  2:32 ` Martin K. Petersen
  2 siblings, 0 replies; 5+ messages in thread
From: Justin Tee @ 2026-07-07 17:00 UTC (permalink / raw)
  To: Abdun Nihaal
  Cc: justin.tee, paul.ely, James.Bottomley, martin.petersen,
	linux-scsi, linux-kernel, stable

Reviewed-by: Justin Tee <justin.tee@broadcom.com>

Regards,
Justin

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

* Re: [PATCH] scsi: lpfc: Fix memory leak in lpfc_sli4_driver_resource_setup()
  2026-07-07  6:53 [PATCH] scsi: lpfc: Fix memory leak in lpfc_sli4_driver_resource_setup() Abdun Nihaal
  2026-07-07 17:00 ` Justin Tee
@ 2026-07-10 18:00 ` Markus Elfring
  2026-07-10 21:20   ` Justin Tee
  2026-07-13  2:32 ` Martin K. Petersen
  2 siblings, 1 reply; 5+ messages in thread
From: Markus Elfring @ 2026-07-10 18:00 UTC (permalink / raw)
  To: Abdun Nihaal, linux-scsi, Justin Tee
  Cc: stable, LKML, James Bottomley, Martin K. Petersen, Paul Ely

> The memory allocated for mboxq using mempool_alloc() is not freed in
> some of the early exit error paths. Fix that by moving the
> mempool_free() call to an earlier point after last use.
> +++ b/drivers/scsi/lpfc/lpfc_init.c
> @@ -8189,6 +8189,7 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
>  		mempool_free(mboxq, phba->mbox_mem_pool);
>  		goto out_free_bsmbx;
>  	}
> +	mempool_free(mboxq, phba->mbox_mem_pool);
>  
>  	/*
>  	 * 1 for cmd, 1 for rsp, NVME adds an extra one

How do you think about to move the mempool_free() call directly behind
the statement “rc = lpfc_get_sli4_parameters(phba, mboxq);”?
https://elixir.bootlin.com/linux/v7.2-rc2/source/drivers/scsi/lpfc/lpfc_init.c#L8180-L8191

Regards,
Markus

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

* Re: [PATCH] scsi: lpfc: Fix memory leak in lpfc_sli4_driver_resource_setup()
  2026-07-10 18:00 ` Markus Elfring
@ 2026-07-10 21:20   ` Justin Tee
  0 siblings, 0 replies; 5+ messages in thread
From: Justin Tee @ 2026-07-10 21:20 UTC (permalink / raw)
  To: Markus Elfring
  Cc: Abdun Nihaal, linux-scsi, Justin Tee, stable, LKML,
	James Bottomley, Martin K. Petersen, Paul Ely

Hi Markus,

> How do you think about to move the mempool_free() call directly behind
> the statement “rc = lpfc_get_sli4_parameters(phba, mboxq);”?
> https://elixir.bootlin.com/linux/v7.2-rc2/source/drivers/scsi/lpfc/lpfc_init.c#L8180-L8191

I think you mean after the "rc = lpfc_get_sli4_parameters(phba,
mboxq);" statement, but yes completely agreed that suggestion is
better.

Thanks,
Justin

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

* Re: [PATCH] scsi: lpfc: Fix memory leak in lpfc_sli4_driver_resource_setup()
  2026-07-07  6:53 [PATCH] scsi: lpfc: Fix memory leak in lpfc_sli4_driver_resource_setup() Abdun Nihaal
  2026-07-07 17:00 ` Justin Tee
  2026-07-10 18:00 ` Markus Elfring
@ 2026-07-13  2:32 ` Martin K. Petersen
  2 siblings, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2026-07-13  2:32 UTC (permalink / raw)
  To: justin.tee, Abdun Nihaal
  Cc: Martin K . Petersen, paul.ely, James.Bottomley, linux-scsi,
	linux-kernel, stable

On Tue, 07 Jul 2026 12:23:02 +0530, Abdun Nihaal wrote:

> The memory allocated for mboxq using mempool_alloc() is not freed in
> some of the early exit error paths. Fix that by moving the
> mempool_free() call to an earlier point after last use.
> 
> 

Applied to 7.2/scsi-fixes, thanks!

[1/1] scsi: lpfc: Fix memory leak in lpfc_sli4_driver_resource_setup()
      https://git.kernel.org/mkp/scsi/c/1bd28625e25b

-- 
Martin K. Petersen

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

end of thread, other threads:[~2026-07-13  2:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-07  6:53 [PATCH] scsi: lpfc: Fix memory leak in lpfc_sli4_driver_resource_setup() Abdun Nihaal
2026-07-07 17:00 ` Justin Tee
2026-07-10 18:00 ` Markus Elfring
2026-07-10 21:20   ` Justin Tee
2026-07-13  2:32 ` Martin K. Petersen

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