aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeert Uytterhoeven <geert+renesas@glider.be>2015-11-19 13:32:06 -0500
committerSimon Horman <horms+renesas@verge.net.au>2015-11-23 21:49:18 -0500
commit6575a9c69a211ac1cf454f9c76be54f7a5fae9fe (patch)
tree8a4cd82a6df5e6362152c1438ce5dbc6c79383c9
parent90069ad1b602d05740ed0fc5f72f09a616ceddd0 (diff)
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>
-rw-r--r--drivers/sh/clk/core.c12
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)
469 469
470unsigned long clk_get_rate(struct clk *clk) 470unsigned long clk_get_rate(struct clk *clk)
471{ 471{
472 if (!clk)
473 return 0;
474
472 return clk->rate; 475 return clk->rate;
473} 476}
474EXPORT_SYMBOL_GPL(clk_get_rate); 477EXPORT_SYMBOL_GPL(clk_get_rate);
@@ -478,6 +481,9 @@ int clk_set_rate(struct clk *clk, unsigned long rate)
478 int ret = -EOPNOTSUPP; 481 int ret = -EOPNOTSUPP;
479 unsigned long flags; 482 unsigned long flags;
480 483
484 if (!clk)
485 return 0;
486
481 spin_lock_irqsave(&clock_lock, flags); 487 spin_lock_irqsave(&clock_lock, flags);
482 488
483 if (likely(clk->ops && clk->ops->set_rate)) { 489 if (likely(clk->ops && clk->ops->set_rate)) {
@@ -535,12 +541,18 @@ EXPORT_SYMBOL_GPL(clk_set_parent);
535 541
536struct clk *clk_get_parent(struct clk *clk) 542struct clk *clk_get_parent(struct clk *clk)
537{ 543{
544 if (!clk)
545 return NULL;
546
538 return clk->parent; 547 return clk->parent;
539} 548}
540EXPORT_SYMBOL_GPL(clk_get_parent); 549EXPORT_SYMBOL_GPL(clk_get_parent);
541 550
542long clk_round_rate(struct clk *clk, unsigned long rate) 551long clk_round_rate(struct clk *clk, unsigned long rate)
543{ 552{
553 if (!clk)
554 return 0;
555
544 if (likely(clk->ops && clk->ops->round_rate)) { 556 if (likely(clk->ops && clk->ops->round_rate)) {
545 unsigned long flags, rounded; 557 unsigned long flags, rounded;
546 558