mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1] spi: check tx_buf and rx_buf in spi_unmap_msg
@ 2015-04-16  2:54 Robin Gong
  2015-04-16 17:58 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Robin Gong @ 2015-04-16  2:54 UTC (permalink / raw)
  To: broonie; +Cc: linux-spi, linux-kernel

Some spi device drivers use the same tx_buf and rx_buf repeatly for better
performance such as driver/input/touchsreen/ads7846.c, but spi core grab tx_buf
/rx_buf of transfer and set them as dummy_tx/dummy_rx once they are NULL. Thus,
in the second time the tx_buf/rx_buf will be replaced by dummy_tx/dummy_rx and
the data which produced by the last tx or rx may be wrongly sent to the device
or handled by the upper level protocol. This patch just keep the orignal value
of tx_buf/rx_buf if they are NULL after this transfer processed.

Signed-off-by: Robin Gong <b38343@freescale.com>
---
 drivers/spi/spi.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index d5d7d22..50910d8 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -583,6 +583,15 @@ static int spi_unmap_msg(struct spi_master *master, struct spi_message *msg)
 	rx_dev = master->dma_rx->device->dev;
 
 	list_for_each_entry(xfer, &msg->transfers, transfer_list) {
+		/*
+		 * Restore the original value of tx_buf or rx_buf if they are
+		 * NULL.
+		 */
+		if (xfer->tx_buf == master->dummy_tx)
+			xfer->tx_buf = NULL;
+		if (xfer->rx_buf == master->dummy_rx)
+			xfer->rx_buf = NULL;
+
 		if (!master->can_dma(master, msg->spi, xfer))
 			continue;
 
-- 
1.9.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v1] spi: check tx_buf and rx_buf in spi_unmap_msg
  2015-04-16  2:54 [PATCH v1] spi: check tx_buf and rx_buf in spi_unmap_msg Robin Gong
@ 2015-04-16 17:58 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2015-04-16 17:58 UTC (permalink / raw)
  To: Robin Gong; +Cc: linux-spi, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 331 bytes --]

On Thu, Apr 16, 2015 at 10:54:18AM +0800, Robin Gong wrote:
> Some spi device drivers use the same tx_buf and rx_buf repeatly for better
> performance such as driver/input/touchsreen/ads7846.c, but spi core grab tx_buf
> /rx_buf of transfer and set them as dummy_tx/dummy_rx once they are NULL. Thus,

Applied, thanks - good spot.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-04-16 17:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-16  2:54 [PATCH v1] spi: check tx_buf and rx_buf in spi_unmap_msg Robin Gong
2015-04-16 17:58 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®