]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
media: cx23885: add ioremap return check and cleanup
authorWang Jun <1742789905@qq.com>
Fri, 20 Mar 2026 07:04:53 +0000 (15:04 +0800)
committerHans Verkuil <hverkuil+cisco@kernel.org>
Wed, 6 May 2026 07:05:56 +0000 (09:05 +0200)
Add a check for the return value of pci_ioremap_bar()
in cx23885_dev_setup().
If ioremap for BAR0 fails, release the already allocated
PCI memory region,
decrement the device count, and return -ENODEV.

This prevents a potential null pointer dereference and
ensures proper cleanup
on memory mapping failure.

Fixes: d19770e5178a ("V4L/DVB (6150): Add CX23885/CX23887 PCIe bridge driver")
Cc: stable@vger.kernel.org
Signed-off-by: Wang Jun <1742789905@qq.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
drivers/media/pci/cx23885/cx23885-core.c

index 4a8af8b88d84d4c603144f7b00bcc85895cae24e..9b92e8db494c5953e7e6895bf4af66631069ddda 100644 (file)
@@ -1002,8 +1002,12 @@ static int cx23885_dev_setup(struct cx23885_dev *dev)
        }
 
        /* PCIe stuff */
-       dev->lmmio = ioremap(pci_resource_start(dev->pci, 0),
-                            pci_resource_len(dev->pci, 0));
+       dev->lmmio = pci_ioremap_bar(dev->pci, 0);
+       if (!dev->lmmio) {
+               dev_err(&dev->pci->dev, "CORE %s: can't ioremap MMIO memory\n",
+                       dev->name);
+               goto err_release_region;
+       }
 
        dev->bmmio = (u8 __iomem *)dev->lmmio;
 
@@ -1109,6 +1113,12 @@ static int cx23885_dev_setup(struct cx23885_dev *dev)
        }
 
        return 0;
+
+err_release_region:
+       release_mem_region(pci_resource_start(dev->pci, 0),
+                          pci_resource_len(dev->pci, 0));
+       cx23885_devcount--;
+       return -ENODEV;
 }
 
 static void cx23885_dev_unregister(struct cx23885_dev *dev)