Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Geert Uytterhoeven and committed by
Simon Horman
6575a9c6 90069ad1

+12
+12
drivers/sh/clk/core.c
··· 469 469 470 470 unsigned long clk_get_rate(struct clk *clk) 471 471 { 472 + if (!clk) 473 + return 0; 474 + 472 475 return clk->rate; 473 476 } 474 477 EXPORT_SYMBOL_GPL(clk_get_rate); ··· 480 477 { 481 478 int ret = -EOPNOTSUPP; 482 479 unsigned long flags; 480 + 481 + if (!clk) 482 + return 0; 483 483 484 484 spin_lock_irqsave(&clock_lock, flags); 485 485 ··· 541 535 542 536 struct clk *clk_get_parent(struct clk *clk) 543 537 { 538 + if (!clk) 539 + return NULL; 540 + 544 541 return clk->parent; 545 542 } 546 543 EXPORT_SYMBOL_GPL(clk_get_parent); 547 544 548 545 long clk_round_rate(struct clk *clk, unsigned long rate) 549 546 { 547 + if (!clk) 548 + return 0; 549 + 550 550 if (likely(clk->ops && clk->ops->round_rate)) { 551 551 unsigned long flags, rounded; 552 552