Skip to contentSkip to conversation

clk: clk-divider: Fix infinite loop for table divider

PATCH In review Fabio Estevam 2 participants 3 messages May 6, 2014 – May 7, 2014 Common clk

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: clk-divider: Fix infinite loop for table divider

From: Fabio Estevam <[email protected]>

Since commit e7489693b3 (clk: divider: Optimize clk_divider_bestdiv loop) we notice a system hang on mx6qboard.

The cause for the hang is well explained by Sascha Hauer [1]:

"This cannot work. _round_up_table is implemented like this:

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);

        for (clkt = table; clkt->div; clkt++) {
                if (clkt->div == div)
                        return clkt->div;
                ...
        }
        ...
}

Here when a table entry matches the input div this function will return exactly the input div. This means _next_div() will always return the same value and clk_divider_bestdiv() has an infinite loop:

        for (i = 1; i <= maxdiv; i = _next_div(divider, i)) {
                ...
        } 

"
[1] http://marc.info/?l=linux-arm-kernel&m=139940658726253&w=2

Remove the 'return _round_up_table' so that the system can work normally again.

---
 drivers/clk/clk-divider.c | 2 --
 1 file changed, 2 deletions(-)
drivers/clk/clk-divider.c +0 -2
index b3c8396..fc3e344 100644
@@ -246,8 +246,6 @@ static int _next_div(struct clk_divider *divider, int div)
 
 	if (divider->flags & CLK_DIVIDER_POWER_OF_TWO)
 		return __roundup_pow_of_two(div);
-	if (divider->table)
-		return _round_up_table(divider->table, div);
 
 	return div;
 }
Signature · 1 line
1.8.3.2
#1 lore raw

Hi Fabio,

Quoted 44 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

Since commit e7489693b3 (clk: divider: Optimize clk_divider_bestdiv loop) we notice a system hang on mx6qboard.

The cause for the hang is well explained by Sascha Hauer [1]:

"This cannot work. _round_up_table is implemented like this:

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);

         for (clkt = table; clkt->div; clkt++) {
                 if (clkt->div == div)
                         return clkt->div;
                 ...
         }
         ...
}

Here when a table entry matches the input div this function will return exactly the input div. This means _next_div() will always return the same value and clk_divider_bestdiv() has an infinite loop:

         for (i = 1; i <= maxdiv; i = _next_div(divider, i)) {
                 ...
         }

"
[1] http://marc.info/?l=linux-arm-kernel&m=139940658726253&w=2

Remove the 'return _round_up_table' so that the system can work normally again.

---
  drivers/clk/clk-divider.c | 2 --
  1 file changed, 2 deletions(-)
drivers/clk/clk-divider.c +0 -0
index b3c8396..fc3e344 100644

drivers/clk/clk-divider.c static int _next_div(struct clk_divider *divider, int div) · line 250

Quoted 5 lines
drivers/clk/clk-divider.c +0 -2
@@ -246,8 +246,6 @@ static int _next_div(struct clk_divider *divider, int div)
 
  	if (divider->flags & CLK_DIVIDER_POWER_OF_TWO)
  		return __roundup_pow_of_two(div);
-	if (divider->table)
-		return _round_up_table(divider->table, div);

Couldn't we initialize "up" variable to INT_MAX in _round_up_table() as I just proposed in mail thread reporting the regression?

See http://marc.info/?l=linux-arm-kernel&m=139945172905130&w=2

Regards,
Maxime

Quoted 4 lines
drivers/clk/clk-divider.c +0 -0
  	return div;
  }
 
#2 lore raw
Quoted 2 lines · Maxime Coquelin

Couldn't we initialize "up" variable to INT_MAX in _round_up_table() as I just proposed in mail thread reporting the regression?

Yes, it works fine. Please submit your version.

Thanks