All of lore.kernel.org
 help / color / mirror / Atom feed
From: t.figa@samsung.com (Tomasz Figa)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] clk: divider: Fix overflow in clk_divider_bestdiv
Date: Thu, 15 May 2014 18:51:10 +0200	[thread overview]
Message-ID: <5374F07E.9070106@samsung.com> (raw)
In-Reply-To: <1399479850-25292-1-git-send-email-t.figa@samsung.com>

Hi Mike,

On 07.05.2014 18:24, Tomasz Figa wrote:
> Commit c686078 ("clk: divider: Add round to closest divider") introduced
> a helper function to check whether given divisor is the best one instead
> of direct check. However due to int type used instead of unsigned long
> for passing calculated rates to this function in certain cases an
> overflow could occur, for example when trying to obtain maximum possible
> clock rate by calling clk_round_rate(..., UINT_MAX).
> 
> This patch fixes this issue by changing the type of rate, now and best
> arguments of the function to unsigned long, which is the type that
> should be used for clock rates.
> 
> Signed-off-by: Tomasz Figa <t.figa@samsung.com>
> ---
>  drivers/clk/clk-divider.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
> index c572945..e0b360a 100644
> --- a/drivers/clk/clk-divider.c
> +++ b/drivers/clk/clk-divider.c
> @@ -232,7 +232,7 @@ static int _div_round(struct clk_divider *divider, unsigned long parent_rate,
>  }
>  
>  static bool _is_best_div(struct clk_divider *divider,
> -		int rate, int now, int best)
> +		unsigned long rate, unsigned long now, unsigned long best)
>  {
>  	if (divider->flags & CLK_DIVIDER_ROUND_CLOSEST)
>  		return abs(rate - now) < abs(rate - best);
> 

Ping. It's quite important fix as the issue makes all Exynos boards
using sdhci-s3c almost unusable.

Best regards,
Tomasz

WARNING: multiple messages have this Message-ID (diff)
From: Tomasz Figa <t.figa@samsung.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Mike Turquette <mturquette@linaro.org>,
	linux-kernel@vger.kernel.org,
	Maxime COQUELIN <maxime.coquelin@st.com>
Subject: Re: [PATCH] clk: divider: Fix overflow in clk_divider_bestdiv
Date: Thu, 15 May 2014 18:51:10 +0200	[thread overview]
Message-ID: <5374F07E.9070106@samsung.com> (raw)
In-Reply-To: <1399479850-25292-1-git-send-email-t.figa@samsung.com>

Hi Mike,

On 07.05.2014 18:24, Tomasz Figa wrote:
> Commit c686078 ("clk: divider: Add round to closest divider") introduced
> a helper function to check whether given divisor is the best one instead
> of direct check. However due to int type used instead of unsigned long
> for passing calculated rates to this function in certain cases an
> overflow could occur, for example when trying to obtain maximum possible
> clock rate by calling clk_round_rate(..., UINT_MAX).
> 
> This patch fixes this issue by changing the type of rate, now and best
> arguments of the function to unsigned long, which is the type that
> should be used for clock rates.
> 
> Signed-off-by: Tomasz Figa <t.figa@samsung.com>
> ---
>  drivers/clk/clk-divider.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
> index c572945..e0b360a 100644
> --- a/drivers/clk/clk-divider.c
> +++ b/drivers/clk/clk-divider.c
> @@ -232,7 +232,7 @@ static int _div_round(struct clk_divider *divider, unsigned long parent_rate,
>  }
>  
>  static bool _is_best_div(struct clk_divider *divider,
> -		int rate, int now, int best)
> +		unsigned long rate, unsigned long now, unsigned long best)
>  {
>  	if (divider->flags & CLK_DIVIDER_ROUND_CLOSEST)
>  		return abs(rate - now) < abs(rate - best);
> 

Ping. It's quite important fix as the issue makes all Exynos boards
using sdhci-s3c almost unusable.

Best regards,
Tomasz

  parent reply	other threads:[~2014-05-15 16:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-07 16:24 [PATCH] clk: divider: Fix overflow in clk_divider_bestdiv Tomasz Figa
2014-05-07 16:24 ` Tomasz Figa
2014-05-07 16:50 ` Maxime Coquelin
2014-05-07 16:50   ` Maxime Coquelin
2014-05-15 16:51 ` Tomasz Figa [this message]
2014-05-15 16:51   ` Tomasz Figa
2014-05-24 23:33   ` [FIX] [CRITICAL] " Tomasz Figa
2014-05-24 23:33     ` Tomasz Figa
2014-05-28  2:16 ` Mike Turquette
2014-05-28  2:16   ` Mike Turquette

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=5374F07E.9070106@samsung.com \
    --to=t.figa@samsung.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.