All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv2] myrb: fixup null pointer access on myrb_cleanup()
@ 2022-05-23 12:02 Hannes Reinecke
  2022-05-23 12:52 ` Zheyu Ma
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Hannes Reinecke @ 2022-05-23 12:02 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi, Hannes Reinecke,
	Zheyu Ma

When myrb_probe() fails the callback might not be set, so we need
to validate the 'disable_intr' callback in myrb_cleanup() to not
cause a null pointer exception. And while at it do not call
myrb_cleanup() if we cannot enable the PCI device at all.

Reported-by: Zheyu Ma <zheyuma97@gmail.com>
Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/myrb.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/myrb.c b/drivers/scsi/myrb.c
index 71585528e8db..e885c1dbf61f 100644
--- a/drivers/scsi/myrb.c
+++ b/drivers/scsi/myrb.c
@@ -1239,7 +1239,8 @@ static void myrb_cleanup(struct myrb_hba *cb)
 	myrb_unmap(cb);
 
 	if (cb->mmio_base) {
-		cb->disable_intr(cb->io_base);
+		if (cb->disable_intr)
+			cb->disable_intr(cb->io_base);
 		iounmap(cb->mmio_base);
 	}
 	if (cb->irq)
@@ -3413,9 +3414,13 @@ static struct myrb_hba *myrb_detect(struct pci_dev *pdev,
 	mutex_init(&cb->dcmd_mutex);
 	mutex_init(&cb->dma_mutex);
 	cb->pdev = pdev;
+	cb->host = shost;
 
-	if (pci_enable_device(pdev))
-		goto failure;
+	if (pci_enable_device(pdev)) {
+		dev_err(&pdev->dev, "Failed to enable PCI device\n");
+		scsi_host_put(shost);
+		return NULL;
+	}
 
 	if (privdata->hw_init == DAC960_PD_hw_init ||
 	    privdata->hw_init == DAC960_P_hw_init) {
-- 
2.29.2


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

* Re: [PATCHv2] myrb: fixup null pointer access on myrb_cleanup()
  2022-05-23 12:02 [PATCHv2] myrb: fixup null pointer access on myrb_cleanup() Hannes Reinecke
@ 2022-05-23 12:52 ` Zheyu Ma
  2022-05-24  3:24 ` Martin K. Petersen
  2022-05-24 18:11 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Zheyu Ma @ 2022-05-23 12:52 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: Martin K. Petersen, Christoph Hellwig, James Bottomley, linux-scsi

On Mon, May 23, 2022 at 8:02 PM Hannes Reinecke <hare@suse.de> wrote:
>
> When myrb_probe() fails the callback might not be set, so we need
> to validate the 'disable_intr' callback in myrb_cleanup() to not
> cause a null pointer exception. And while at it do not call
> myrb_cleanup() if we cannot enable the PCI device at all.
>
> Reported-by: Zheyu Ma <zheyuma97@gmail.com>
> Signed-off-by: Hannes Reinecke <hare@suse.de>
> ---
>  drivers/scsi/myrb.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/scsi/myrb.c b/drivers/scsi/myrb.c
> index 71585528e8db..e885c1dbf61f 100644
> --- a/drivers/scsi/myrb.c
> +++ b/drivers/scsi/myrb.c
> @@ -1239,7 +1239,8 @@ static void myrb_cleanup(struct myrb_hba *cb)
>         myrb_unmap(cb);
>
>         if (cb->mmio_base) {
> -               cb->disable_intr(cb->io_base);
> +               if (cb->disable_intr)
> +                       cb->disable_intr(cb->io_base);
>                 iounmap(cb->mmio_base);
>         }
>         if (cb->irq)
> @@ -3413,9 +3414,13 @@ static struct myrb_hba *myrb_detect(struct pci_dev *pdev,
>         mutex_init(&cb->dcmd_mutex);
>         mutex_init(&cb->dma_mutex);
>         cb->pdev = pdev;
> +       cb->host = shost;
>
> -       if (pci_enable_device(pdev))
> -               goto failure;
> +       if (pci_enable_device(pdev)) {
> +               dev_err(&pdev->dev, "Failed to enable PCI device\n");
> +               scsi_host_put(shost);
> +               return NULL;
> +       }
>
>         if (privdata->hw_init == DAC960_PD_hw_init ||
>             privdata->hw_init == DAC960_P_hw_init) {
> --
> 2.29.2

This patch works for me, Thanks!

Tested-by: Zheyu Ma <zheyuma97@gmail.com>

Zheyu Ma

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

* Re: [PATCHv2] myrb: fixup null pointer access on myrb_cleanup()
  2022-05-23 12:02 [PATCHv2] myrb: fixup null pointer access on myrb_cleanup() Hannes Reinecke
  2022-05-23 12:52 ` Zheyu Ma
@ 2022-05-24  3:24 ` Martin K. Petersen
  2022-05-24 18:11 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2022-05-24  3:24 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: Martin K. Petersen, Christoph Hellwig, James Bottomley,
	linux-scsi, Zheyu Ma


Hannes,

> When myrb_probe() fails the callback might not be set, so we need
> to validate the 'disable_intr' callback in myrb_cleanup() to not
> cause a null pointer exception. And while at it do not call
> myrb_cleanup() if we cannot enable the PCI device at all.

Applied to 5.19/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* Re: [PATCHv2] myrb: fixup null pointer access on myrb_cleanup()
  2022-05-23 12:02 [PATCHv2] myrb: fixup null pointer access on myrb_cleanup() Hannes Reinecke
  2022-05-23 12:52 ` Zheyu Ma
  2022-05-24  3:24 ` Martin K. Petersen
@ 2022-05-24 18:11 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2022-05-24 18:11 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: Martin K . Petersen, linux-scsi, Zheyu Ma, Christoph Hellwig,
	James Bottomley

On Mon, 23 May 2022 14:02:44 +0200, Hannes Reinecke wrote:

> When myrb_probe() fails the callback might not be set, so we need
> to validate the 'disable_intr' callback in myrb_cleanup() to not
> cause a null pointer exception. And while at it do not call
> myrb_cleanup() if we cannot enable the PCI device at all.
> 
> 

Applied to 5.19/scsi-queue, thanks!

[1/1] myrb: fixup null pointer access on myrb_cleanup()
      https://git.kernel.org/mkp/scsi/c/f9f0a46141e2

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2022-05-24 18:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-23 12:02 [PATCHv2] myrb: fixup null pointer access on myrb_cleanup() Hannes Reinecke
2022-05-23 12:52 ` Zheyu Ma
2022-05-24  3:24 ` Martin K. Petersen
2022-05-24 18:11 ` 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.