Skip to contentSkip to conversation

myrb: fixup null pointer access on myrb_cleanup()

PATCH Applied Hannes Reinecke 3 participants 4 messages May 23, 2022 – May 24, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 myrb: fixup null pointer access on myrb_cleanup()

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.

---
 drivers/scsi/myrb.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/scsi/myrb.c +8 -3
index 71585528e8db..e885c1dbf61f 100644
@@ -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) {
Signature · 1 line
2.29.2
Tested-by on v2 1/1
#1 lore raw
Quoted 43 lines · Hannes Reinecke

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.

---
 drivers/scsi/myrb.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/scsi/myrb.c +8 -4
index 71585528e8db..e885c1dbf61f 100644
@@ -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) {
--
Quoted 1 line

2.29.2

This patch works for me, Thanks!

Zheyu Ma

#2 lore raw
In reply to Hannes Reinecke

Hannes,

Quoted 4 lines

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!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#3 lore raw
In reply to Hannes Reinecke
Quoted 6 lines · Hannes Reinecke

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
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering