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.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index b31f4431849b..93e9de46977a 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -541,10 +541,7 @@ static void spi_complete(void *arg)
541 * Also, the caller is guaranteeing that the memory associated with the 541 * Also, the caller is guaranteeing that the memory associated with the
542 * message will not be freed before this call returns. 542 * message will not be freed before this call returns.
543 * 543 *
544 * The return value is a negative error code if the message could not be 544 * It returns zero on success, else a negative error code.
545 * submitted, else zero. When the value is zero, then message->status is
546 * also defined; it's the completion code for the transfer, either zero
547 * or a negative error code from the controller driver.
548 */ 545 */
549int spi_sync(struct spi_device *spi, struct spi_message *message) 546int spi_sync(struct spi_device *spi, struct spi_message *message)
550{ 547{
@@ -554,8 +551,10 @@ int spi_sync(struct spi_device *spi, struct spi_message *message)
554 message->complete = spi_complete; 551 message->complete = spi_complete;
555 message->context = &done; 552 message->context = &done;
556 status = spi_async(spi, message); 553 status = spi_async(spi, message);
557 if (status == 0) 554 if (status == 0) {
558 wait_for_completion(&done); 555 wait_for_completion(&done);
556 status = message->status;
557 }
559 message->context = NULL; 558 message->context = NULL;
560 return status; 559 return status;
561} 560}
@@ -589,7 +588,7 @@ int spi_write_then_read(struct spi_device *spi,
589 const u8 *txbuf, unsigned n_tx, 588 const u8 *txbuf, unsigned n_tx,
590 u8 *rxbuf, unsigned n_rx) 589 u8 *rxbuf, unsigned n_rx)
591{ 590{
592 static DECLARE_MUTEX(lock); 591 static DEFINE_MUTEX(lock);
593 592
594 int status; 593 int status;
595 struct spi_message message; 594 struct spi_message message;
@@ -615,7 +614,7 @@ int spi_write_then_read(struct spi_device *spi,
615 } 614 }
616 615
617 /* ... unless someone else is using the pre-allocated buffer */ 616 /* ... unless someone else is using the pre-allocated buffer */
618 if (down_trylock(&lock)) { 617 if (!mutex_trylock(&lock)) {
619 local_buf = kmalloc(SPI_BUFSIZ, GFP_KERNEL); 618 local_buf = kmalloc(SPI_BUFSIZ, GFP_KERNEL);
620 if (!local_buf) 619 if (!local_buf)
621 return -ENOMEM; 620 return -ENOMEM;
@@ -628,13 +627,11 @@ int spi_write_then_read(struct spi_device *spi,
628 627
629 /* do the i/o */ 628 /* do the i/o */
630 status = spi_sync(spi, &message); 629 status = spi_sync(spi, &message);
631 if (status == 0) { 630 if (status == 0)
632 memcpy(rxbuf, x[1].rx_buf, n_rx); 631 memcpy(rxbuf, x[1].rx_buf, n_rx);
633 status = message.status;
634 }
635 632
636 if (x[0].tx_buf == buf) 633 if (x[0].tx_buf == buf)
637 up(&lock); 634 mutex_unlock(&lock);
638 else 635 else
639 kfree(local_buf); 636 kfree(local_buf);
640 637