[PATCH] scsi: ips: Add missing check for dma_alloc_coherent

From: Jiasheng Jiang
Date: Tue Dec 13 2022 - 22:22:10 EST


Add check for the return value of the dma_alloc_coherent in order to
avoid NULL pointer dereference.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Jiasheng Jiang <jiasheng@xxxxxxxxxxx>
---
drivers/scsi/ips.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/scsi/ips.c b/drivers/scsi/ips.c
index 16419aeec02d..26101f5b0434 100644
--- a/drivers/scsi/ips.c
+++ b/drivers/scsi/ips.c
@@ -6932,6 +6932,11 @@ ips_init_phase1(struct pci_dev *pci_dev, int *indexPtr)
if(ips_cd_boot && !ips_FlashData){
ips_FlashData = dma_alloc_coherent(&pci_dev->dev,
PAGE_SIZE << 7, &ips_flashbusaddr, GFP_KERNEL);
+ if (!ips_FlashData) {
+ IPS_PRINTK(KERN_WARNING, pci_dev,
+ "Unable to allocate ips FlashData structure\n");
+ return ips_abort_init(ha, index);
+ }
}

ha->enq = dma_alloc_coherent(&pci_dev->dev, sizeof (IPS_ENQ),
--
2.25.1