[PATCH] scsi: elx: efct: Check return value of ioremap() when mapping BARs

Wang Jun <[email protected]>
Newsgroups org.kernel.vger.target-devel,org.kernel.vger.linux-scsi
Message-ID <[email protected]>
The driver maps PCI BAR memory using ioremap() but does not check
the return value. If ioremap() fails and returns NULL, the driver
may later dereference an invalid pointer, leading to a crash.

Add proper error handling for ioremap() failures when mapping
memory BARs during device probe.

Signed-off-by: Wang Jun <[email protected]>
---
 drivers/scsi/elx/efct/efct_driver.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/scsi/elx/efct/efct_driver.c b/drivers/scsi/elx/efct/efct_driver.c
index 1bd42f7db177..ba23d73c3ec1 100644
--- a/drivers/scsi/elx/efct/efct_driver.c
+++ b/drivers/scsi/elx/efct/efct_driver.c
@@ -528,6 +528,11 @@ efct_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 		if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) {
 			efct->reg[r] = ioremap(pci_resource_start(pdev, i),
 					       pci_resource_len(pdev, i));
+			if (!efct->reg[r]) {
+				dev_err(&pdev->dev, "Failed to ioremap BAR %d\n", i);
+				rc = -EIO;
+				goto dma_mask_out;
+			}
 			r++;
 		}
 
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.