media: bt878: check register mapping in probe
PATCH 1/1 media: bt878: check register mapping in probe
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.
--- drivers/media/pci/bt8xx/bt878.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/media/pci/bt8xx/bt878.c +10 -0
@@ -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:
Signature · 1 line
2.51.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Race condition in bt878_probe due to unprotected global variable bt878_num --
commit 5c524e09ca816b9e46cc6d10e5292d06fb75ca23
Author: Ruoyu Wang <[email protected]>
media: bt878: check register mapping in probe
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. This patch adds a check for the mapping before touching the registers, and unmaps it on later probe failures.
drivers/media/pci/bt8xx/bt878.c static int bt878_probe(struct pci_dev *dev, const struct pci_device_id *pci_id) · line 447
Quoted 8 lines
drivers/media/pci/bt8xx/bt878.c +0
-0@@ -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 );
[Severity: High]
This isn't a bug introduced by this patch, but looking at how bt is assigned earlier in bt878_probe():
bt = &bt878[bt878_num]; bt->dev = dev; bt->nr = bt878_num;
Could this cause a race condition since the global bt878_num counter and bt878 array are modified without any locking?
If multiple bt878 devices are bound simultaneously (e.g. via concurrent userspace sysfs bind writes), multiple threads could read the same bt878_num index and concurrently overwrite the same bt878[bt878_num] element.
Could this lead to resource leaks (like losing the ioremap pointer assigned here) or memory corruption when devices process interrupts using clobbered state?
Quoted 7 lines
drivers/media/pci/bt8xx/bt878.c +4
-0+if (!bt->bt878_mem) { + result = -ENOMEM ; + goto fail1; + }#endif /* clear interrupt mask */
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1