net: ethernet: renesas: ravb_main: test clock rate to avoid division by 0
authorWolfram Sang <[email protected]>
Fri, 8 Apr 2016 11:28:42 +0000 (13:28 +0200)
committerDavid S. Miller <[email protected]>
Thu, 14 Apr 2016 02:36:28 +0000 (22:36 -0400)
The clk API may return 0 on clk_get_rate, so we should check the result before
using it as a divisor.

Signed-off-by: Wolfram Sang <[email protected]>
Acked-by: Sergei Shtylyov <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
drivers/net/ethernet/renesas/ravb_main.c

index 087e14a3fba726cd0637cbd12f2138b7dbe8adbf..9e2a0bd8f5a88803b4d1e260e18ffff9f119d541 100644 (file)
@@ -1691,6 +1691,9 @@ static int ravb_set_gti(struct net_device *ndev)
        rate = clk_get_rate(clk);
        clk_put(clk);
 
+       if (!rate)
+               return -EINVAL;
+
        inc = 1000000000ULL << 20;
        do_div(inc, rate);