On Sun Sep 13 22:28:08 2026 -0400, Myeonghun Pak wrote:
> cx18_setup_pci() enables the PCI device but does not disable it when
> DMA mask setup or the memory-region reservation fails. Later probe
> failure paths release the region without balancing the enable either.
> 
> Unwind the enable inside cx18_setup_pci() when that helper fails after
> enabling the device. Once setup succeeds, disable it in the probe
> cleanup after releasing the memory region. Setup failures skip that
> cleanup, so each successful enable is balanced exactly once.
> 
> Keep the existing error codes and normal removal path unchanged.
> 
> This issue was identified during our ongoing static-analysis research
> while reviewing kernel code.
> 
> Fixes: 1c1e45d17b66 ("V4L/DVB (7786): cx18: new driver for the Conexant 
> CX23418 MPEG encoder chip")
> Cc: [email protected]
> Co-developed-by: Ijae Kim <[email protected]>
> Signed-off-by: Ijae Kim <[email protected]>
> Signed-off-by: Myeonghun Pak <[email protected]>
> Assisted-by: OpenAI:GPT-5.6
> Signed-off-by: Hans Verkuil <[email protected]>

Patch committed.

Thanks,
Hans Verkuil

 drivers/media/pci/cx18/cx18-driver.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

---

diff --git a/drivers/media/pci/cx18/cx18-driver.c 
b/drivers/media/pci/cx18/cx18-driver.c
index 214fac7af61e..ac90ce6cd044 100644
--- a/drivers/media/pci/cx18/cx18-driver.c
+++ b/drivers/media/pci/cx18/cx18-driver.c
@@ -805,12 +805,12 @@ static int cx18_setup_pci(struct cx18 *cx, struct pci_dev 
*pci_dev,
        }
        if (dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(32))) {
                CX18_ERR("No suitable DMA available, card %d\n", cx->instance);
-               return -EIO;
+               goto err_disable_device;
        }
        if (!request_mem_region(cx->base_addr, CX18_MEM_SIZE, "cx18 encoder")) {
                CX18_ERR("Cannot request encoder memory region, card %d\n",
                         cx->instance);
-               return -EIO;
+               goto err_disable_device;
        }
 
        /* Enable bus mastering and memory mapped IO for the CX23418 */
@@ -834,6 +834,10 @@ static int cx18_setup_pci(struct cx18 *cx, struct pci_dev 
*pci_dev,
                   cx->pci_dev->irq, pci_latency, (u64)cx->base_addr);
 
        return 0;
+
+err_disable_device:
+       pci_disable_device(pci_dev);
+       return -EIO;
 }
 
 static void cx18_init_subdevs(struct cx18 *cx)
@@ -1120,6 +1124,7 @@ free_map:
        cx18_iounmap(cx);
 free_mem:
        release_mem_region(cx->base_addr, CX18_MEM_SIZE);
+       pci_disable_device(pci_dev);
 free_workqueues:
        destroy_workqueue(cx->in_work_queue);
 err:
_______________________________________________
linuxtv-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to