diff mbox

[LINUX-CCF] clk: must judge return value of get_parent in __clk_init.

Message ID 1382532863-30417-1-git-send-email-shaojie.sun@linaro.com
State New
Headers show

Commit Message

sunshaojie Oct. 23, 2013, 12:54 p.m. UTC
For get_parent function may be return a below zero value to
indicate that it couldn't find a valued parent.
In this condition orphan->parent_names[i] will lead system to
access an unknown memory.

Signed-off-by: Shaojie Sun <shaojie.sun@linaro.com>
---
 drivers/clk/clk.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 1144e8c..fcb5c85 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -1632,7 +1632,8 @@  int __clk_init(struct device *dev, struct clk *clk)
 	hlist_for_each_entry_safe(orphan, tmp2, &clk_orphan_list, child_node) {
 		if (orphan->ops->get_parent) {
 			i = orphan->ops->get_parent(orphan->hw);
-			if (!strcmp(clk->name, orphan->parent_names[i]))
+			if ((i >= 0)
+				&& !strcmp(clk->name, orphan->parent_names[i]))
 				__clk_reparent(orphan, clk);
 			continue;
 		}