Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: df7e762db5f6 ("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>

authored by

Johan Hovold and committed by
Vinod Koul
dd6e4943 9fb49032

+12 -6
+12 -6
drivers/dma/stm32/stm32-dmamux.c
··· 90 90 struct stm32_dmamux_data *dmamux = platform_get_drvdata(pdev); 91 91 struct stm32_dmamux *mux; 92 92 u32 i, min, max; 93 - int ret; 93 + int ret = -EINVAL; 94 94 unsigned long flags; 95 95 96 96 if (dma_spec->args_count != 3) { 97 97 dev_err(&pdev->dev, "invalid number of dma mux args\n"); 98 - return ERR_PTR(-EINVAL); 98 + goto err_put_pdev; 99 99 } 100 100 101 101 if (dma_spec->args[0] > dmamux->dmamux_requests) { 102 102 dev_err(&pdev->dev, "invalid mux request number: %d\n", 103 103 dma_spec->args[0]); 104 - return ERR_PTR(-EINVAL); 104 + goto err_put_pdev; 105 105 } 106 106 107 107 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 + } 110 112 111 113 spin_lock_irqsave(&dmamux->lock, flags); 112 114 mux->chan_id = find_first_zero_bit(dmamux->dma_inuse, ··· 135 133 dma_spec->np = of_parse_phandle(ofdma->of_node, "dma-masters", i - 1); 136 134 if (!dma_spec->np) { 137 135 dev_err(&pdev->dev, "can't get dma master\n"); 138 - ret = -EINVAL; 139 136 goto error; 140 137 } 141 138 ··· 161 160 dev_dbg(&pdev->dev, "Mapping DMAMUX(%u) to DMA%u(%u)\n", 162 161 mux->request, mux->master, mux->chan_id); 163 162 163 + put_device(&pdev->dev); 164 + 164 165 return mux; 165 166 166 167 error: ··· 170 167 171 168 error_chan_id: 172 169 kfree(mux); 170 + err_put_pdev: 171 + put_device(&pdev->dev); 172 + 173 173 return ERR_PTR(ret); 174 174 } 175 175