Skip to content

Commit cb64165

Browse files
committed
Merge tag 'dmaengine-fix-4.16-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/vkoul/slave-dma
Pull dmaengine fix from Vinod Koul: "One small fix for stm32-dmamux fixing buffer overflow" * tag 'dmaengine-fix-4.16-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/vkoul/slave-dma: dmaengine: stm32-dmamux: fix a potential buffer overflow
2 parents d286236 + 3e4543b commit cb64165

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/dma/stm32-dmamux.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,15 @@ static void *stm32_dmamux_route_allocate(struct of_phandle_args *dma_spec,
118118
spin_lock_irqsave(&dmamux->lock, flags);
119119
mux->chan_id = find_first_zero_bit(dmamux->dma_inuse,
120120
dmamux->dma_requests);
121-
set_bit(mux->chan_id, dmamux->dma_inuse);
122-
spin_unlock_irqrestore(&dmamux->lock, flags);
123121

124122
if (mux->chan_id == dmamux->dma_requests) {
123+
spin_unlock_irqrestore(&dmamux->lock, flags);
125124
dev_err(&pdev->dev, "Run out of free DMA requests\n");
126125
ret = -ENOMEM;
127-
goto error;
126+
goto error_chan_id;
128127
}
128+
set_bit(mux->chan_id, dmamux->dma_inuse);
129+
spin_unlock_irqrestore(&dmamux->lock, flags);
129130

130131
/* Look for DMA Master */
131132
for (i = 1, min = 0, max = dmamux->dma_reqs[i];
@@ -173,6 +174,8 @@ static void *stm32_dmamux_route_allocate(struct of_phandle_args *dma_spec,
173174

174175
error:
175176
clear_bit(mux->chan_id, dmamux->dma_inuse);
177+
178+
error_chan_id:
176179
kfree(mux);
177180
return ERR_PTR(ret);
178181
}

0 commit comments

Comments
 (0)