mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] media: bt878: check register mapping in probe
@ 2026-06-07  9:35 Ruoyu Wang
  0 siblings, 0 replies; only message in thread
From: Ruoyu Wang @ 2026-06-07  9:35 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: linux-media, linux-kernel, Ruoyu Wang

bt878_probe() maps the device register window and then immediately clears
the interrupt mask through btwrite(). If ioremap() fails, the register
write dereferences a NULL mapping.

Check the mapping before touching the registers, and unmap it again on
later probe failures after the IRQ or DMA buffer allocation paths fail.

Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
---
 drivers/media/pci/bt8xx/bt878.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/media/pci/bt8xx/bt878.c b/drivers/media/pci/bt8xx/bt878.c
index 62a6c4a80..245a5f0ef 100644
--- a/drivers/media/pci/bt8xx/bt878.c
+++ b/drivers/media/pci/bt8xx/bt878.c
@@ -445,6 +445,10 @@ static int bt878_probe(struct pci_dev *dev, const struct pci_device_id *pci_id)
 	bt->bt878_mem = (unsigned char *) bt->bt878_adr;
 #else
 	bt->bt878_mem = ioremap(bt->bt878_adr, 0x1000);
+	if (!bt->bt878_mem) {
+		result = -ENOMEM;
+		goto fail1;
+	}
 #endif
 
 	/* clear interrupt mask */
@@ -486,6 +490,12 @@ static int bt878_probe(struct pci_dev *dev, const struct pci_device_id *pci_id)
       fail2:
 	free_irq(bt->irq, bt);
       fail1:
+#ifndef __sparc__
+	if (bt->bt878_mem) {
+		iounmap(bt->bt878_mem);
+		bt->bt878_mem = NULL;
+	}
+#endif
 	release_mem_region(pci_resource_start(bt->dev, 0),
 			   pci_resource_len(bt->dev, 0));
       fail0:
-- 
2.51.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-06-07  9:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-07  9:35 [PATCH] media: bt878: check register mapping in probe Ruoyu Wang

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

all inboxes | Powered by JetHome®