diff mbox series

[U-Boot,1/2] mmc: mtk-sd: fix possible incomplete read ops

Message ID 20190117170601.20676-1-fparent@baylibre.com
State Accepted
Commit 924ed344a759f2d699ee397600af13363425ae90
Delegated to: Tom Rini
Headers show
Series [U-Boot,1/2] mmc: mtk-sd: fix possible incomplete read ops | expand

Commit Message

Fabien Parent Jan. 17, 2019, 5:06 p.m. UTC
The code is checking for incomplete read when it see the INT_XFER_COMPL
flag, but it forget to first check whether there is anything left in the
FIFO to copy to the RX buffer. This means that sometimes we will get
errors because of erroneous incomplete read operation.

This commit fixes the driver re-ordering the code so that we first
check for data inside the RX fifo and only after check the status
of the INT_XFER_COMPL flag.

Signed-off-by: Fabien Parent <fparent@baylibre.com>
---
 drivers/mmc/mtk-sd.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

Comments

Tom Rini Jan. 27, 2019, 3:52 a.m. UTC | #1
On Thu, Jan 17, 2019 at 06:06:00PM +0100, Fabien Parent wrote:

> The code is checking for incomplete read when it see the INT_XFER_COMPL
> flag, but it forget to first check whether there is anything left in the
> FIFO to copy to the RX buffer. This means that sometimes we will get
> errors because of erroneous incomplete read operation.
> 
> This commit fixes the driver re-ordering the code so that we first
> check for data inside the RX fifo and only after check the status
> of the INT_XFER_COMPL flag.
> 
> Signed-off-by: Fabien Parent <fparent@baylibre.com>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/drivers/mmc/mtk-sd.c b/drivers/mmc/mtk-sd.c
index 0741a525c0..e668df7017 100644
--- a/drivers/mmc/mtk-sd.c
+++ b/drivers/mmc/mtk-sd.c
@@ -554,6 +554,14 @@  static int msdc_pio_read(struct msdc_host *host, u8 *ptr, u32 size)
 			break;
 		}
 
+		chksz = min(size, (u32)MSDC_FIFO_SIZE);
+
+		if (msdc_fifo_rx_bytes(host) >= chksz) {
+			msdc_fifo_read(host, ptr, chksz);
+			ptr += chksz;
+			size -= chksz;
+		}
+
 		if (status & MSDC_INT_XFER_COMPL) {
 			if (size) {
 				pr_err("data not fully read\n");
@@ -562,15 +570,7 @@  static int msdc_pio_read(struct msdc_host *host, u8 *ptr, u32 size)
 
 			break;
 		}
-
-		chksz = min(size, (u32)MSDC_FIFO_SIZE);
-
-		if (msdc_fifo_rx_bytes(host) >= chksz) {
-			msdc_fifo_read(host, ptr, chksz);
-			ptr += chksz;
-			size -= chksz;
-		}
-	}
+}
 
 	return ret;
 }