提交 9b938b74 编写于 作者: M Marc Pignat 提交者: Linus Torvalds

spi: simplify spi_sync() calling convention

Simplify spi_sync calling convention, eliminating the need to check both
the return value AND the message->status.  In consequence, this corrects
misbehaviours of spi_read and spi_write (which only checked the former) and
their callers.
Signed-off-by: NMarc Pignat <marc.pignat@hevs.ch>
Signed-off-by: NDavid Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 3f86f14c
...@@ -541,10 +541,7 @@ static void spi_complete(void *arg) ...@@ -541,10 +541,7 @@ static void spi_complete(void *arg)
* Also, the caller is guaranteeing that the memory associated with the * Also, the caller is guaranteeing that the memory associated with the
* message will not be freed before this call returns. * message will not be freed before this call returns.
* *
* The return value is a negative error code if the message could not be * It returns zero on success, else a negative error code.
* submitted, else zero. When the value is zero, then message->status is
* also defined; it's the completion code for the transfer, either zero
* or a negative error code from the controller driver.
*/ */
int spi_sync(struct spi_device *spi, struct spi_message *message) int spi_sync(struct spi_device *spi, struct spi_message *message)
{ {
...@@ -554,8 +551,10 @@ int spi_sync(struct spi_device *spi, struct spi_message *message) ...@@ -554,8 +551,10 @@ int spi_sync(struct spi_device *spi, struct spi_message *message)
message->complete = spi_complete; message->complete = spi_complete;
message->context = &done; message->context = &done;
status = spi_async(spi, message); status = spi_async(spi, message);
if (status == 0) if (status == 0) {
wait_for_completion(&done); wait_for_completion(&done);
status = message->status;
}
message->context = NULL; message->context = NULL;
return status; return status;
} }
...@@ -628,10 +627,8 @@ int spi_write_then_read(struct spi_device *spi, ...@@ -628,10 +627,8 @@ int spi_write_then_read(struct spi_device *spi,
/* do the i/o */ /* do the i/o */
status = spi_sync(spi, &message); status = spi_sync(spi, &message);
if (status == 0) { if (status == 0)
memcpy(rxbuf, x[1].rx_buf, n_rx); memcpy(rxbuf, x[1].rx_buf, n_rx);
status = message.status;
}
if (x[0].tx_buf == buf) if (x[0].tx_buf == buf)
mutex_unlock(&lock); mutex_unlock(&lock);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册