Commit dc8e483f authored by Rafael Mendonca's avatar Rafael Mendonca Committed by Martin K. Petersen

scsi: lpfc: Fix memory leak in lpfc_create_port()

Commit 5e633302 ("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: 5e633302 ("scsi: lpfc: vmid: Add support for VMID in mailbox command")
Signed-off-by: default avatarRafael Mendonca <rafaelmendsr@gmail.com>
Link: https://lore.kernel.org/r/20220916035908.712799-1-rafaelmendsr@gmail.comReviewed-by: default avatarJames Smart <jsmart2021@gmail.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 2331ce61
...@@ -4812,7 +4812,7 @@ lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) ...@@ -4812,7 +4812,7 @@ lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
rc = lpfc_vmid_res_alloc(phba, vport); rc = lpfc_vmid_res_alloc(phba, vport);
if (rc) if (rc)
goto out; goto out_put_shost;
/* Initialize all internally managed lists. */ /* Initialize all internally managed lists. */
INIT_LIST_HEAD(&vport->fc_nodes); INIT_LIST_HEAD(&vport->fc_nodes);
...@@ -4830,16 +4830,17 @@ lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) ...@@ -4830,16 +4830,17 @@ lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
if (error) if (error)
goto out_put_shost; goto out_free_vmid;
spin_lock_irq(&phba->port_list_lock); spin_lock_irq(&phba->port_list_lock);
list_add_tail(&vport->listentry, &phba->port_list); list_add_tail(&vport->listentry, &phba->port_list);
spin_unlock_irq(&phba->port_list_lock); spin_unlock_irq(&phba->port_list_lock);
return vport; return vport;
out_put_shost: out_free_vmid:
kfree(vport->vmid); kfree(vport->vmid);
bitmap_free(vport->vmid_priority_range); bitmap_free(vport->vmid_priority_range);
out_put_shost:
scsi_host_put(shost); scsi_host_put(shost);
out: out:
return NULL; return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment