Skip to content

Commit dc8e483

Browse files
rafaelmsoaresmartinkpetersen
authored andcommitted
scsi: lpfc: Fix memory leak in lpfc_create_port()
Commit 5e63330 ("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: 5e63330 ("scsi: lpfc: vmid: Add support for VMID in mailbox command") Signed-off-by: Rafael Mendonca <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: James Smart <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 2331ce6 commit dc8e483

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/scsi/lpfc/lpfc_init.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4812,7 +4812,7 @@ lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
48124812
rc = lpfc_vmid_res_alloc(phba, vport);
48134813

48144814
if (rc)
4815-
goto out;
4815+
goto out_put_shost;
48164816

48174817
/* Initialize all internally managed lists. */
48184818
INIT_LIST_HEAD(&vport->fc_nodes);
@@ -4830,16 +4830,17 @@ lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
48304830

48314831
error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev);
48324832
if (error)
4833-
goto out_put_shost;
4833+
goto out_free_vmid;
48344834

48354835
spin_lock_irq(&phba->port_list_lock);
48364836
list_add_tail(&vport->listentry, &phba->port_list);
48374837
spin_unlock_irq(&phba->port_list_lock);
48384838
return vport;
48394839

4840-
out_put_shost:
4840+
out_free_vmid:
48414841
kfree(vport->vmid);
48424842
bitmap_free(vport->vmid_priority_range);
4843+
out_put_shost:
48434844
scsi_host_put(shost);
48444845
out:
48454846
return NULL;

0 commit comments

Comments
 (0)