Skip to content

Commit d9847e6

Browse files
jhovoldvinodkoul
authored andcommitted
dmaengine: lpc32xx-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: 5d318b5 ("dmaengine: Add dma router for pl08x in LPC32XX SoC") Cc: stable@vger.kernel.org # 6.12 Cc: Piotr Wojtaszczyk <piotr.wojtaszczyk@timesys.com> Signed-off-by: Johan Hovold <johan@kernel.org> Reviewed-by: Vladimir Zapolskiy <vz@mleia.com> Link: https://patch.msgid.link/20251117161258.10679-9-johan@kernel.org Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent d4d6305 commit d9847e6

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

drivers/dma/lpc32xx-dmamux.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,12 @@ static void *lpc32xx_dmamux_reserve(struct of_phandle_args *dma_spec,
9595
struct lpc32xx_dmamux_data *dmamux = platform_get_drvdata(pdev);
9696
unsigned long flags;
9797
struct lpc32xx_dmamux *mux = NULL;
98+
int ret = -EINVAL;
9899
int i;
99100

100101
if (dma_spec->args_count != 3) {
101102
dev_err(&pdev->dev, "invalid number of dma mux args\n");
102-
return ERR_PTR(-EINVAL);
103+
goto err_put_pdev;
103104
}
104105

105106
for (i = 0; i < ARRAY_SIZE(lpc32xx_muxes); i++) {
@@ -111,20 +112,20 @@ static void *lpc32xx_dmamux_reserve(struct of_phandle_args *dma_spec,
111112
if (!mux) {
112113
dev_err(&pdev->dev, "invalid mux request number: %d\n",
113114
dma_spec->args[0]);
114-
return ERR_PTR(-EINVAL);
115+
goto err_put_pdev;
115116
}
116117

117118
if (dma_spec->args[2] > 1) {
118119
dev_err(&pdev->dev, "invalid dma mux value: %d\n",
119120
dma_spec->args[1]);
120-
return ERR_PTR(-EINVAL);
121+
goto err_put_pdev;
121122
}
122123

123124
/* The of_node_put() will be done in the core for the node */
124125
dma_spec->np = of_parse_phandle(ofdma->of_node, "dma-masters", 0);
125126
if (!dma_spec->np) {
126127
dev_err(&pdev->dev, "can't get dma master\n");
127-
return ERR_PTR(-EINVAL);
128+
goto err_put_pdev;
128129
}
129130

130131
spin_lock_irqsave(&dmamux->lock, flags);
@@ -133,7 +134,8 @@ static void *lpc32xx_dmamux_reserve(struct of_phandle_args *dma_spec,
133134
dev_err(dev, "dma request signal %d busy, routed to %s\n",
134135
mux->signal, mux->muxval ? mux->name_sel1 : mux->name_sel1);
135136
of_node_put(dma_spec->np);
136-
return ERR_PTR(-EBUSY);
137+
ret = -EBUSY;
138+
goto err_put_pdev;
137139
}
138140

139141
mux->busy = true;
@@ -148,7 +150,14 @@ static void *lpc32xx_dmamux_reserve(struct of_phandle_args *dma_spec,
148150
dev_dbg(dev, "dma request signal %d routed to %s\n",
149151
mux->signal, mux->muxval ? mux->name_sel1 : mux->name_sel1);
150152

153+
put_device(&pdev->dev);
154+
151155
return mux;
156+
157+
err_put_pdev:
158+
put_device(&pdev->dev);
159+
160+
return ERR_PTR(ret);
152161
}
153162

154163
static int lpc32xx_dmamux_probe(struct platform_device *pdev)

0 commit comments

Comments
 (0)