On Mon, Nov 12, 2012 at 12:45:28PM +0800, Haijun Zhang wrote:
> As some mmc cards need large timeout value usually a few seconds,
> so data timeout nanosecond will overflow with u32 variable and
> give the wrong timeout value, so use u64 will be safe.
>
> Signed-off-by: Jerry Huang <[email protected]>
> Signed-off-by: Haijun Zhang <[email protected]>
> CC: Anton Vorontsov <[email protected]>
> ---
> drivers/mmc/core/core.c | 21 ++++++++-------------
> drivers/mmc/host/sdhci.c | 6 +++---
> include/linux/mmc/core.h | 2 +-
> 3 files changed, 12 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
> index 06c42cf..c241fc1 100644
> --- a/drivers/mmc/core/core.c
> +++ b/drivers/mmc/core/core.c
> @@ -208,10 +208,10 @@ mmc_start_request(struct mmc_host *host, struct
> mmc_request *mrq)
>
> if (mrq->data) {
> pr_debug("%s: blksz %d blocks %d flags %08x "
> - "tsac %d ms nsac %d\n",
> + "tsac %lld ms nsac %d\n",
> mmc_hostname(host), mrq->data->blksz,
> mrq->data->blocks, mrq->data->flags,
> - mrq->data->timeout_ns / 1000000,
> + div_u64(mrq->data->timeout_ns, 1000000),
> mrq->data->timeout_clks);
> }
>
> @@ -659,16 +659,16 @@ void mmc_set_data_timeout(struct mmc_data *data, const
> struct mmc_card *card)
> if (data->flags & MMC_DATA_WRITE)
> mult <<= card->csd.r2w_factor;
>
> - data->timeout_ns = card->csd.tacc_ns * mult;
> + data->timeout_ns = (u64)card->csd.tacc_ns * (u64)mult;
one cast would be enough.
> data->timeout_clks = card->csd.tacc_clks * mult;
>
> /*
> * SD cards also have an upper limit on the timeout.
> */
> if (mmc_card_sd(card)) {
> - unsigned int timeout_us, limit_us;
> + u64 timeout_us, limit_us;
>
> - timeout_us = data->timeout_ns / 1000;
> + timeout_us = div_u64(data->timeout_ns, 1000);
> if (mmc_host_clk_rate(card->host))
> timeout_us += data->timeout_clks * 1000 /
> (mmc_host_clk_rate(card->host) / 1000);
> @@ -1545,14 +1545,9 @@ static unsigned int mmc_mmc_erase_timeout(struct
> mmc_card *card,
> /* CSD Erase Group Size uses write timeout */
> unsigned int mult = (10 << card->csd.r2w_factor);
> unsigned int timeout_clks = card->csd.tacc_clks * mult;
> - unsigned int timeout_us;
> -
> - /* Avoid overflow: e.g. tacc_ns=80000000 mult=1280 */
> - if (card->csd.tacc_ns < 1000000)
> - timeout_us = (card->csd.tacc_ns * mult) / 1000;
> - else
> - timeout_us = (card->csd.tacc_ns / 1000) * mult;
> + u64 timeout_us;
>
> + timeout_us = (u64)(card->csd.tacc_ns / 1000) * (u64)mult;
Ditto.
Otherwise it looks good.
Thanks,
Anton.
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html