[U-Boot] [PATCH v2] mmc: sdhci: clean up timeout detection

The current timeout detection logic is not very nice; it calls get_timer(start) in the while() loop, and then calls it again after the loop to check if a timeout error happened.
Because of the time difference between the two calls of get_timer(), the timeout detected after the loop may not be true.
Signed-off-by: Masahiro Yamada yamada.masahiro@socionext.com Acked-by: Jaehoon Chung jh80.chung@samsung.com ---
Changes in v2: - Fix a typo : get_time() -> get_timer() in git-log
drivers/mmc/sdhci.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c index 604f18d..0a1882d 100644 --- a/drivers/mmc/sdhci.c +++ b/drivers/mmc/sdhci.c @@ -243,17 +243,17 @@ static int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd, stat = sdhci_readl(host, SDHCI_INT_STATUS); if (stat & SDHCI_INT_ERROR) break; - } while (((stat & mask) != mask) && - (get_timer(start) < SDHCI_READ_STATUS_TIMEOUT));
- if (get_timer(start) >= SDHCI_READ_STATUS_TIMEOUT) { - if (host->quirks & SDHCI_QUIRK_BROKEN_R1B) - return 0; - else { - printf("%s: Timeout for status update!\n", __func__); - return TIMEOUT; + if (get_timer(start) >= SDHCI_READ_STATUS_TIMEOUT) { + if (host->quirks & SDHCI_QUIRK_BROKEN_R1B) { + return 0; + } else { + printf("%s: Timeout for status update!\n", + __func__); + return TIMEOUT; + } } - } + } while ((stat & mask) != mask);
if ((stat & (SDHCI_INT_ERROR | mask)) == mask) { sdhci_cmd_done(host, cmd);

Hi
On 07/10/2016 12:40 AM, Masahiro Yamada wrote:
The current timeout detection logic is not very nice; it calls get_timer(start) in the while() loop, and then calls it again after the loop to check if a timeout error happened.
Because of the time difference between the two calls of get_timer(), the timeout detected after the loop may not be true.
Applied on u-boot-mmc. Thanks!
Best Regards, Jaehoon Chung
Signed-off-by: Masahiro Yamada yamada.masahiro@socionext.com Acked-by: Jaehoon Chung jh80.chung@samsung.com
Changes in v2:
- Fix a typo : get_time() -> get_timer() in git-log
drivers/mmc/sdhci.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c index 604f18d..0a1882d 100644 --- a/drivers/mmc/sdhci.c +++ b/drivers/mmc/sdhci.c @@ -243,17 +243,17 @@ static int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd, stat = sdhci_readl(host, SDHCI_INT_STATUS); if (stat & SDHCI_INT_ERROR) break;
} while (((stat & mask) != mask) &&
(get_timer(start) < SDHCI_READ_STATUS_TIMEOUT));
if (get_timer(start) >= SDHCI_READ_STATUS_TIMEOUT) {
if (host->quirks & SDHCI_QUIRK_BROKEN_R1B)
return 0;
else {
printf("%s: Timeout for status update!\n", __func__);
return TIMEOUT;
if (get_timer(start) >= SDHCI_READ_STATUS_TIMEOUT) {
if (host->quirks & SDHCI_QUIRK_BROKEN_R1B) {
return 0;
} else {
printf("%s: Timeout for status update!\n",
__func__);
return TIMEOUT;
}}
- }
} while ((stat & mask) != mask);
if ((stat & (SDHCI_INT_ERROR | mask)) == mask) { sdhci_cmd_done(host, cmd);
participants (2)
-
Jaehoon Chung
-
Masahiro Yamada