linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: "Torne (Richard Coles)" <torne@google.com>
Cc: cjb@laptop.org, linus.walleij@linaro.org, jh80.chung@samsung.com,
	linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org,
	ben@decadent.org.uk
Subject: Re: [PATCH V3] MMC: core: cap MMC card timeouts at UINT_MAX
Date: Mon, 04 Jun 2012 11:13:08 +0300	[thread overview]
Message-ID: <4FCC6E14.4010603@intel.com> (raw)
In-Reply-To: <1338556815-26487-1-git-send-email-torne@google.com>

On 01/06/12 16:20, Torne (Richard Coles) wrote:
> From: "Torne (Richard Coles)" <torne@google.com>
> 
> MMC CSD info can specify very large, ridiculous timeouts, big enough to
> overflow timeout_ns. This can result in the card timing out on every
> operation because the wrapped timeout value is far too small.
> 
> Fix the overflow by capping the result at UINT_MAX.  Cards specifying
> longer timeouts are almost certainly insane, and host controllers
> generally cannot support timeouts that long in any case.
> 
> Signed-off-by: Torne (Richard Coles) <torne@google.com>
> ---
>  drivers/mmc/core/core.c |   11 ++++++++++-
>  1 files changed, 10 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
> index 0b6141d..74ec3d4 100644
> --- a/drivers/mmc/core/core.c
> +++ b/drivers/mmc/core/core.c
> @@ -512,7 +512,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;
> +	/*
> +	 * The timeout in nanoseconds may overflow with some cards. Cap it at
> +	 * UINT_MAX to avoid the overflow; host controllers cannot generally
> +	 * generate timeouts that long anyway.
> +	 */
> +	if (card->csd.tacc_ns <= UINT_MAX / mult)
> +		data->timeout_ns = card->csd.tacc_ns * mult;
> +	else
> +		data->timeout_ns = UINT_MAX;
> +
>  	data->timeout_clks = card->csd.tacc_clks * mult;
>  
>  	/*

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

  reply	other threads:[~2012-06-04  8:13 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-28 17:31 [PATCH V2] MMC: core: cap MMC card timeouts at 2 seconds Torne (Richard Coles)
2012-05-29  2:32 ` Ben Hutchings
2012-05-29  9:02   ` Torne (Richard Coles)
2012-05-29  9:02     ` [PATCH] " Torne (Richard Coles)
2012-05-31 10:00       ` Ulf Hansson
2012-05-31 10:15         ` Torne (Richard Coles)
2012-05-31 15:00           ` Ulf Hansson
2012-06-01  8:35   ` [PATCH V2] " Adrian Hunter
2012-06-01  9:31     ` Torne (Richard Coles)
2012-06-01  9:32       ` Torne (Richard Coles)
2012-06-01 10:09         ` Adrian Hunter
2012-06-01 10:20           ` Torne (Richard Coles)
2012-06-01 12:59             ` Adrian Hunter
2012-06-01 13:12               ` Torne (Richard Coles)
2012-06-01 13:20                 ` [PATCH V3] MMC: core: cap MMC card timeouts at UINT_MAX Torne (Richard Coles)
2012-06-04  8:13                   ` Adrian Hunter [this message]
2012-06-01 14:48               ` [PATCH V2] MMC: core: cap MMC card timeouts at 2 seconds Chris Ball

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4FCC6E14.4010603@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=ben@decadent.org.uk \
    --cc=cjb@laptop.org \
    --cc=jh80.chung@samsung.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=torne@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).