Skip to content

Commit

Permalink
clk: validate pointer in __clk_disable()
Browse files Browse the repository at this point in the history
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 <rmk@arm.linux.org.uk>
Cc: Paul Gortmaker <paul.gortmaker@windriver.com>
Cc: Viresh Kumar <viresh.kumar@st.com>
Cc: viresh kumar <viresh.linux@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Fengguang Wu authored and Linus Torvalds committed Jul 31, 2012
1 parent 7041717 commit e47c6a3
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/clk/clk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit e47c6a3

Please sign in to comment.