diff mbox

clk: divider: Fix table round up function

Message ID 1399481332-9550-1-git-send-email-maxime.coquelin@st.com
State Accepted
Commit fe52e7505f8bf365d5ab0eeee19ababe406cbaaf
Headers show

Commit Message

Maxime COQUELIN May 7, 2014, 4:48 p.m. UTC
Commit 1d9fe6b97 ("clk: divider: Fix best div calculation for power-of-two and
table dividers") introduces a regression in its _table_round_up function.

When the divider passed to this function is greater than the max divider
available in the table, this function returns table's max divider.
Problem is that it causes an infinite loop in clk_divider_bestdiv() because
_next_div() will never return a value greater than maxdiv.

Instead of returning table's max divider, this patch returns INT_MAX.

Reported-by: Fabio Estevam <festevam@gmail.com>
Reported-by: Shawn Guo <shawn.guo@freescale.com>
Tested-by: Fabio Estevam <festevam@gmail.com>
Cc: Mike Turquette <mike.turquette@linaro.org>
Signed-off-by: Maxime Coquelin <maxime.coquelin@st.com>
---
 drivers/clk/clk-divider.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Fabio Estevam May 15, 2014, 1:28 p.m. UTC | #1
Hi Mike,

On Wed, May 7, 2014 at 1:48 PM, Maxime COQUELIN <maxime.coquelin@st.com> wrote:
> Commit 1d9fe6b97 ("clk: divider: Fix best div calculation for power-of-two and
> table dividers") introduces a regression in its _table_round_up function.
>
> When the divider passed to this function is greater than the max divider
> available in the table, this function returns table's max divider.
> Problem is that it causes an infinite loop in clk_divider_bestdiv() because
> _next_div() will never return a value greater than maxdiv.
>
> Instead of returning table's max divider, this patch returns INT_MAX.
>
> Reported-by: Fabio Estevam <festevam@gmail.com>
> Reported-by: Shawn Guo <shawn.guo@freescale.com>
> Tested-by: Fabio Estevam <festevam@gmail.com>
> Cc: Mike Turquette <mike.turquette@linaro.org>
> Signed-off-by: Maxime Coquelin <maxime.coquelin@st.com>

Any comments on this one? It does fix a regression.
--
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/
Maxime COQUELIN May 21, 2014, 12:52 p.m. UTC | #2
Hi Mike,

On 05/15/2014 03:28 PM, Fabio Estevam wrote:
> Hi Mike,
>
> On Wed, May 7, 2014 at 1:48 PM, Maxime COQUELIN <maxime.coquelin@st.com> wrote:
>> Commit 1d9fe6b97 ("clk: divider: Fix best div calculation for power-of-two and
>> table dividers") introduces a regression in its _table_round_up function.
>>
>> When the divider passed to this function is greater than the max divider
>> available in the table, this function returns table's max divider.
>> Problem is that it causes an infinite loop in clk_divider_bestdiv() because
>> _next_div() will never return a value greater than maxdiv.
>>
>> Instead of returning table's max divider, this patch returns INT_MAX.
>>
>> Reported-by: Fabio Estevam <festevam@gmail.com>
>> Reported-by: Shawn Guo <shawn.guo@freescale.com>
>> Tested-by: Fabio Estevam <festevam@gmail.com>
>> Cc: Mike Turquette <mike.turquette@linaro.org>
>> Signed-off-by: Maxime Coquelin <maxime.coquelin@st.com>
>
> Any comments on this one? It does fix a regression.
>

This patch is important as it fixes a regression, could you review it 
please?

Thanks,
Maxime
--
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/
Mike Turquette May 23, 2014, 9:39 p.m. UTC | #3
Quoting Maxime COQUELIN (2014-05-07 09:48:52)
> Commit 1d9fe6b97 ("clk: divider: Fix best div calculation for power-of-two and
> table dividers") introduces a regression in its _table_round_up function.
> 
> When the divider passed to this function is greater than the max divider
> available in the table, this function returns table's max divider.
> Problem is that it causes an infinite loop in clk_divider_bestdiv() because
> _next_div() will never return a value greater than maxdiv.
> 
> Instead of returning table's max divider, this patch returns INT_MAX.
> 
> Reported-by: Fabio Estevam <festevam@gmail.com>
> Reported-by: Shawn Guo <shawn.guo@freescale.com>
> Tested-by: Fabio Estevam <festevam@gmail.com>
> Cc: Mike Turquette <mike.turquette@linaro.org>
> Signed-off-by: Maxime Coquelin <maxime.coquelin@st.com>

Pulled into clk-fixes for -rc7.

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 b3c8396..cf9114a 100644
> --- a/drivers/clk/clk-divider.c
> +++ b/drivers/clk/clk-divider.c
> @@ -158,7 +158,7 @@ static bool _is_valid_div(struct clk_divider *divider, unsigned int div)
>  static int _round_up_table(const struct clk_div_table *table, int div)
>  {
>         const struct clk_div_table *clkt;
> -       int up = _get_table_maxdiv(table);
> +       int up = INT_MAX;
>  
>         for (clkt = table; clkt->div; clkt++) {
>                 if (clkt->div == div)
> -- 
> 1.9.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/
Maxime COQUELIN May 26, 2014, 7:31 a.m. UTC | #4
On 05/23/2014 11:39 PM, Mike Turquette wrote:
> Quoting Maxime COQUELIN (2014-05-07 09:48:52)
>> Commit 1d9fe6b97 ("clk: divider: Fix best div calculation for power-of-two and
>> table dividers") introduces a regression in its _table_round_up function.
>>
>> When the divider passed to this function is greater than the max divider
>> available in the table, this function returns table's max divider.
>> Problem is that it causes an infinite loop in clk_divider_bestdiv() because
>> _next_div() will never return a value greater than maxdiv.
>>
>> Instead of returning table's max divider, this patch returns INT_MAX.
>>
>> Reported-by: Fabio Estevam <festevam@gmail.com>
>> Reported-by: Shawn Guo <shawn.guo@freescale.com>
>> Tested-by: Fabio Estevam <festevam@gmail.com>
>> Cc: Mike Turquette <mike.turquette@linaro.org>
>> Signed-off-by: Maxime Coquelin <maxime.coquelin@st.com>
>
> Pulled into clk-fixes for -rc7.

Thanks Mike.

Regards,
Maxime

>
> 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 b3c8396..cf9114a 100644
>> --- a/drivers/clk/clk-divider.c
>> +++ b/drivers/clk/clk-divider.c
>> @@ -158,7 +158,7 @@ static bool _is_valid_div(struct clk_divider *divider, unsigned int div)
>>   static int _round_up_table(const struct clk_div_table *table, int div)
>>   {
>>          const struct clk_div_table *clkt;
>> -       int up = _get_table_maxdiv(table);
>> +       int up = INT_MAX;
>>
>>          for (clkt = table; clkt->div; clkt++) {
>>                  if (clkt->div == div)
>> --
>> 1.9.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/
diff mbox

Patch

diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
index b3c8396..cf9114a 100644
--- a/drivers/clk/clk-divider.c
+++ b/drivers/clk/clk-divider.c
@@ -158,7 +158,7 @@  static bool _is_valid_div(struct clk_divider *divider, unsigned int div)
 static int _round_up_table(const struct clk_div_table *table, int div)
 {
 	const struct clk_div_table *clkt;
-	int up = _get_table_maxdiv(table);
+	int up = INT_MAX;
 
 	for (clkt = table; clkt->div; clkt++) {
 		if (clkt->div == div)