clk: validate pointer in __clk_disable()
authorFengguang Wu <[email protected]>
Mon, 30 Jul 2012 21:39:54 +0000 (14:39 -0700)
committerLinus Torvalds <[email protected]>
Tue, 31 Jul 2012 00:25:13 +0000 (17:25 -0700)
clk_get() returns -ENOENT on error and some careless caller might
dereference it without error checking:

In mxc_rnga_remove():

        struct clk *clk = clk_get(&pdev->dev, "rng");

// ...

        clk_disable(clk);

Since it's insane to audit the lots of existing and future clk users,
let's add a check in the callee to avoid kernel panic and warn about
any buggy user.

Cc: Russell King <[email protected]>
Cc: Paul Gortmaker <[email protected]>
Cc: Viresh Kumar <[email protected]>
Cc: viresh kumar <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
drivers/clk/clk.c

index c87fdd7105609d7bddd836dd9fa2e640753bb22a..efdfd009c2701a40b18a7ec8025ce7500fb98c53 100644 (file)
@@ -465,6 +465,9 @@ static void __clk_disable(struct clk *clk)
        if (!clk)
                return;
 
+       if (WARN_ON(IS_ERR(clk)))
+               return;
+
        if (WARN_ON(clk->enable_count == 0))
                return;