Skip to contentSkip to conversation

fsldma: Fix cookie issues

PATCH In review Steven J. Magnani 2 participants 2 messages Feb 25, 2010 – Mar 1, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 2/2 fsldma: Fix cookie issues

fsl_dma_update_completed_cookie() appears to calculate the last completed cookie incorrectly in the corner case where DMA on cookie 1 is in progress just following a cookie wrap.

---

drivers/dma/fsldma.c +4 -1
diff -uprN a/drivers/dma/fsldma.c b/drivers/dma/fsldma.c
@@ -819,8 +819,11 @@ static void fsl_dma_update_completed_coo
 	desc = to_fsl_desc(chan->ld_running.prev);
 	if (dma_is_idle(chan))
 		cookie = desc->async_tx.cookie;
-	else
+	else {
 		cookie = desc->async_tx.cookie - 1;
+		if (unlikely(cookie < DMA_MIN_COOKIE))
+			cookie = DMA_MAX_COOKIE;
+	}
 
 	chan->completed_cookie = cookie;
 
include/linux/dmaengine.h +2 -0
diff -uprN a/include/linux/dmaengine.h b/include/linux/dmaengine.h
@@ -31,6 +31,8 @@
  * if dma_cookie_t is >0 it's a DMA request cookie, <0 it's an error code
  */
 typedef s32 dma_cookie_t;
+#define DMA_MIN_COOKIE	1
+#define DMA_MAX_COOKIE	((1 << 31) - 1)
 
 #define dma_submit_error(cookie) ((cookie) < 0 ? 1 : 0)
 
#1 lore raw
Quoted 2 lines · Steven J. Magnani

fsl_dma_update_completed_cookie() appears to calculate the last completed cookie incorrectly in the corner case where DMA on cookie 1 is in progres=

s

Quoted 24 lines

just following a cookie wrap.

---
diff -uprN a/drivers/dma/fsldma.c b/drivers/dma/fsldma.c

drivers/dma/fsldma.c =A0 =A0 =A02010-02-22 11:08:41.000000000 -0600 renamed from drivers/dma/fsldma.c =A0 =A0 =A02010-02-22 11:16:36.000000000 -0600 +4 -1
@@ -819,8 +819,11 @@ static void fsl_dma_update_completed_coo
 =A0 =A0 =A0 =A0desc =3D to_fsl_desc(chan->ld_running.prev);
 =A0 =A0 =A0 =A0if (dma_is_idle(chan))
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0cookie =3D desc->async_tx.cookie;
- =A0 =A0 =A0 else
+ =A0 =A0 =A0 else {
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0cookie =3D desc->async_tx.cookie - 1;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (unlikely(cookie < DMA_MIN_COOKIE))
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 cookie =3D DMA_MAX_COOKIE;
+ =A0 =A0 =A0 }
 
 =A0 =A0 =A0 =A0chan->completed_cookie =3D cookie;
 

diff -uprN a/include/linux/dmaengine.h b/include/linux/dmaengine.h

include/linux/dmaengine.h 2010-02-22 11:18:30.000000000 -0600 renamed from include/linux/dmaengine.h 2010-02-22 11:18:11.000000000 -0600 +0 -0
@@ -31,6 +31,8 @@
Quoted 1 line

=A0* if dma_cookie_t is >0 it's a DMA request cookie, <0 it's an error co=

de

include/linux/dmaengine.h 2010-02-22 11:18:30.000000000 -0600

Quoted 5 lines

=A0*/
=A0typedef s32 dma_cookie_t;

include/linux/dmaengine.h 2010-02-22 11:18:30.000000000 -0600 renamed from include/linux/dmaengine.h 2010-02-22 11:18:11.000000000 -0600 +2 -0
+#define DMA_MIN_COOKIE 1
+#define DMA_MAX_COOKIE ((1 << 31) - 1)

This patch introduces a new warning::

drivers/dma/fsldma.c:825: warning: integer overflow in expression

I'll fix this up to use INT_MAX instead.

--
Dan

powerpc-linux-gnu-gcc --version powerpc-linux-gnu-gcc (Sourcery G++ Lite 4.2-50) 4.2.1