diff options
Diffstat (limited to 'drivers/spi/spi.c')
-rw-r--r-- | drivers/spi/spi.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 3ecedccdb96c..cdb242de901d 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c | |||
@@ -557,6 +557,17 @@ int spi_write_then_read(struct spi_device *spi, | |||
557 | if ((n_tx + n_rx) > SPI_BUFSIZ) | 557 | if ((n_tx + n_rx) > SPI_BUFSIZ) |
558 | return -EINVAL; | 558 | return -EINVAL; |
559 | 559 | ||
560 | spi_message_init(&message); | ||
561 | memset(x, 0, sizeof x); | ||
562 | if (n_tx) { | ||
563 | x[0].len = n_tx; | ||
564 | spi_message_add_tail(&x[0], &message); | ||
565 | } | ||
566 | if (n_rx) { | ||
567 | x[1].len = n_rx; | ||
568 | spi_message_add_tail(&x[1], &message); | ||
569 | } | ||
570 | |||
560 | /* ... unless someone else is using the pre-allocated buffer */ | 571 | /* ... unless someone else is using the pre-allocated buffer */ |
561 | if (down_trylock(&lock)) { | 572 | if (down_trylock(&lock)) { |
562 | local_buf = kmalloc(SPI_BUFSIZ, GFP_KERNEL); | 573 | local_buf = kmalloc(SPI_BUFSIZ, GFP_KERNEL); |
@@ -565,18 +576,11 @@ int spi_write_then_read(struct spi_device *spi, | |||
565 | } else | 576 | } else |
566 | local_buf = buf; | 577 | local_buf = buf; |
567 | 578 | ||
568 | memset(x, 0, sizeof x); | ||
569 | |||
570 | memcpy(local_buf, txbuf, n_tx); | 579 | memcpy(local_buf, txbuf, n_tx); |
571 | x[0].tx_buf = local_buf; | 580 | x[0].tx_buf = local_buf; |
572 | x[0].len = n_tx; | ||
573 | |||
574 | x[1].rx_buf = local_buf + n_tx; | 581 | x[1].rx_buf = local_buf + n_tx; |
575 | x[1].len = n_rx; | ||
576 | 582 | ||
577 | /* do the i/o */ | 583 | /* do the i/o */ |
578 | message.transfers = x; | ||
579 | message.n_transfer = ARRAY_SIZE(x); | ||
580 | status = spi_sync(spi, &message); | 584 | status = spi_sync(spi, &message); |
581 | if (status == 0) { | 585 | if (status == 0) { |
582 | memcpy(rxbuf, x[1].rx_buf, n_rx); | 586 | memcpy(rxbuf, x[1].rx_buf, n_rx); |