From: Sylwester Nawrocki Date: Tue, 7 Jan 2014 12:03:43 +0000 (+0100) Subject: clk: Correct handling of NULL clk in __clk_{get, put} X-Git-Tag: upstream/snapshot3+hdmi~3337^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=00efcb1c8e1c3c5e5d3ce6f0682d66402911a84f;p=platform%2Fadaptation%2Frenesas_rcar%2Frenesas_kernel.git clk: Correct handling of NULL clk in __clk_{get, put} Ensure clk->kref is dereferenced only when clk is not NULL. Signed-off-by: Sylwester Nawrocki Tested-by: Sachin Kamat Signed-off-by: Mike Turquette --- diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 5517944..c42e608 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -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 ***/