Skip to contentSkip to conversation

SPI -- Freescale iMX SPI controller driver

PATCH In review Andrea Paterniani 3 participants 3 messages Nov 17, 2008 – Nov 18, 2008 2 messages not in the archive

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

PATCH 1/1 SPI -- Freescale iMX SPI controller driver

Subject: [patch-2.6.28-rc5-spi_imx] arm: SPI controller driver for Freescale iMX
From: Andrea Paterniani <[email protected]>

Kernel version: linux-2.6.28-rc5.
Patch description:
Fix unsafe order in dma mapping operation.

---

diff -uprN -X linux-2.6.28-rc5/Documentation/dontdiff linux-2.6.28-rc5/drivers/spi/spi_imx.c linux-2.6.28-rc5-spi_imx/drivers/spi/spi_imx.c
--- linux-2.6.28-rc5/drivers/spi/spi_imx.c 2008-10-10
00:13:53.000000000 +0200
+++ linux-2.6.28-rc5-spi_imx/drivers/spi/spi_imx.c 2008-11-17
11:26:54.000000000 +0100
@@ -506,20 +506,6 @@ static int map_dma_buffers(struct driver

     if (!IS_DMA_ALIGNED(drv_data->rx) || !IS_DMA_ALIGNED(drv_data->tx))
         return -1;

- /* NULL rx means write-only transfer and no map needed
- since rx DMA will not be used */
- if (drv_data->rx) {
- buf = drv_data->rx;
- drv_data->rx_dma = dma_map_single(

-                    dev,
-                    buf,
-                    drv_data->len,
-                    DMA_FROM_DEVICE);

- if (dma_mapping_error(dev, drv_data->rx_dma))
- return -1;
- drv_data->rx_dma_needs_unmap = 1;
- }
-

     if (drv_data->tx == NULL) {
         /* Read only message --> use drv_data->dummy_dma_buf for dummy
            writes to achive reads */
@@ -533,18 +519,31 @@ static int map_dma_buffers(struct driver
                     buf,
                     drv_data->tx_map_len,
                     DMA_TO_DEVICE);
-    if (dma_mapping_error(dev, drv_data->tx_dma)) {
-        if (drv_data->rx_dma) {
-            dma_unmap_single(dev,
-                    drv_data->rx_dma,
-                    drv_data->len,
-                    DMA_FROM_DEVICE);
-            drv_data->rx_dma_needs_unmap = 0;
-        }
+    if (dma_mapping_error(dev, drv_data->tx_dma))
         return -1;
-    }
     drv_data->tx_dma_needs_unmap = 1;

+ /* NULL rx means write-only transfer and no map needed
+ since rx DMA will not be used */
+ if (drv_data->rx) {
+ buf = drv_data->rx;
+ drv_data->rx_dma = dma_map_single(dev,

+                        buf,
+                        drv_data->len,
+                        DMA_FROM_DEVICE);
+        if (dma_mapping_error(dev, drv_data->rx_dma)) {
+            if (drv_data->tx_dma) {
+                dma_unmap_single(dev,
+                        drv_data->tx_dma,
+                        drv_data->tx_map_len,
+                        DMA_TO_DEVICE);

+ drv_data->tx_dma_needs_unmap = 0;
+ }
+ return -1;
+ }
+ drv_data->rx_dma_needs_unmap = 1;
+ }
+

     return 0;

}

Signature · 6 lines
------------------------------------------------------------------------

-------------------------------------------------------------------
List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
FAQ:        http://www.arm.linux.org.uk/mailinglists/faq.php
Etiquette:  http://www.arm.linux.org.uk/mailinglists/etiquette.php
#2 lore raw
In reply to a message not in the archive
Quoted 1 line · Andrea Paterniani

Fix unsafe order in dma mapping operation.

This arrived horribly mangled. Can you verify that the appended patch is an appropriate un-mangled version?

======= CUT HERE
From: Andrea Paterniani <a.paterniani-03BXCEkGbFHYGGNLXY5/[email protected]>

Fix unsafe order in dma mapping operation: always flush data from the cache *BEFORE* invalidating it, to allow full duplex transfers where the same buffer may be used for both writes and reads.

---
 drivers/spi/spi_imx.c |   45 ++++++++++++++++++++++-----------------------
 1 file changed, 22 insertions(+), 23 deletions(-)
drivers/spi/spi_imx.c +22 -23
@@ -506,20 +506,6 @@ static int map_dma_buffers(struct driver
 	if (!IS_DMA_ALIGNED(drv_data->rx) || !IS_DMA_ALIGNED(drv_data->tx))
 		return -1;
 
-	/* NULL rx means write-only transfer and no map needed
-	   since rx DMA will not be used */
-	if (drv_data->rx) {
-		buf = drv_data->rx;
-		drv_data->rx_dma = dma_map_single(
-					dev,
-					buf,
-					drv_data->len,
-					DMA_FROM_DEVICE);
-		if (dma_mapping_error(dev, drv_data->rx_dma))
-			return -1;
-		drv_data->rx_dma_needs_unmap = 1;
-	}
-
 	if (drv_data->tx == NULL) {
 		/* Read only message --> use drv_data->dummy_dma_buf for dummy
 		   writes to achive reads */
@@ -533,18 +519,31 @@ static int map_dma_buffers(struct driver
 					buf,
 					drv_data->tx_map_len,
 					DMA_TO_DEVICE);
-	if (dma_mapping_error(dev, drv_data->tx_dma)) {
-		if (drv_data->rx_dma) {
-			dma_unmap_single(dev,
-					drv_data->rx_dma,
-					drv_data->len,
-					DMA_FROM_DEVICE);
-			drv_data->rx_dma_needs_unmap = 0;
-		}
+	if (dma_mapping_error(dev, drv_data->tx_dma))
 		return -1;
-	}
 	drv_data->tx_dma_needs_unmap = 1;
 
+	/* NULL rx means write-only transfer and no map needed
+	 * since rx DMA will not be used */
+	if (drv_data->rx) {
+		buf = drv_data->rx;
+		drv_data->rx_dma = dma_map_single(dev,
+						buf,
+						drv_data->len,
+						DMA_FROM_DEVICE);
+		if (dma_mapping_error(dev, drv_data->rx_dma)) {
+			if (drv_data->tx_dma) {
+				dma_unmap_single(dev,
+						drv_data->tx_dma,
+						drv_data->tx_map_len,
+						DMA_TO_DEVICE);
+				drv_data->tx_dma_needs_unmap = 0;
+			}
+			return -1;
+		}
+		drv_data->rx_dma_needs_unmap = 1;
+	}
+
 	return 0;
 }
 

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/

#4 lore raw
In reply to a message not in the archive

It's ok.
The only difference I see is a character * added a the beginning of a comment:

+ /* NULL rx means write-only transfer and no map needed
+ * since rx DMA will not be used */

should be

+ /* NULL rx means write-only transfer and no map needed
+ since rx DMA will not be used */

Regards,
- Andrea

David Brownell ha scritto:

Quoted 87 lines · Andrea Paterniani
Quoted 3 lines

Fix unsafe order in dma mapping operation.

This arrived horribly mangled. Can you verify that the appended patch is an appropriate un-mangled version?

======= CUT HERE
From: Andrea Paterniani <a.paterniani-03BXCEkGbFHYGGNLXY5/[email protected]>

Fix unsafe order in dma mapping operation: always flush data from the cache *BEFORE* invalidating it, to allow full duplex transfers where the same buffer may be used for both writes and reads.

---
 drivers/spi/spi_imx.c |   45 ++++++++++++++++++++++-----------------------
 1 file changed, 22 insertions(+), 23 deletions(-)
drivers/spi/spi_imx.c +22 -23
@@ -506,20 +506,6 @@ static int map_dma_buffers(struct driver
 	if (!IS_DMA_ALIGNED(drv_data->rx) || !IS_DMA_ALIGNED(drv_data->tx))
 		return -1;
 
-	/* NULL rx means write-only transfer and no map needed
-	   since rx DMA will not be used */
-	if (drv_data->rx) {
-		buf = drv_data->rx;
-		drv_data->rx_dma = dma_map_single(
-					dev,
-					buf,
-					drv_data->len,
-					DMA_FROM_DEVICE);
-		if (dma_mapping_error(dev, drv_data->rx_dma))
-			return -1;
-		drv_data->rx_dma_needs_unmap = 1;
-	}
-
 	if (drv_data->tx == NULL) {
 		/* Read only message --> use drv_data->dummy_dma_buf for dummy
 		   writes to achive reads */
@@ -533,18 +519,31 @@ static int map_dma_buffers(struct driver
 					buf,
 					drv_data->tx_map_len,
 					DMA_TO_DEVICE);
-	if (dma_mapping_error(dev, drv_data->tx_dma)) {
-		if (drv_data->rx_dma) {
-			dma_unmap_single(dev,
-					drv_data->rx_dma,
-					drv_data->len,
-					DMA_FROM_DEVICE);
-			drv_data->rx_dma_needs_unmap = 0;
-		}
+	if (dma_mapping_error(dev, drv_data->tx_dma))
 		return -1;
-	}
 	drv_data->tx_dma_needs_unmap = 1;
 
+	/* NULL rx means write-only transfer and no map needed
+	 * since rx DMA will not be used */
+	if (drv_data->rx) {
+		buf = drv_data->rx;
+		drv_data->rx_dma = dma_map_single(dev,
+						buf,
+						drv_data->len,
+						DMA_FROM_DEVICE);
+		if (dma_mapping_error(dev, drv_data->rx_dma)) {
+			if (drv_data->tx_dma) {
+				dma_unmap_single(dev,
+						drv_data->tx_dma,
+						drv_data->tx_map_len,
+						DMA_TO_DEVICE);
+				drv_data->tx_dma_needs_unmap = 0;
+			}
+			return -1;
+		}
+		drv_data->rx_dma_needs_unmap = 1;
+	}
+
 	return 0;
 }
 
Signature · 13 lines
------------------------------------------------------------------------

*Ing. Andrea Paterniani*

*SWAPP* - Studio Professionale
Via degli Abeti, 312 - 61100 Pesaro
Tel 0721 24256
Fax 178 220 8730

a.paterniani-03BXCEkGbFHYGGNLXY5/[email protected]
www.swapp-eng.it <mailto:%0d%0aa.paterniani-03BXCEkGbFHYGGNLXY5/[email protected]%0d%0awww.swapp-eng.it>

------------------------------------------------------------------------

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/

_______________________________________________
spi-devel-general mailing list spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/spi-devel-general