aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/spi/spi.c')
-rw-r--r--drivers/spi/spi.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 643908b74bc0..8eba98c8ed1e 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -658,7 +658,7 @@ int spi_write_then_read(struct spi_device *spi,
658 658
659 int status; 659 int status;
660 struct spi_message message; 660 struct spi_message message;
661 struct spi_transfer x; 661 struct spi_transfer x[2];
662 u8 *local_buf; 662 u8 *local_buf;
663 663
664 /* Use preallocated DMA-safe buffer. We can't avoid copying here, 664 /* Use preallocated DMA-safe buffer. We can't avoid copying here,
@@ -669,9 +669,15 @@ int spi_write_then_read(struct spi_device *spi,
669 return -EINVAL; 669 return -EINVAL;
670 670
671 spi_message_init(&message); 671 spi_message_init(&message);
672 memset(&x, 0, sizeof x); 672 memset(x, 0, sizeof x);
673 x.len = n_tx + n_rx; 673 if (n_tx) {
674 spi_message_add_tail(&x, &message); 674 x[0].len = n_tx;
675 spi_message_add_tail(&x[0], &message);
676 }
677 if (n_rx) {
678 x[1].len = n_rx;
679 spi_message_add_tail(&x[1], &message);
680 }
675 681
676 /* ... unless someone else is using the pre-allocated buffer */ 682 /* ... unless someone else is using the pre-allocated buffer */
677 if (!mutex_trylock(&lock)) { 683 if (!mutex_trylock(&lock)) {
@@ -682,15 +688,15 @@ int spi_write_then_read(struct spi_device *spi,
682 local_buf = buf; 688 local_buf = buf;
683 689
684 memcpy(local_buf, txbuf, n_tx); 690 memcpy(local_buf, txbuf, n_tx);
685 x.tx_buf = local_buf; 691 x[0].tx_buf = local_buf;
686 x.rx_buf = local_buf; 692 x[1].rx_buf = local_buf + n_tx;
687 693
688 /* do the i/o */ 694 /* do the i/o */
689 status = spi_sync(spi, &message); 695 status = spi_sync(spi, &message);
690 if (status == 0) 696 if (status == 0)
691 memcpy(rxbuf, x.rx_buf + n_tx, n_rx); 697 memcpy(rxbuf, x[1].rx_buf, n_rx);
692 698
693 if (x.tx_buf == buf) 699 if (x[0].tx_buf == buf)
694 mutex_unlock(&lock); 700 mutex_unlock(&lock);
695 else 701 else
696 kfree(local_buf); 702 kfree(local_buf);