linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Race condition in mpc52xx_psc_spi
@ 2008-12-08 11:59 Stefano Babic
  0 siblings, 0 replies; only message in thread
From: Stefano Babic @ 2008-12-08 11:59 UTC (permalink / raw)
  To: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f; +Cc: Stefano Babic

The RFNUM register is read only once to get the number of bytes
in the RXFIFO. If additional bytes are received during the for
loop that transfers data from the FIFO, the RFNUM register will not be
set to zero after the reading.
This causes that the RXFIFO interrupt remains pending, because
the interrupt is removed after all bytes are read from the RXFIFO
(with granularity set to 0 as set by the driver).

Signed-off-by: Stefano Babic <sbabic-ynQEQJNshbs@public.gmane.org>
---
 drivers/spi/mpc52xx_psc_spi.c |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/spi/mpc52xx_psc_spi.c b/drivers/spi/mpc52xx_psc_spi.c
index 8bd39df..e91d91a 100644
--- a/drivers/spi/mpc52xx_psc_spi.c
+++ b/drivers/spi/mpc52xx_psc_spi.c
@@ -191,17 +191,19 @@ static int mpc52xx_psc_spi_transfer_rxtx(struct spi_device *spi,
 		}
 		out_be16(&psc->mpc52xx_psc_imr, MPC52xx_PSC_IMR_RXRDY);
 		wait_for_completion(&mps->done);
-		recv_at_once = in_be16(&fifo->rfnum);
-		dev_dbg(&spi->dev, "%d bytes received\n", recv_at_once);
 
-		send_at_once = recv_at_once;
-		if (rx_buf) {
-			for (; recv_at_once; rb++, recv_at_once--)
-				rx_buf[rb] = in_8(&psc->mpc52xx_psc_buffer_8);
-		} else {
-			for (; recv_at_once; rb++, recv_at_once--)
+		recv_at_once = 0;
+		while (in_be16(&fifo->rfnum)) {
+			recv_at_once++;
+			if (rx_buf) {
+				rx_buf[rb++] = in_8(&psc->mpc52xx_psc_buffer_8);
+			} else {
 				in_8(&psc->mpc52xx_psc_buffer_8);
+				rb++;
+			}
 		}
+		dev_dbg(&spi->dev, "%d bytes received\n", recv_at_once);
+		send_at_once = recv_at_once;
 	}
 	/* disable transmiter/receiver */
 	out_8(&psc->command, MPC52xx_PSC_TX_DISABLE | MPC52xx_PSC_RX_DISABLE);
-- 
1.5.4.3


------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2008-12-08 11:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-08 11:59 [PATCH] Race condition in mpc52xx_psc_spi Stefano Babic

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).