[U-Boot] [PATCH v1] clk: clk-uclass: Check ops pointer before use it

Wenyou Yang wenyou.yang at atmel.com
Wed Aug 17 09:05:53 CEST 2016


Add check ops pointer before use it. Otherwise, it will cause
the runtime error for the clk devices without ops callback.

Signed-off-by: Wenyou Yang <wenyou.yang at atmel.com>
---

 drivers/clk/clk-uclass.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 4d78e3f..13b8739 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -82,7 +82,7 @@ int clk_get_by_index(struct udevice *dev, int index, struct clk *clk)
 	}
 	ops = clk_dev_ops(dev_clk);
 
-	if (ops->of_xlate)
+	if (ops && ops->of_xlate)
 		ret = ops->of_xlate(clk, &args);
 	else
 		ret = clk_of_xlate_default(clk, &args);
@@ -120,7 +120,7 @@ int clk_request(struct udevice *dev, struct clk *clk)
 
 	clk->dev = dev;
 
-	if (!ops->request)
+	if (!ops || !ops->request)
 		return 0;
 
 	return ops->request(clk);
@@ -132,7 +132,7 @@ int clk_free(struct clk *clk)
 
 	debug("%s(clk=%p)\n", __func__, clk);
 
-	if (!ops->free)
+	if (!ops || !ops->free)
 		return 0;
 
 	return ops->free(clk);
@@ -144,7 +144,7 @@ ulong clk_get_rate(struct clk *clk)
 
 	debug("%s(clk=%p)\n", __func__, clk);
 
-	if (!ops->get_rate)
+	if (!ops || !ops->get_rate)
 		return -ENOSYS;
 
 	return ops->get_rate(clk);
@@ -156,7 +156,7 @@ ulong clk_set_rate(struct clk *clk, ulong rate)
 
 	debug("%s(clk=%p, rate=%lu)\n", __func__, clk, rate);
 
-	if (!ops->set_rate)
+	if (!ops || !ops->set_rate)
 		return -ENOSYS;
 
 	return ops->set_rate(clk, rate);
@@ -168,7 +168,7 @@ int clk_enable(struct clk *clk)
 
 	debug("%s(clk=%p)\n", __func__, clk);
 
-	if (!ops->enable)
+	if (!ops || !ops->enable)
 		return -ENOSYS;
 
 	return ops->enable(clk);
@@ -180,7 +180,7 @@ int clk_disable(struct clk *clk)
 
 	debug("%s(clk=%p)\n", __func__, clk);
 
-	if (!ops->disable)
+	if (!ops || !ops->disable)
 		return -ENOSYS;
 
 	return ops->disable(clk);
-- 
2.7.4



More information about the U-Boot mailing list