Skip to content

Commit

Permalink
drivers: sh: clk: Avoid crashes when passing NULL clocks
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Geert Uytterhoeven authored and Simon Horman committed Nov 24, 2015
1 parent 90069ad commit 6575a9c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions drivers/sh/clk/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)) {
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 6575a9c

Please sign in to comment.