[PATCH] clk: Treat NULL as dummy clocks

Sascha Hauer s.hauer at pengutronix.de
Thu Mar 5 06:17:17 PST 2015


NULL pointers should be treated as dummy clocks as done in the kernel.
Using a not fully filled in clk * array for of_clk_add_provider may result
in NULL clks. When these are passed into the clk framework we should not
crash.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/clk/clk.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 584e2f3..1f11bb3 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -44,6 +44,9 @@ int clk_enable(struct clk *clk)
 {
 	int ret;
 
+	if (!clk)
+		return 0;
+
 	if (IS_ERR(clk))
 		return PTR_ERR(clk);
 
@@ -68,6 +71,9 @@ int clk_enable(struct clk *clk)
 
 void clk_disable(struct clk *clk)
 {
+	if (!clk)
+		return;
+
 	if (IS_ERR(clk))
 		return;
 
@@ -89,10 +95,15 @@ unsigned long clk_get_rate(struct clk *clk)
 	struct clk *parent;
 	unsigned long parent_rate = 0;
 
+	if (!clk)
+		return 0;
+
 	if (IS_ERR(clk))
 		return 0;
 
 	parent = clk_get_parent(clk);
+
+
 	if (!IS_ERR_OR_NULL(parent))
 		parent_rate = clk_get_rate(parent);
 
@@ -107,6 +118,9 @@ long clk_round_rate(struct clk *clk, unsigned long rate)
 	unsigned long parent_rate = 0;
 	struct clk *parent;
 
+	if (!clk)
+		return 0;
+
 	if (IS_ERR(clk))
 		return 0;
 
@@ -125,6 +139,9 @@ int clk_set_rate(struct clk *clk, unsigned long rate)
 	struct clk *parent;
 	unsigned long parent_rate = 0;
 
+	if (!clk)
+		return 0;
+
 	if (IS_ERR(clk))
 		return PTR_ERR(clk);
 
-- 
2.1.4




More information about the barebox mailing list