diff options
author | Geert Uytterhoeven <geert+renesas@glider.be> | 2015-11-19 19:32:06 +0100 |
---|---|---|
committer | Simon Horman <horms+renesas@verge.net.au> | 2015-11-24 11:49:18 +0900 |
commit | 6575a9c69a211ac1cf454f9c76be54f7a5fae9fe (patch) | |
tree | 8a4cd82a6df5e6362152c1438ce5dbc6c79383c9 /drivers/sh | |
parent | 90069ad1b602d05740ed0fc5f72f09a616ceddd0 (diff) | |
download | linux-6575a9c69a211ac1cf454f9c76be54f7a5fae9fe.tar.gz linux-6575a9c69a211ac1cf454f9c76be54f7a5fae9fe.tar.bz2 linux-6575a9c69a211ac1cf454f9c76be54f7a5fae9fe.zip |
drivers: sh: clk: Avoid crashes when passing NULL clocks
Several clock API functions handle NULL clocks when the Common Clock
Framework is used, while their legacy SH counterparts don't, and would
just crash when a NULL clock is passed.
Add NULL checks to clk_get_rate(), clk_set_rate(), clk_get_parent(), and
clk_round_rate(), to avoid different behavior in drivers shared between
legacy and CCF-based platforms.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
Diffstat (limited to 'drivers/sh')
-rw-r--r-- | drivers/sh/clk/core.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/drivers/sh/clk/core.c b/drivers/sh/clk/core.c index 6bf973bd9654..92863e3818e5 100644 --- a/drivers/sh/clk/core.c +++ b/drivers/sh/clk/core.c @@ -469,6 +469,9 @@ void clk_enable_init_clocks(void) unsigned long clk_get_rate(struct clk *clk) { + if (!clk) + return 0; + return clk->rate; } EXPORT_SYMBOL_GPL(clk_get_rate); @@ -478,6 +481,9 @@ int clk_set_rate(struct clk *clk, unsigned long rate) int ret = -EOPNOTSUPP; unsigned long flags; + if (!clk) + return 0; + spin_lock_irqsave(&clock_lock, flags); if (likely(clk->ops && clk->ops->set_rate)) { @@ -535,12 +541,18 @@ EXPORT_SYMBOL_GPL(clk_set_parent); struct clk *clk_get_parent(struct clk *clk) { + if (!clk) + return NULL; + return clk->parent; } EXPORT_SYMBOL_GPL(clk_get_parent); long clk_round_rate(struct clk *clk, unsigned long rate) { + if (!clk) + return 0; + if (likely(clk->ops && clk->ops->round_rate)) { unsigned long flags, rounded; |