Skip to content

Commit

Permalink
clk: Correct handling of NULL clk in __clk_{get, put}
Browse files Browse the repository at this point in the history
Ensure clk->kref is dereferenced only when clk is not NULL.

Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Tested-by: Sachin Kamat <sachin.kamat@linaro.org>
Signed-off-by: Mike Turquette <mturquette@linaro.org>
  • Loading branch information
Sylwester Nawrocki authored and Mike Turquette committed Feb 25, 2014
1 parent 624009a commit 00efcb1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions drivers/clk/clk.c
Original file line number Diff line number Diff line change
Expand Up @@ -2226,24 +2226,25 @@ EXPORT_SYMBOL_GPL(devm_clk_unregister);
*/
int __clk_get(struct clk *clk)
{
if (clk && !try_module_get(clk->owner))
return 0;
if (clk) {
if (!try_module_get(clk->owner))
return 0;

kref_get(&clk->ref);
kref_get(&clk->ref);
}
return 1;
}

void __clk_put(struct clk *clk)
{
if (WARN_ON_ONCE(IS_ERR(clk)))
if (!clk || WARN_ON_ONCE(IS_ERR(clk)))
return;

clk_prepare_lock();
kref_put(&clk->ref, __clk_release);
clk_prepare_unlock();

if (clk)
module_put(clk->owner);
module_put(clk->owner);
}

/*** clk rate change notifiers ***/
Expand Down

0 comments on commit 00efcb1

Please sign in to comment.