diff mbox series

myrb: fixup null pointer access on myrb_cleanup()

Message ID 20220522081921.105515-1-hare@suse.de
State New
Headers show
Series myrb: fixup null pointer access on myrb_cleanup() | expand

Commit Message

Hannes Reinecke May 22, 2022, 8:19 a.m. UTC
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 | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/drivers/scsi/myrb.c b/drivers/scsi/myrb.c
index 71585528e8db..f460aed2435f 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)
@@ -3414,8 +3415,11 @@  static struct myrb_hba *myrb_detect(struct pci_dev *pdev,
 	mutex_init(&cb->dma_mutex);
 	cb->pdev = pdev;
 
-	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) {