public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] media: saa7164: add missing ioremap error handling
@ 2026-03-12 13:32 Wang Jun
  2026-03-12 15:28 ` Markus Elfring
  0 siblings, 1 reply; 12+ messages in thread
From: Wang Jun @ 2026-03-12 13:32 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Wang Jun, linux-media, linux-kernel
  Cc: gszhai, 25125332, 25125283, 23120469

Add checks for ioremap return values in saa7164_dev_setup(). If
ioremap for BAR0 or BAR2 fails, release the already allocated PCI
memory regions, remove the device from the global list, decrement
the device count, and return -ENODEV.

This prevents potential null pointer dereferences and ensures proper
cleanup on memory mapping failures.

Signed-off-by: Wang Jun <1742789905@qq.com>
---
 drivers/media/pci/saa7164/saa7164-core.c | 29 ++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/drivers/media/pci/saa7164/saa7164-core.c b/drivers/media/pci/saa7164/saa7164-core.c
index a8a004f28ca0..dc68d7cac7cf 100644
--- a/drivers/media/pci/saa7164/saa7164-core.c
+++ b/drivers/media/pci/saa7164/saa7164-core.c
@@ -998,9 +998,21 @@ static int saa7164_dev_setup(struct saa7164_dev *dev)
 	/* PCI/e allocations */
 	dev->lmmio = ioremap(pci_resource_start(dev->pci, 0),
 			     pci_resource_len(dev->pci, 0));
+	if (!dev->lmmio) {
+		dev_err(&dev->pci->dev,
+				"failed to remap MMIO memory @ 0x%llx\n",
+			(u64)pci_resource_start(dev->pci, 0));
+		goto err_ioremap;
+	}
 
 	dev->lmmio2 = ioremap(pci_resource_start(dev->pci, 2),
 			     pci_resource_len(dev->pci, 2));
+	if (!dev->lmmio2) {
+		dev_err(&dev->pci->dev,
+				"failed to remap MMIO memory @ 0x%llx\n",
+			(u64)pci_resource_start(dev->pci, 2));
+		goto err_ioremap2;
+	}
 
 	dev->bmmio = (u8 __iomem *)dev->lmmio;
 	dev->bmmio2 = (u8 __iomem *)dev->lmmio2;
@@ -1019,6 +1031,23 @@ static int saa7164_dev_setup(struct saa7164_dev *dev)
 	saa7164_pci_quirks(dev);
 
 	return 0;
+
+err_ioremap2:
+	iounmap(dev->lmmio);
+err_ioremap:
+	/* Release the PCI memory regions allocated in get_resources() */
+	release_mem_region(pci_resource_start(dev->pci, 0),
+					   pci_resource_len(dev->pci, 0));
+	release_mem_region(pci_resource_start(dev->pci, 2),
+					   pci_resource_len(dev->pci, 2));
+
+	/* Remove from device list and decrement count */
+	mutex_lock(&devlist);
+	list_del(&dev->devlist);
+	mutex_unlock(&devlist);
+	saa7164_devcount--;
+
+	return -ENODEV;
 }
 
 static void saa7164_dev_unregister(struct saa7164_dev *dev)
-- 
2.43.0


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

end of thread, other threads:[~2026-03-16 12:25 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-12 13:32 [PATCH v3] media: saa7164: add missing ioremap error handling Wang Jun
2026-03-12 15:28 ` Markus Elfring
2026-03-13  8:08   ` [PATCH v4 0/1] media: saa7164: add ioremap return checks and cleanups Wang Jun
     [not found]   ` <20260313080845.169663-1-1742789905@qq.com>
2026-03-13  8:08     ` [PATCH v4] " Wang Jun
2026-03-16  0:48   ` [PATCH v5 0/1] " Wang Jun
     [not found]   ` <20260316004854.1711-1-1742789905@qq.com>
2026-03-16  0:48     ` [PATCH v5 1/1] " Wang Jun
2026-03-16  6:09   ` [PATCH v5 0/1] " Wang Jun
     [not found]   ` <20260316060940.9659-1-1742789905@qq.com>
2026-03-16  6:09     ` [PATCH v5] " Wang Jun
2026-03-16  9:16   ` [PATCH v6 0/1] " Wang Jun
     [not found]   ` <20260316091649.14827-1-1742789905@qq.com>
2026-03-16  9:16     ` [PATCH v6 1/1] " Wang Jun
2026-03-16 12:24   ` [PATCH v7 0/1] " Wang Jun
     [not found]   ` <20260316122403.23337-1-1742789905@qq.com>
2026-03-16 12:24     ` [PATCH v7 1/1] " Wang Jun

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox