提交 da1b94e6 编写于 作者: S Santosh Shilimkar 提交者: Tony Lindgren

ARM: OMAP: Fix for possible race condition in omap_free_dma()

Fix the possible race condition in omap_free_dma(). Function omap_free_dma()
sets the dev_id = -1 and then accesses the channel afterwards to clear it.
But setting the dev_id=-1 makes the channel available for allocation again.
So it is possible someone else can grab it and results are unpredictable.
To avod this DMA channle is cleared first and then the dev_id = -1 is set.

Thanks to McNeil, Sean <sean.mcneil@ti.com> for ointing out this issue.
Signed-off-by: NSantosh Shilimkar <santosh.shilimkar@ti.com>
Signed-off-by: NTony Lindgren <tony@atomide.com>
上级 09106974
...@@ -760,19 +760,12 @@ void omap_free_dma(int lch) ...@@ -760,19 +760,12 @@ void omap_free_dma(int lch)
{ {
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&dma_chan_lock, flags);
if (dma_chan[lch].dev_id == -1) { if (dma_chan[lch].dev_id == -1) {
pr_err("omap_dma: trying to free unallocated DMA channel %d\n", pr_err("omap_dma: trying to free unallocated DMA channel %d\n",
lch); lch);
spin_unlock_irqrestore(&dma_chan_lock, flags);
return; return;
} }
dma_chan[lch].dev_id = -1;
dma_chan[lch].next_lch = -1;
dma_chan[lch].callback = NULL;
spin_unlock_irqrestore(&dma_chan_lock, flags);
if (cpu_class_is_omap1()) { if (cpu_class_is_omap1()) {
/* Disable all DMA interrupts for the channel. */ /* Disable all DMA interrupts for the channel. */
dma_write(0, CICR(lch)); dma_write(0, CICR(lch));
...@@ -798,6 +791,12 @@ void omap_free_dma(int lch) ...@@ -798,6 +791,12 @@ void omap_free_dma(int lch)
dma_write(0, CCR(lch)); dma_write(0, CCR(lch));
omap_clear_dma(lch); omap_clear_dma(lch);
} }
spin_lock_irqsave(&dma_chan_lock, flags);
dma_chan[lch].dev_id = -1;
dma_chan[lch].next_lch = -1;
dma_chan[lch].callback = NULL;
spin_unlock_irqrestore(&dma_chan_lock, flags);
} }
EXPORT_SYMBOL(omap_free_dma); EXPORT_SYMBOL(omap_free_dma);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册