]> git.karo-electronics.de Git - linux-beck.git/commitdiff
clk: vt8500: Fix division-by-0 when requested rate=0
authorTony Prisk <linux@prisktech.co.nz>
Thu, 27 Dec 2012 00:14:31 +0000 (13:14 +1300)
committerMike Turquette <mturquette@linaro.org>
Wed, 16 Jan 2013 00:16:25 +0000 (16:16 -0800)
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>
drivers/clk/clk-vt8500.c

index 3306c2b1906c46e85f391e6150890453f4692d81..db7d41f25046e276525ec9ab7dedfb04a3e8c4bf 100644 (file)
@@ -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)
@@ -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++;