linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: lpfc: Fix memory leak in lpfc_create_port()
@ 2022-09-16  3:59 Rafael Mendonca
  2022-10-01 10:01 ` Martin K. Petersen
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Rafael Mendonca @ 2022-09-16  3:59 UTC (permalink / raw)
  To: James Smart, Dick Kennedy, James E.J. Bottomley,
	Martin K. Petersen, Gaurav Srivastava, Hannes Reinecke,
	Muneendra Kumar
  Cc: Rafael Mendonca, James Smart, linux-scsi, linux-kernel

Commit 5e633302ace1 ("scsi: lpfc: vmid: Add support for VMID in mailbox
command") introduced allocations for the VMID resources in
lpfc_create_port() after the call to scsi_host_alloc(). Upon failure on the
VMID allocations, the new code would branch to the 'out' label, which
returns NULL without unwinding anything, thus skipping the call to
scsi_host_put().

Fix the problem by creating a separate label 'out_free_vmid' to unwind the
VMID resources and make the 'out_put_shost' label call only
scsi_host_put(), as was done before the introduction of allocations for
VMID.

Fixes: 5e633302ace1 ("scsi: lpfc: vmid: Add support for VMID in mailbox command")
Signed-off-by: Rafael Mendonca <rafaelmendsr@gmail.com>
---
 drivers/scsi/lpfc/lpfc_init.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 55a1ad6eed03..6f572f0c5c45 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -4819,7 +4819,7 @@ lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
 	rc = lpfc_vmid_res_alloc(phba, vport);
 
 	if (rc)
-		goto out;
+		goto out_put_shost;
 
 	/* Initialize all internally managed lists. */
 	INIT_LIST_HEAD(&vport->fc_nodes);
@@ -4837,16 +4837,17 @@ lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
 
 	error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
 	if (error)
-		goto out_put_shost;
+		goto out_free_vmid;
 
 	spin_lock_irq(&phba->port_list_lock);
 	list_add_tail(&vport->listentry, &phba->port_list);
 	spin_unlock_irq(&phba->port_list_lock);
 	return vport;
 
-out_put_shost:
+out_free_vmid:
 	kfree(vport->vmid);
 	bitmap_free(vport->vmid_priority_range);
+out_put_shost:
 	scsi_host_put(shost);
 out:
 	return NULL;
-- 
2.34.1


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

* Re: [PATCH] scsi: lpfc: Fix memory leak in lpfc_create_port()
  2022-09-16  3:59 [PATCH] scsi: lpfc: Fix memory leak in lpfc_create_port() Rafael Mendonca
@ 2022-10-01 10:01 ` Martin K. Petersen
  2022-10-02 16:48 ` James Smart
  2022-10-18  3:52 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2022-10-01 10:01 UTC (permalink / raw)
  To: Rafael Mendonca
  Cc: James Smart, Dick Kennedy, James E.J. Bottomley,
	Martin K. Petersen, Gaurav Srivastava, Hannes Reinecke,
	Muneendra Kumar, James Smart, linux-scsi, linux-kernel


> Commit 5e633302ace1 ("scsi: lpfc: vmid: Add support for VMID in mailbox
> command") introduced allocations for the VMID resources in
> lpfc_create_port() after the call to scsi_host_alloc(). Upon failure on the
> VMID allocations, the new code would branch to the 'out' label, which
> returns NULL without unwinding anything, thus skipping the call to
> scsi_host_put().

Broadcom: Please review, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* Re: [PATCH] scsi: lpfc: Fix memory leak in lpfc_create_port()
  2022-09-16  3:59 [PATCH] scsi: lpfc: Fix memory leak in lpfc_create_port() Rafael Mendonca
  2022-10-01 10:01 ` Martin K. Petersen
@ 2022-10-02 16:48 ` James Smart
  2022-10-18  3:52 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: James Smart @ 2022-10-02 16:48 UTC (permalink / raw)
  To: Rafael Mendonca, James Smart, Dick Kennedy, James E.J. Bottomley,
	Martin K. Petersen, Gaurav Srivastava, Hannes Reinecke,
	Muneendra Kumar
  Cc: linux-scsi, linux-kernel

On 9/15/2022 8:59 PM, Rafael Mendonca wrote:
> Commit 5e633302ace1 ("scsi: lpfc: vmid: Add support for VMID in mailbox
> command") introduced allocations for the VMID resources in
> lpfc_create_port() after the call to scsi_host_alloc(). Upon failure on the
> VMID allocations, the new code would branch to the 'out' label, which
> returns NULL without unwinding anything, thus skipping the call to
> scsi_host_put().
> 
> Fix the problem by creating a separate label 'out_free_vmid' to unwind the
> VMID resources and make the 'out_put_shost' label call only
> scsi_host_put(), as was done before the introduction of allocations for
> VMID.
> 
> Fixes: 5e633302ace1 ("scsi: lpfc: vmid: Add support for VMID in mailbox command")
> Signed-off-by: Rafael Mendonca <rafaelmendsr@gmail.com>
> ---
>   drivers/scsi/lpfc/lpfc_init.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
> 

Looks good

Reviewed-by: James Smart <jsmart2021@gmail.com>

-- james



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

* Re: [PATCH] scsi: lpfc: Fix memory leak in lpfc_create_port()
  2022-09-16  3:59 [PATCH] scsi: lpfc: Fix memory leak in lpfc_create_port() Rafael Mendonca
  2022-10-01 10:01 ` Martin K. Petersen
  2022-10-02 16:48 ` James Smart
@ 2022-10-18  3:52 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2022-10-18  3:52 UTC (permalink / raw)
  To: Muneendra Kumar, James Smart, Rafael Mendonca, Dick Kennedy,
	Hannes Reinecke, Gaurav Srivastava, James E.J. Bottomley
  Cc: Martin K . Petersen, James Smart, linux-kernel, linux-scsi

On Fri, 16 Sep 2022 00:59:07 -0300, Rafael Mendonca wrote:

> Commit 5e633302ace1 ("scsi: lpfc: vmid: Add support for VMID in mailbox
> command") introduced allocations for the VMID resources in
> lpfc_create_port() after the call to scsi_host_alloc(). Upon failure on the
> VMID allocations, the new code would branch to the 'out' label, which
> returns NULL without unwinding anything, thus skipping the call to
> scsi_host_put().
> 
> [...]

Applied to 6.1/scsi-fixes, thanks!

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

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2022-10-18  3:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-16  3:59 [PATCH] scsi: lpfc: Fix memory leak in lpfc_create_port() Rafael Mendonca
2022-10-01 10:01 ` Martin K. Petersen
2022-10-02 16:48 ` James Smart
2022-10-18  3:52 ` 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;
as well as URLs for NNTP newsgroup(s).