Skip to content

Commit dd6e494

Browse files
jhovoldvinodkoul
authored andcommitted
dmaengine: stm32: 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: df7e762 ("dmaengine: Add STM32 DMAMUX driver") Cc: stable@vger.kernel.org # 4.15 Cc: Pierre-Yves MORDRET <pierre-yves.mordret@foss.st.com> Signed-off-by: Johan Hovold <johan@kernel.org> Reviewed-by: Amelie Delaunay <amelie.delaunay@foss.st.com> Link: https://patch.msgid.link/20251117161258.10679-11-johan@kernel.org Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent 9fb4903 commit dd6e494

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

drivers/dma/stm32/stm32-dmamux.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,25 @@ static void *stm32_dmamux_route_allocate(struct of_phandle_args *dma_spec,
9090
struct stm32_dmamux_data *dmamux = platform_get_drvdata(pdev);
9191
struct stm32_dmamux *mux;
9292
u32 i, min, max;
93-
int ret;
93+
int ret = -EINVAL;
9494
unsigned long flags;
9595

9696
if (dma_spec->args_count != 3) {
9797
dev_err(&pdev->dev, "invalid number of dma mux args\n");
98-
return ERR_PTR(-EINVAL);
98+
goto err_put_pdev;
9999
}
100100

101101
if (dma_spec->args[0] > dmamux->dmamux_requests) {
102102
dev_err(&pdev->dev, "invalid mux request number: %d\n",
103103
dma_spec->args[0]);
104-
return ERR_PTR(-EINVAL);
104+
goto err_put_pdev;
105105
}
106106

107107
mux = kzalloc(sizeof(*mux), GFP_KERNEL);
108-
if (!mux)
109-
return ERR_PTR(-ENOMEM);
108+
if (!mux) {
109+
ret = -ENOMEM;
110+
goto err_put_pdev;
111+
}
110112

111113
spin_lock_irqsave(&dmamux->lock, flags);
112114
mux->chan_id = find_first_zero_bit(dmamux->dma_inuse,
@@ -133,7 +135,6 @@ static void *stm32_dmamux_route_allocate(struct of_phandle_args *dma_spec,
133135
dma_spec->np = of_parse_phandle(ofdma->of_node, "dma-masters", i - 1);
134136
if (!dma_spec->np) {
135137
dev_err(&pdev->dev, "can't get dma master\n");
136-
ret = -EINVAL;
137138
goto error;
138139
}
139140

@@ -160,13 +161,18 @@ static void *stm32_dmamux_route_allocate(struct of_phandle_args *dma_spec,
160161
dev_dbg(&pdev->dev, "Mapping DMAMUX(%u) to DMA%u(%u)\n",
161162
mux->request, mux->master, mux->chan_id);
162163

164+
put_device(&pdev->dev);
165+
163166
return mux;
164167

165168
error:
166169
clear_bit(mux->chan_id, dmamux->dma_inuse);
167170

168171
error_chan_id:
169172
kfree(mux);
173+
err_put_pdev:
174+
put_device(&pdev->dev);
175+
170176
return ERR_PTR(ret);
171177
}
172178

0 commit comments

Comments
 (0)