]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
dmaengine: cv1800b-dmamux: fix device leak on route allocation
authorJohan Hovold <johan@kernel.org>
Mon, 17 Nov 2025 16:12:46 +0000 (17:12 +0100)
committerVinod Koul <vkoul@kernel.org>
Sun, 14 Dec 2025 09:17:24 +0000 (14:47 +0530)
Make sure to drop the reference taken when looking up the DMA mux
platform device during route allocation.

Note that holding a reference to a device does not prevent its driver
data from going away so there is no point in keeping the reference.

Fixes: db7d07b5add4 ("dmaengine: add driver for Sophgo CV18XX/SG200X dmamux")
Cc: stable@vger.kernel.org # 6.17
Cc: Inochi Amaoto <inochiama@gmail.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Link: https://patch.msgid.link/20251117161258.10679-5-johan@kernel.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/dma/cv1800b-dmamux.c

index e900d65956171f56e4c7d7af4c9e8f054333494c..f7a952fcbc7d7693cbd8c16095b2c90e01150d49 100644 (file)
@@ -102,11 +102,11 @@ static void *cv1800_dmamux_route_allocate(struct of_phandle_args *dma_spec,
        struct llist_node *node;
        unsigned long flags;
        unsigned int chid, devid, cpuid;
-       int ret;
+       int ret = -EINVAL;
 
        if (dma_spec->args_count != DMAMUX_NCELLS) {
                dev_err(&pdev->dev, "invalid number of dma mux args\n");
-               return ERR_PTR(-EINVAL);
+               goto err_put_pdev;
        }
 
        devid = dma_spec->args[0];
@@ -115,18 +115,18 @@ static void *cv1800_dmamux_route_allocate(struct of_phandle_args *dma_spec,
 
        if (devid > MAX_DMA_MAPPING_ID) {
                dev_err(&pdev->dev, "invalid device id: %u\n", devid);
-               return ERR_PTR(-EINVAL);
+               goto err_put_pdev;
        }
 
        if (cpuid > MAX_DMA_CPU_ID) {
                dev_err(&pdev->dev, "invalid cpu id: %u\n", cpuid);
-               return ERR_PTR(-EINVAL);
+               goto err_put_pdev;
        }
 
        dma_spec->np = of_parse_phandle(ofdma->of_node, "dma-masters", 0);
        if (!dma_spec->np) {
                dev_err(&pdev->dev, "can't get dma master\n");
-               return ERR_PTR(-EINVAL);
+               goto err_put_pdev;
        }
 
        spin_lock_irqsave(&dmamux->lock, flags);
@@ -136,8 +136,6 @@ static void *cv1800_dmamux_route_allocate(struct of_phandle_args *dma_spec,
                        if (map->peripheral == devid && map->cpu == cpuid)
                                goto found;
                }
-
-               ret = -EINVAL;
                goto failed;
        } else {
                node = llist_del_first(&dmamux->free_maps);
@@ -171,12 +169,17 @@ found:
        dev_dbg(&pdev->dev, "register channel %u for req %u (cpu %u)\n",
                chid, devid, cpuid);
 
+       put_device(&pdev->dev);
+
        return map;
 
 failed:
        spin_unlock_irqrestore(&dmamux->lock, flags);
        of_node_put(dma_spec->np);
        dev_err(&pdev->dev, "errno %d\n", ret);
+err_put_pdev:
+       put_device(&pdev->dev);
+
        return ERR_PTR(ret);
 }