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

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linux Kernel Mailing List
Date: Saturday, May 2, 2009 - 5:03 pm

Gitweb:     http://git.kernel.org/linus/da1b94e6a68e1bdeb9cdda016cceb17228b37d25
Commit:     da1b94e6a68e1bdeb9cdda016cceb17228b37d25
Parent:     091069740304c979f957ceacec39c461d0192158
Author:     Santosh Shilimkar <santosh.shilimkar@ti.com>
AuthorDate: Thu Apr 23 11:10:40 2009 -0700
Committer:  Tony Lindgren <tony@atomide.com>
CommitDate: Thu Apr 23 11:10:40 2009 -0700

    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: Santosh Shilimkar <santosh.shilimkar@ti.com>
    Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 arch/arm/plat-omap/dma.c |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/arch/arm/plat-omap/dma.c b/arch/arm/plat-omap/dma.c
index 21cc014..7fc8c04 100644
--- a/arch/arm/plat-omap/dma.c
+++ b/arch/arm/plat-omap/dma.c
@@ -760,19 +760,12 @@ void omap_free_dma(int lch)
 {
 	unsigned long flags;
 
-	spin_lock_irqsave(&dma_chan_lock, flags);
 	if (dma_chan[lch].dev_id == -1) {
 		pr_err("omap_dma: trying to free unallocated DMA channel %d\n",
 		       lch);
-		spin_unlock_irqrestore(&dma_chan_lock, flags);
 		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()) {
 		/* Disable all DMA interrupts for the channel. */
 		dma_write(0, CICR(lch));
@@ -798,6 +791,12 @@ void omap_free_dma(int lch)
 		dma_write(0, CCR(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);
 
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
ARM: OMAP: Fix for possible race condition in omap_free_dma(), Linux Kernel Mailing ..., (Sat May 2, 5:03 pm)