* [PATCH 1/1]mmc: fix division by zero when calculate mmc erase time @ 2011-02-24 11:18 Chuanxiao Dong 2011-02-24 11:37 ` Marc Koschewski 2011-02-24 12:35 ` Linus Walleij 0 siblings, 2 replies; 7+ messages in thread From: Chuanxiao Dong @ 2011-02-24 11:18 UTC (permalink / raw) To: linux-mmc, cjb; +Cc: adrian.hunter, linus.walleij, linux-kernel Since if clock gating feature is enabled, the clock frequency may be zero when host clock is gated. In such scenario, mmc_set_mmc_erase_timeout() may have a division by zero bug. So this patch used mmc_host_clk_rate() to fix this. Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.com> --- drivers/mmc/core/core.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 34a7e8c..12d0eb8 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -1201,8 +1201,14 @@ static void mmc_set_mmc_erase_timeout(struct mmc_card *card, * less but not that much less, so fudge it by multiplying by 2. */ timeout_clks <<= 1; - timeout_us += (timeout_clks * 1000) / - (card->host->ios.clock / 1000); + + /* + * at this moment, host controller maybe clock gated, so make + * sure we can get a correct host clock freq. + */ + if (mmc_host_clk_rate(card->host)) + timeout_us += (timeout_clks * 1000) / + (mmc_host_clk_rate(card->host) / 1000); erase_timeout = timeout_us / 1000; -- 1.6.6.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/1]mmc: fix division by zero when calculate mmc erase time 2011-02-24 11:18 [PATCH 1/1]mmc: fix division by zero when calculate mmc erase time Chuanxiao Dong @ 2011-02-24 11:37 ` Marc Koschewski 2011-02-24 12:09 ` Dong, Chuanxiao 2011-02-24 12:35 ` Linus Walleij 1 sibling, 1 reply; 7+ messages in thread From: Marc Koschewski @ 2011-02-24 11:37 UTC (permalink / raw) To: Chuanxiao Dong; +Cc: linux-mmc, cjb, adrian.hunter, linus.walleij, linux-kernel Hi, * Chuanxiao Dong <chuanxiao.dong@intel.com> [2011-02-24 19:18:01 +0800]: > Since if clock gating feature is enabled, the clock frequency may be zero when > host clock is gated. In such scenario, mmc_set_mmc_erase_timeout() may have a > division by zero bug. > > So this patch used mmc_host_clk_rate() to fix this. > > Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.com> > --- > drivers/mmc/core/core.c | 10 ++++++++-- > 1 files changed, 8 insertions(+), 2 deletions(-) > > diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c > index 34a7e8c..12d0eb8 100644 > --- a/drivers/mmc/core/core.c > +++ b/drivers/mmc/core/core.c > @@ -1201,8 +1201,14 @@ static void mmc_set_mmc_erase_timeout(struct mmc_card *card, > * less but not that much less, so fudge it by multiplying by 2. > */ > timeout_clks <<= 1; > - timeout_us += (timeout_clks * 1000) / > - (card->host->ios.clock / 1000); > + > + /* > + * at this moment, host controller maybe clock gated, so make > + * sure we can get a correct host clock freq. > + */ > + if (mmc_host_clk_rate(card->host)) > + timeout_us += (timeout_clks * 1000) / > + (mmc_host_clk_rate(card->host) / 1000); Why don't you just reuse mmc_host_clk_rate()'s result instead of calling it twice? Cheers, Marc > > erase_timeout = timeout_us / 1000; > > -- > 1.6.6.1 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > > -- Marc Koschewski ^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [PATCH 1/1]mmc: fix division by zero when calculate mmc erase time 2011-02-24 11:37 ` Marc Koschewski @ 2011-02-24 12:09 ` Dong, Chuanxiao 2011-02-24 12:22 ` Marc Koschewski 0 siblings, 1 reply; 7+ messages in thread From: Dong, Chuanxiao @ 2011-02-24 12:09 UTC (permalink / raw) To: Marc Koschewski Cc: linux-mmc@vger.kernel.org, cjb@laptop.org, adrian.hunter@nokia.com, linus.walleij@linaro.org, linux-kernel@vger.kernel.org > -----Original Message----- > From: Marc Koschewski [mailto:marc@osknowledge.org] > Sent: Thursday, February 24, 2011 7:38 PM > To: Dong, Chuanxiao > Cc: linux-mmc@vger.kernel.org; cjb@laptop.org; adrian.hunter@nokia.com; > linus.walleij@linaro.org; linux-kernel@vger.kernel.org > Subject: Re: [PATCH 1/1]mmc: fix division by zero when calculate mmc erase time > > Hi, > > * Chuanxiao Dong <chuanxiao.dong@intel.com> [2011-02-24 19:18:01 +0800]: > > > Since if clock gating feature is enabled, the clock frequency may be zero when > > host clock is gated. In such scenario, mmc_set_mmc_erase_timeout() may have a > > division by zero bug. > > > > So this patch used mmc_host_clk_rate() to fix this. > > > > Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.com> > > --- > > drivers/mmc/core/core.c | 10 ++++++++-- > > 1 files changed, 8 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c > > index 34a7e8c..12d0eb8 100644 > > --- a/drivers/mmc/core/core.c > > +++ b/drivers/mmc/core/core.c > > @@ -1201,8 +1201,14 @@ static void mmc_set_mmc_erase_timeout(struct > mmc_card *card, > > * less but not that much less, so fudge it by multiplying by 2. > > */ > > timeout_clks <<= 1; > > - timeout_us += (timeout_clks * 1000) / > > - (card->host->ios.clock / 1000); > > + > > + /* > > + * at this moment, host controller maybe clock gated, so make > > + * sure we can get a correct host clock freq. > > + */ > > + if (mmc_host_clk_rate(card->host)) > > + timeout_us += (timeout_clks * 1000) / > > + (mmc_host_clk_rate(card->host) / 1000); > > Why don't you just reuse mmc_host_clk_rate()'s result instead of calling it twice? This is a incline function and just return host->ios.clock. Reuse mmc_host_clk_rate()'s result need to add a new variable to save the value. Thanks Chuanxiao ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/1]mmc: fix division by zero when calculate mmc erase time 2011-02-24 12:09 ` Dong, Chuanxiao @ 2011-02-24 12:22 ` Marc Koschewski 2011-02-24 12:25 ` Dong, Chuanxiao 0 siblings, 1 reply; 7+ messages in thread From: Marc Koschewski @ 2011-02-24 12:22 UTC (permalink / raw) To: Dong, Chuanxiao Cc: linux-mmc@vger.kernel.org, cjb@laptop.org, adrian.hunter@nokia.com, linus.walleij@linaro.org, linux-kernel@vger.kernel.org * Dong, Chuanxiao <chuanxiao.dong@intel.com> [2011-02-24 20:09:59 +0800]: > > > > -----Original Message----- > > From: Marc Koschewski [mailto:marc@osknowledge.org] > > Sent: Thursday, February 24, 2011 7:38 PM > > To: Dong, Chuanxiao > > Cc: linux-mmc@vger.kernel.org; cjb@laptop.org; adrian.hunter@nokia.com; > > linus.walleij@linaro.org; linux-kernel@vger.kernel.org > > Subject: Re: [PATCH 1/1]mmc: fix division by zero when calculate mmc erase time > > > > Hi, > > > > * Chuanxiao Dong <chuanxiao.dong@intel.com> [2011-02-24 19:18:01 +0800]: > > > > > Since if clock gating feature is enabled, the clock frequency may be zero when > > > host clock is gated. In such scenario, mmc_set_mmc_erase_timeout() may have a > > > division by zero bug. > > > > > > So this patch used mmc_host_clk_rate() to fix this. > > > > > > Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.com> > > > --- > > > drivers/mmc/core/core.c | 10 ++++++++-- > > > 1 files changed, 8 insertions(+), 2 deletions(-) > > > > > > diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c > > > index 34a7e8c..12d0eb8 100644 > > > --- a/drivers/mmc/core/core.c > > > +++ b/drivers/mmc/core/core.c > > > @@ -1201,8 +1201,14 @@ static void mmc_set_mmc_erase_timeout(struct > > mmc_card *card, > > > * less but not that much less, so fudge it by multiplying by 2. > > > */ > > > timeout_clks <<= 1; > > > - timeout_us += (timeout_clks * 1000) / > > > - (card->host->ios.clock / 1000); > > > + > > > + /* > > > + * at this moment, host controller maybe clock gated, so make > > > + * sure we can get a correct host clock freq. > > > + */ > > > + if (mmc_host_clk_rate(card->host)) > > > + timeout_us += (timeout_clks * 1000) / > > > + (mmc_host_clk_rate(card->host) / 1000); > > > > Why don't you just reuse mmc_host_clk_rate()'s result instead of calling it twice? > This is a incline function and just return host->ios.clock. Reuse mmc_host_clk_rate()'s result need to add a new variable to save the value. It's not inline on trunk and it spinlocks. drivers/mmc/core/host.c:195 194 */ 195 unsigned int mmc_host_clk_rate(struct mmc_host *host) 196 { Cheers, Marc > > Thanks > Chuanxiao > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > > -- Marc Koschewski ^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [PATCH 1/1]mmc: fix division by zero when calculate mmc erase time 2011-02-24 12:22 ` Marc Koschewski @ 2011-02-24 12:25 ` Dong, Chuanxiao 2011-02-24 12:34 ` Marc Koschewski 0 siblings, 1 reply; 7+ messages in thread From: Dong, Chuanxiao @ 2011-02-24 12:25 UTC (permalink / raw) To: Marc Koschewski Cc: linux-mmc@vger.kernel.org, cjb@laptop.org, adrian.hunter@nokia.com, linus.walleij@linaro.org, linux-kernel@vger.kernel.org > -----Original Message----- > From: Marc Koschewski [mailto:marc@osknowledge.org] > Sent: Thursday, February 24, 2011 8:23 PM > To: Dong, Chuanxiao > Cc: linux-mmc@vger.kernel.org; cjb@laptop.org; adrian.hunter@nokia.com; > linus.walleij@linaro.org; linux-kernel@vger.kernel.org > Subject: Re: [PATCH 1/1]mmc: fix division by zero when calculate mmc erase time > > * Dong, Chuanxiao <chuanxiao.dong@intel.com> [2011-02-24 20:09:59 +0800]: > > > > > > > > -----Original Message----- > > > From: Marc Koschewski [mailto:marc@osknowledge.org] > > > Sent: Thursday, February 24, 2011 7:38 PM > > > To: Dong, Chuanxiao > > > Cc: linux-mmc@vger.kernel.org; cjb@laptop.org; adrian.hunter@nokia.com; > > > linus.walleij@linaro.org; linux-kernel@vger.kernel.org > > > Subject: Re: [PATCH 1/1]mmc: fix division by zero when calculate mmc erase > time > > > > > > Hi, > > > > > > * Chuanxiao Dong <chuanxiao.dong@intel.com> [2011-02-24 19:18:01 +0800]: > > > > > > > Since if clock gating feature is enabled, the clock frequency may be zero when > > > > host clock is gated. In such scenario, mmc_set_mmc_erase_timeout() may > have a > > > > division by zero bug. > > > > > > > > So this patch used mmc_host_clk_rate() to fix this. > > > > > > > > Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.com> > > > > --- > > > > drivers/mmc/core/core.c | 10 ++++++++-- > > > > 1 files changed, 8 insertions(+), 2 deletions(-) > > > > > > > > diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c > > > > index 34a7e8c..12d0eb8 100644 > > > > --- a/drivers/mmc/core/core.c > > > > +++ b/drivers/mmc/core/core.c > > > > @@ -1201,8 +1201,14 @@ static void mmc_set_mmc_erase_timeout(struct > > > mmc_card *card, > > > > * less but not that much less, so fudge it by multiplying by 2. > > > > */ > > > > timeout_clks <<= 1; > > > > - timeout_us += (timeout_clks * 1000) / > > > > - (card->host->ios.clock / 1000); > > > > + > > > > + /* > > > > + * at this moment, host controller maybe clock gated, so make > > > > + * sure we can get a correct host clock freq. > > > > + */ > > > > + if (mmc_host_clk_rate(card->host)) > > > > + timeout_us += (timeout_clks * 1000) / > > > > + (mmc_host_clk_rate(card->host) / 1000); > > > > > > Why don't you just reuse mmc_host_clk_rate()'s result instead of calling it > twice? > > This is a incline function and just return host->ios.clock. Reuse > mmc_host_clk_rate()'s result need to add a new variable to save the value. > > It's not inline on trunk and it spinlocks. > > drivers/mmc/core/host.c:195 > > 194 */ > 195 unsigned int mmc_host_clk_rate(struct mmc_host *host) > 196 { OK. With the clock gating framework enabled... I agree. So, what do you think? Add a new variable is better? Thanks Chuanxiao ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/1]mmc: fix division by zero when calculate mmc erase time 2011-02-24 12:25 ` Dong, Chuanxiao @ 2011-02-24 12:34 ` Marc Koschewski 0 siblings, 0 replies; 7+ messages in thread From: Marc Koschewski @ 2011-02-24 12:34 UTC (permalink / raw) To: Dong, Chuanxiao Cc: linux-mmc@vger.kernel.org, cjb@laptop.org, adrian.hunter@nokia.com, linus.walleij@linaro.org, linux-kernel@vger.kernel.org * Dong, Chuanxiao <chuanxiao.dong@intel.com> [2011-02-24 20:25:21 +0800]: > > -----Original Message----- > > From: Marc Koschewski [mailto:marc@osknowledge.org] > > Sent: Thursday, February 24, 2011 8:23 PM > > To: Dong, Chuanxiao > > Cc: linux-mmc@vger.kernel.org; cjb@laptop.org; adrian.hunter@nokia.com; > > linus.walleij@linaro.org; linux-kernel@vger.kernel.org > > Subject: Re: [PATCH 1/1]mmc: fix division by zero when calculate mmc erase time > > > > * Dong, Chuanxiao <chuanxiao.dong@intel.com> [2011-02-24 20:09:59 +0800]: > > > > > > > > > > > > -----Original Message----- > > > > From: Marc Koschewski [mailto:marc@osknowledge.org] > > > > Sent: Thursday, February 24, 2011 7:38 PM > > > > To: Dong, Chuanxiao > > > > Cc: linux-mmc@vger.kernel.org; cjb@laptop.org; adrian.hunter@nokia.com; > > > > linus.walleij@linaro.org; linux-kernel@vger.kernel.org > > > > Subject: Re: [PATCH 1/1]mmc: fix division by zero when calculate mmc erase > > time > > > > > > > > Hi, > > > > > > > > * Chuanxiao Dong <chuanxiao.dong@intel.com> [2011-02-24 19:18:01 +0800]: > > > > > > > > > Since if clock gating feature is enabled, the clock frequency may be zero when > > > > > host clock is gated. In such scenario, mmc_set_mmc_erase_timeout() may > > have a > > > > > division by zero bug. > > > > > > > > > > So this patch used mmc_host_clk_rate() to fix this. > > > > > > > > > > Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.com> > > > > > --- > > > > > drivers/mmc/core/core.c | 10 ++++++++-- > > > > > 1 files changed, 8 insertions(+), 2 deletions(-) > > > > > > > > > > diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c > > > > > index 34a7e8c..12d0eb8 100644 > > > > > --- a/drivers/mmc/core/core.c > > > > > +++ b/drivers/mmc/core/core.c > > > > > @@ -1201,8 +1201,14 @@ static void mmc_set_mmc_erase_timeout(struct > > > > mmc_card *card, > > > > > * less but not that much less, so fudge it by multiplying by 2. > > > > > */ > > > > > timeout_clks <<= 1; > > > > > - timeout_us += (timeout_clks * 1000) / > > > > > - (card->host->ios.clock / 1000); > > > > > + > > > > > + /* > > > > > + * at this moment, host controller maybe clock gated, so make > > > > > + * sure we can get a correct host clock freq. > > > > > + */ > > > > > + if (mmc_host_clk_rate(card->host)) > > > > > + timeout_us += (timeout_clks * 1000) / > > > > > + (mmc_host_clk_rate(card->host) / 1000); > > > > > > > > Why don't you just reuse mmc_host_clk_rate()'s result instead of calling it > > twice? > > > This is a incline function and just return host->ios.clock. Reuse > > mmc_host_clk_rate()'s result need to add a new variable to save the value. > > > > It's not inline on trunk and it spinlocks. > > > > drivers/mmc/core/host.c:195 > > > > 194 */ > > 195 unsigned int mmc_host_clk_rate(struct mmc_host *host) > > 196 { > OK. With the clock gating framework enabled... I agree. So, what do you think? Add a new variable is better? I personally would prefer the variable over the spinlock and function call, yes. And calling the same method with the same parameters on a line and another time on the next line is generally a bad idea I think. But maybe that's kind of a 'taste', moreover. It just hit my eye when I saw it... Cheers, Marc > > Thanks > Chuanxiao > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > > -- Marc Koschewski ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/1]mmc: fix division by zero when calculate mmc erase time 2011-02-24 11:18 [PATCH 1/1]mmc: fix division by zero when calculate mmc erase time Chuanxiao Dong 2011-02-24 11:37 ` Marc Koschewski @ 2011-02-24 12:35 ` Linus Walleij 1 sibling, 0 replies; 7+ messages in thread From: Linus Walleij @ 2011-02-24 12:35 UTC (permalink / raw) To: Chuanxiao Dong; +Cc: linux-mmc, cjb, adrian.hunter, linux-kernel 2011/2/24 Chuanxiao Dong <chuanxiao.dong@intel.com>: > Since if clock gating feature is enabled, the clock frequency may be zero when > host clock is gated. In such scenario, mmc_set_mmc_erase_timeout() may have a > division by zero bug. > > So this patch used mmc_host_clk_rate() to fix this. > > Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> Actually I think these divide-by zero bugs were there before since clock 0 is perfectly legal, we just didn't trigger them before. Yours, Linus Walleij ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-02-24 12:35 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-02-24 11:18 [PATCH 1/1]mmc: fix division by zero when calculate mmc erase time Chuanxiao Dong 2011-02-24 11:37 ` Marc Koschewski 2011-02-24 12:09 ` Dong, Chuanxiao 2011-02-24 12:22 ` Marc Koschewski 2011-02-24 12:25 ` Dong, Chuanxiao 2011-02-24 12:34 ` Marc Koschewski 2011-02-24 12:35 ` Linus Walleij
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox