Skip to content

Commit

Permalink
clk: vt8500: Fix division-by-0 when requested rate=0
Browse files Browse the repository at this point in the history
A request to vt8500_dclk_(round_rate/set_rate) with rate=0 results
in a division-by-0 in the kernel.

Signed-off-by: Tony Prisk <linux@prisktech.co.nz>
Signed-off-by: Mike Turquette <mturquette@linaro.org>
  • Loading branch information
Tony Prisk authored and Mike Turquette committed Jan 16, 2013
1 parent 7248001 commit 58eb5a6
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions drivers/clk/clk-vt8500.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ static long vt8500_dclk_round_rate(struct clk_hw *hw, unsigned long rate,
unsigned long *prate)
{
struct clk_device *cdev = to_clk_device(hw);
u32 divisor = *prate / rate;
u32 divisor;

if (rate == 0)
return 0;

divisor = *prate / rate;

/* If prate / rate would be decimal, incr the divisor */
if (rate * divisor < *prate)
Expand All @@ -142,9 +147,14 @@ static int vt8500_dclk_set_rate(struct clk_hw *hw, unsigned long rate,
unsigned long parent_rate)
{
struct clk_device *cdev = to_clk_device(hw);
u32 divisor = parent_rate / rate;
u32 divisor;
unsigned long flags = 0;

if (rate == 0)
return 0;

divisor = parent_rate / rate;

/* If prate / rate would be decimal, incr the divisor */
if (rate * divisor < *prate)
divisor++;
Expand Down

0 comments on commit 58eb5a6

Please sign in to comment.