* [PATCH] clk: divider: Fix overflow in clk_divider_bestdiv
@ 2014-05-07 16:24 Tomasz Figa
2014-05-07 16:50 ` Maxime Coquelin
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Tomasz Figa @ 2014-05-07 16:24 UTC (permalink / raw)
To: linux-arm-kernel
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);
--
1.9.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH] clk: divider: Fix overflow in clk_divider_bestdiv
2014-05-07 16:24 [PATCH] clk: divider: Fix overflow in clk_divider_bestdiv Tomasz Figa
@ 2014-05-07 16:50 ` Maxime Coquelin
2014-05-15 16:51 ` Tomasz Figa
2014-05-28 2:16 ` Mike Turquette
2 siblings, 0 replies; 5+ messages in thread
From: Maxime Coquelin @ 2014-05-07 16:50 UTC (permalink / raw)
To: linux-arm-kernel
Hi Tomasz,
On 05/07/2014 06:24 PM, 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.
Good catch.
Acked-by: Maxime Coquelin <maxime.coquelin@st.com>
Thanks,
Maxime
>
> 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);
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] clk: divider: Fix overflow in clk_divider_bestdiv
2014-05-07 16:24 [PATCH] clk: divider: Fix overflow in clk_divider_bestdiv Tomasz Figa
2014-05-07 16:50 ` Maxime Coquelin
@ 2014-05-15 16:51 ` Tomasz Figa
2014-05-24 23:33 ` [FIX] [CRITICAL] " Tomasz Figa
2014-05-28 2:16 ` Mike Turquette
2 siblings, 1 reply; 5+ messages in thread
From: Tomasz Figa @ 2014-05-15 16:51 UTC (permalink / raw)
To: linux-arm-kernel
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* [FIX] [CRITICAL] Re: [PATCH] clk: divider: Fix overflow in clk_divider_bestdiv
2014-05-15 16:51 ` Tomasz Figa
@ 2014-05-24 23:33 ` Tomasz Figa
0 siblings, 0 replies; 5+ messages in thread
From: Tomasz Figa @ 2014-05-24 23:33 UTC (permalink / raw)
To: linux-arm-kernel
Mike,
On 15.05.2014 18:51, Tomasz Figa wrote:
> 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.
Any issues with this patch?
Due to this issue, now since almost 3 weeks, all Samsung boards using
sdhci-s3c have been suffering from boot failures on linux-next due to
incorrect clock rates being calculated.
Best regards,
Tomasz
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] clk: divider: Fix overflow in clk_divider_bestdiv
2014-05-07 16:24 [PATCH] clk: divider: Fix overflow in clk_divider_bestdiv Tomasz Figa
2014-05-07 16:50 ` Maxime Coquelin
2014-05-15 16:51 ` Tomasz Figa
@ 2014-05-28 2:16 ` Mike Turquette
2 siblings, 0 replies; 5+ messages in thread
From: Mike Turquette @ 2014-05-28 2:16 UTC (permalink / raw)
To: linux-arm-kernel
Quoting Tomasz Figa (2014-05-07 09:24:10)
> 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>
Sorry for the long wait. This one flew under the radar. Applied to
clk-next.
Regards,
Mike
> ---
> 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);
> --
> 1.9.2
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-05-28 2:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-07 16:24 [PATCH] clk: divider: Fix overflow in clk_divider_bestdiv Tomasz Figa
2014-05-07 16:50 ` Maxime Coquelin
2014-05-15 16:51 ` Tomasz Figa
2014-05-24 23:33 ` [FIX] [CRITICAL] " Tomasz Figa
2014-05-28 2:16 ` Mike Turquette
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).