diff mbox series

[1/6] mmc: mmc_spi: correct the while condition

Message ID 20200629094730.10051-2-pragnesh.patel@sifive.com
State New
Delegated to: Peng Fan
Headers show
Series mmc_spi: mmc erase resolve | expand

Commit Message

Pragnesh Patel June 29, 2020, 9:47 a.m. UTC
When variable i will become 0, while(i--) loop breaks but variable i will
again decrement to -1 because of i-- and that's why below condition
"if (!i && (r != resp_match_value)" will never execute, So doing "i--"
inside of while() loop solves this problem.

Signed-off-by: Pragnesh Patel <pragnesh.patel@sifive.com>
Reviewed-by: Bin Meng <bin.meng@windriver.com>
---
 drivers/mmc/mmc_spi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Bin Meng July 8, 2020, 5:21 a.m. UTC | #1
On Mon, Jun 29, 2020 at 5:48 PM Pragnesh Patel
<pragnesh.patel@sifive.com> wrote:
>
> When variable i will become 0, while(i--) loop breaks but variable i will
> again decrement to -1 because of i-- and that's why below condition
> "if (!i && (r != resp_match_value)" will never execute, So doing "i--"
> inside of while() loop solves this problem.
>
> Signed-off-by: Pragnesh Patel <pragnesh.patel@sifive.com>
> Reviewed-by: Bin Meng <bin.meng@windriver.com>
> ---
>  drivers/mmc/mmc_spi.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>

Tested-by: Bin Meng <bin.meng@windriver.com>
diff mbox series

Patch

diff --git a/drivers/mmc/mmc_spi.c b/drivers/mmc/mmc_spi.c
index e76ab54838..86cc932151 100644
--- a/drivers/mmc/mmc_spi.c
+++ b/drivers/mmc/mmc_spi.c
@@ -105,12 +105,14 @@  static int mmc_spi_sendcmd(struct udevice *dev,
 	if (resp_match) {
 		r = ~resp_match_value;
 		i = CMD_TIMEOUT;
-		while (i--) {
+		while (i) {
 			ret = dm_spi_xfer(dev, 1 * 8, NULL, &r, 0);
 			if (ret)
 				return ret;
 			debug(" resp%d=0x%x", rpos, r);
 			rpos++;
+			i--;
+
 			if (r == resp_match_value)
 				break;
 		}