Skip to contentSkip to conversation

Race condition in mpc52xx_psc_spi

PATCH New Stefano Babic 1 participant 1 message Dec 8, 2008 SPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Race condition in mpc52xx_psc_spi

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).

---
 drivers/spi/mpc52xx_psc_spi.c |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)
drivers/spi/mpc52xx_psc_spi.c +10 -8
index 8bd39df..e91d91a 100644
@@ -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);
Signature · 8 lines
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/