Skip to content

Commit d4d6305

Browse files
jhovoldvinodkoul
authored andcommitted
dmaengine: lpc18xx-dmamux: fix device leak on route allocation
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: e5f4ae8 ("dmaengine: add driver for lpc18xx dmamux") Cc: stable@vger.kernel.org # 4.3 Signed-off-by: Johan Hovold <johan@kernel.org> Reviewed-by: Vladimir Zapolskiy <vz@mleia.com> Link: https://patch.msgid.link/20251117161258.10679-8-johan@kernel.org Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent 799900f commit d4d6305

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

drivers/dma/lpc18xx-dmamux.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,30 +57,31 @@ static void *lpc18xx_dmamux_reserve(struct of_phandle_args *dma_spec,
5757
struct lpc18xx_dmamux_data *dmamux = platform_get_drvdata(pdev);
5858
unsigned long flags;
5959
unsigned mux;
60+
int ret = -EINVAL;
6061

6162
if (dma_spec->args_count != 3) {
6263
dev_err(&pdev->dev, "invalid number of dma mux args\n");
63-
return ERR_PTR(-EINVAL);
64+
goto err_put_pdev;
6465
}
6566

6667
mux = dma_spec->args[0];
6768
if (mux >= dmamux->dma_master_requests) {
6869
dev_err(&pdev->dev, "invalid mux number: %d\n",
6970
dma_spec->args[0]);
70-
return ERR_PTR(-EINVAL);
71+
goto err_put_pdev;
7172
}
7273

7374
if (dma_spec->args[1] > LPC18XX_DMAMUX_MAX_VAL) {
7475
dev_err(&pdev->dev, "invalid dma mux value: %d\n",
7576
dma_spec->args[1]);
76-
return ERR_PTR(-EINVAL);
77+
goto err_put_pdev;
7778
}
7879

7980
/* The of_node_put() will be done in the core for the node */
8081
dma_spec->np = of_parse_phandle(ofdma->of_node, "dma-masters", 0);
8182
if (!dma_spec->np) {
8283
dev_err(&pdev->dev, "can't get dma master\n");
83-
return ERR_PTR(-EINVAL);
84+
goto err_put_pdev;
8485
}
8586

8687
spin_lock_irqsave(&dmamux->lock, flags);
@@ -89,7 +90,8 @@ static void *lpc18xx_dmamux_reserve(struct of_phandle_args *dma_spec,
8990
dev_err(&pdev->dev, "dma request %u busy with %u.%u\n",
9091
mux, mux, dmamux->muxes[mux].value);
9192
of_node_put(dma_spec->np);
92-
return ERR_PTR(-EBUSY);
93+
ret = -EBUSY;
94+
goto err_put_pdev;
9395
}
9496

9597
dmamux->muxes[mux].busy = true;
@@ -106,7 +108,14 @@ static void *lpc18xx_dmamux_reserve(struct of_phandle_args *dma_spec,
106108
dev_dbg(&pdev->dev, "mapping dmamux %u.%u to dma request %u\n", mux,
107109
dmamux->muxes[mux].value, mux);
108110

111+
put_device(&pdev->dev);
112+
109113
return &dmamux->muxes[mux];
114+
115+
err_put_pdev:
116+
put_device(&pdev->dev);
117+
118+
return ERR_PTR(ret);
110119
}
111120

112121
static int lpc18xx_dmamux_probe(struct platform_device *pdev)

0 commit comments

Comments
 (0)