Skip to content

Commit 91a0c0c

Browse files
Shuchang Limartinkpetersen
authored andcommitted
scsi: lpfc: Fix ioremap issues in lpfc_sli4_pci_mem_setup()
When if_type equals zero and pci_resource_start(pdev, PCI_64BIT_BAR4) returns false, drbl_regs_memmap_p is not remapped. This passes a NULL pointer to iounmap(), which can trigger a WARN() on certain arches. When if_type equals six and pci_resource_start(pdev, PCI_64BIT_BAR4) returns true, drbl_regs_memmap_p may has been remapped and ctrl_regs_memmap_p is not remapped. This is a resource leak and passes a NULL pointer to iounmap(). To fix these issues, we need to add null checks before iounmap(), and change some goto labels. Fixes: 1351e69 ("scsi: lpfc: Add push-to-adapter support to sli4") Signed-off-by: Shuchang Li <lishuchang@hust.edu.cn> Link: https://lore.kernel.org/r/20230404072133.1022-1-lishuchang@hust.edu.cn Reviewed-by: Justin Tee <justin.tee@broadcom.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 85140ba commit 91a0c0c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/scsi/lpfc/lpfc_init.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12024,7 +12024,7 @@ lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
1202412024
goto out_iounmap_all;
1202512025
} else {
1202612026
error = -ENOMEM;
12027-
goto out_iounmap_all;
12027+
goto out_iounmap_ctrl;
1202812028
}
1202912029
}
1203012030

@@ -12042,7 +12042,7 @@ lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
1204212042
dev_err(&pdev->dev,
1204312043
"ioremap failed for SLI4 HBA dpp registers.\n");
1204412044
error = -ENOMEM;
12045-
goto out_iounmap_ctrl;
12045+
goto out_iounmap_all;
1204612046
}
1204712047
phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p;
1204812048
}
@@ -12067,9 +12067,11 @@ lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
1206712067
return 0;
1206812068

1206912069
out_iounmap_all:
12070-
iounmap(phba->sli4_hba.drbl_regs_memmap_p);
12070+
if (phba->sli4_hba.drbl_regs_memmap_p)
12071+
iounmap(phba->sli4_hba.drbl_regs_memmap_p);
1207112072
out_iounmap_ctrl:
12072-
iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
12073+
if (phba->sli4_hba.ctrl_regs_memmap_p)
12074+
iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
1207312075
out_iounmap_conf:
1207412076
iounmap(phba->sli4_hba.conf_regs_memmap_p);
1207512077

0 commit comments

Comments
 (0)