diff options
author | Andrea Paterniani <a.paterniani@swapp-eng.it> | 2008-11-19 18:36:26 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-11-19 21:49:58 -0500 |
commit | 3b45d6380c392e402adc460e4ccf7d41e0caf82a (patch) | |
tree | 39526d9c921330fbdd57c864364b5ce3cdbd8751 /drivers | |
parent | b3b4dc8840a8fdbe495723d35cd976d781fd42fa (diff) |
spi_imx: full duplex dma corruption bugfix
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.
Signed-off-by: Andrea Paterniani <a.paterniani@swapp-eng.it>
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/spi/spi_imx.c | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/drivers/spi/spi_imx.c b/drivers/spi/spi_imx.c index 61ba147e384d..0b4db0ce78d6 100644 --- a/drivers/spi/spi_imx.c +++ b/drivers/spi/spi_imx.c | |||
@@ -506,20 +506,6 @@ static int map_dma_buffers(struct driver_data *drv_data) | |||
506 | if (!IS_DMA_ALIGNED(drv_data->rx) || !IS_DMA_ALIGNED(drv_data->tx)) | 506 | if (!IS_DMA_ALIGNED(drv_data->rx) || !IS_DMA_ALIGNED(drv_data->tx)) |
507 | return -1; | 507 | return -1; |
508 | 508 | ||
509 | /* NULL rx means write-only transfer and no map needed | ||
510 | since rx DMA will not be used */ | ||
511 | if (drv_data->rx) { | ||
512 | buf = drv_data->rx; | ||
513 | drv_data->rx_dma = dma_map_single( | ||
514 | dev, | ||
515 | buf, | ||
516 | drv_data->len, | ||
517 | DMA_FROM_DEVICE); | ||
518 | if (dma_mapping_error(dev, drv_data->rx_dma)) | ||
519 | return -1; | ||
520 | drv_data->rx_dma_needs_unmap = 1; | ||
521 | } | ||
522 | |||
523 | if (drv_data->tx == NULL) { | 509 | if (drv_data->tx == NULL) { |
524 | /* Read only message --> use drv_data->dummy_dma_buf for dummy | 510 | /* Read only message --> use drv_data->dummy_dma_buf for dummy |
525 | writes to achive reads */ | 511 | writes to achive reads */ |
@@ -533,18 +519,31 @@ static int map_dma_buffers(struct driver_data *drv_data) | |||
533 | buf, | 519 | buf, |
534 | drv_data->tx_map_len, | 520 | drv_data->tx_map_len, |
535 | DMA_TO_DEVICE); | 521 | DMA_TO_DEVICE); |
536 | if (dma_mapping_error(dev, drv_data->tx_dma)) { | 522 | if (dma_mapping_error(dev, drv_data->tx_dma)) |
537 | if (drv_data->rx_dma) { | ||
538 | dma_unmap_single(dev, | ||
539 | drv_data->rx_dma, | ||
540 | drv_data->len, | ||
541 | DMA_FROM_DEVICE); | ||
542 | drv_data->rx_dma_needs_unmap = 0; | ||
543 | } | ||
544 | return -1; | 523 | return -1; |
545 | } | ||
546 | drv_data->tx_dma_needs_unmap = 1; | 524 | drv_data->tx_dma_needs_unmap = 1; |
547 | 525 | ||
526 | /* NULL rx means write-only transfer and no map needed | ||
527 | * since rx DMA will not be used */ | ||
528 | if (drv_data->rx) { | ||
529 | buf = drv_data->rx; | ||
530 | drv_data->rx_dma = dma_map_single(dev, | ||
531 | buf, | ||
532 | drv_data->len, | ||
533 | DMA_FROM_DEVICE); | ||
534 | if (dma_mapping_error(dev, drv_data->rx_dma)) { | ||
535 | if (drv_data->tx_dma) { | ||
536 | dma_unmap_single(dev, | ||
537 | drv_data->tx_dma, | ||
538 | drv_data->tx_map_len, | ||
539 | DMA_TO_DEVICE); | ||
540 | drv_data->tx_dma_needs_unmap = 0; | ||
541 | } | ||
542 | return -1; | ||
543 | } | ||
544 | drv_data->rx_dma_needs_unmap = 1; | ||
545 | } | ||
546 | |||
548 | return 0; | 547 | return 0; |
549 | } | 548 | } |
550 | 549 | ||