All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] scsi: lpfc: fix ioremap issues in 'lpfc_sli4_pci_mem_setup'
@ 2023-04-04  7:21 lishuchang
  2023-04-05 16:07 ` Justin Tee
  2023-04-12  1:03 ` Martin K. Petersen
  0 siblings, 2 replies; 3+ messages in thread
From: lishuchang @ 2023-04-04  7:21 UTC (permalink / raw
  To: James Smart, Dick Kennedy, James E.J. Bottomley,
	Martin K. Petersen
  Cc: hust-os-kernel-patches, Shuchang Li, James Smart, linux-scsi,
	linux-kernel

From: Shuchang Li <lishuchang@hust.edu.cn>

When if_type equals to 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 to 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 lables.

Fixes: 1351e69fc6db ("scsi: lpfc: Add push-to-adapter support to sli4")
Signed-off-by: Shuchang Li <lishuchang@hust.edu.cn>
---
 drivers/scsi/lpfc/lpfc_init.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 4f7485958c49..ed75230b0209 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -12026,7 +12026,7 @@ lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
 				goto out_iounmap_all;
 		} else {
 			error = -ENOMEM;
-			goto out_iounmap_all;
+			goto out_iounmap_ctrl;
 		}
 	}
 
@@ -12044,7 +12044,7 @@ lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
 			dev_err(&pdev->dev,
 			   "ioremap failed for SLI4 HBA dpp registers.\n");
 			error = -ENOMEM;
-			goto out_iounmap_ctrl;
+			goto out_iounmap_all;
 		}
 		phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p;
 	}
@@ -12069,9 +12069,11 @@ lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
 	return 0;
 
 out_iounmap_all:
-	iounmap(phba->sli4_hba.drbl_regs_memmap_p);
+	if (phba->sli4_hba.drbl_regs_memmap_p)
+		iounmap(phba->sli4_hba.drbl_regs_memmap_p);
 out_iounmap_ctrl:
-	iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
+	if (phba->sli4_hba.ctrl_regs_memmap_p)
+		iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
 out_iounmap_conf:
 	iounmap(phba->sli4_hba.conf_regs_memmap_p);
 
-- 
2.25.1


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

* Re: [PATCH v2] scsi: lpfc: fix ioremap issues in 'lpfc_sli4_pci_mem_setup'
  2023-04-04  7:21 [PATCH v2] scsi: lpfc: fix ioremap issues in 'lpfc_sli4_pci_mem_setup' lishuchang
@ 2023-04-05 16:07 ` Justin Tee
  2023-04-12  1:03 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Justin Tee @ 2023-04-05 16:07 UTC (permalink / raw
  To: lishuchang
  Cc: James Smart, Dick Kennedy, James E.J. Bottomley,
	Martin K. Petersen, hust-os-kernel-patches, James Smart,
	linux-scsi, linux-kernel, Justin Tee

Looks okay.

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

Thanks,
Justin

On Tue, Apr 4, 2023 at 12:24 AM <lishuchang@hust.edu.cn> wrote:
>
> From: Shuchang Li <lishuchang@hust.edu.cn>
>
> When if_type equals to 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 to 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 lables.
>
> Fixes: 1351e69fc6db ("scsi: lpfc: Add push-to-adapter support to sli4")
> Signed-off-by: Shuchang Li <lishuchang@hust.edu.cn>
> ---
>  drivers/scsi/lpfc/lpfc_init.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
> index 4f7485958c49..ed75230b0209 100644
> --- a/drivers/scsi/lpfc/lpfc_init.c
> +++ b/drivers/scsi/lpfc/lpfc_init.c
> @@ -12026,7 +12026,7 @@ lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
>                                 goto out_iounmap_all;
>                 } else {
>                         error = -ENOMEM;
> -                       goto out_iounmap_all;
> +                       goto out_iounmap_ctrl;
>                 }
>         }
>
> @@ -12044,7 +12044,7 @@ lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
>                         dev_err(&pdev->dev,
>                            "ioremap failed for SLI4 HBA dpp registers.\n");
>                         error = -ENOMEM;
> -                       goto out_iounmap_ctrl;
> +                       goto out_iounmap_all;
>                 }
>                 phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p;
>         }
> @@ -12069,9 +12069,11 @@ lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
>         return 0;
>
>  out_iounmap_all:
> -       iounmap(phba->sli4_hba.drbl_regs_memmap_p);
> +       if (phba->sli4_hba.drbl_regs_memmap_p)
> +               iounmap(phba->sli4_hba.drbl_regs_memmap_p);
>  out_iounmap_ctrl:
> -       iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
> +       if (phba->sli4_hba.ctrl_regs_memmap_p)
> +               iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
>  out_iounmap_conf:
>         iounmap(phba->sli4_hba.conf_regs_memmap_p);
>
> --
> 2.25.1
>

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

* Re: [PATCH v2] scsi: lpfc: fix ioremap issues in 'lpfc_sli4_pci_mem_setup'
  2023-04-04  7:21 [PATCH v2] scsi: lpfc: fix ioremap issues in 'lpfc_sli4_pci_mem_setup' lishuchang
  2023-04-05 16:07 ` Justin Tee
@ 2023-04-12  1:03 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2023-04-12  1:03 UTC (permalink / raw
  To: lishuchang
  Cc: James Smart, Dick Kennedy, James E.J. Bottomley,
	Martin K. Petersen, hust-os-kernel-patches, James Smart,
	linux-scsi, linux-kernel


> When if_type equals to 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.

Applied to 6.4/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2023-04-12  1:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-04  7:21 [PATCH v2] scsi: lpfc: fix ioremap issues in 'lpfc_sli4_pci_mem_setup' lishuchang
2023-04-05 16:07 ` Justin Tee
2023-04-12  1:03 ` Martin K. Petersen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.