clk: Correct lookup logic in clk_fetch_parent_index()
authorTomasz Figa <tomasz.figa@gmail.com>
Sun, 29 Sep 2013 00:37:16 +0000 (02:37 +0200)
committer黄涛 <huangtao@rock-chips.com>
Wed, 8 Jan 2014 03:06:01 +0000 (11:06 +0800)
This function is supposed to iterate over all parents of given child
clock to find the index of given parent clock in its parent list,
using parent cache if possible and falling back to string compare
otherwise. However currently the logic falls back to string compare in
every iteration in which clock cache entry does not match given parent,
due to wrong check conditions.

This patch corrects the logic to continue the loop if parent cache entry
is present and does not match requested parent clock. In addition,
redundant checks for parent cache array presence are removed, because it
is always allocated in the beginning of the function.

Signed-off-by: Tomasz Figa <tomasz.figa@gmail.com>
Signed-off-by: Mike Turquette <mturquette@linaro.org>
drivers/clk/clk.c

index 63f9ac16dcb6952886cee4b86c8a574f90d14280..32e2fed6d143c101ab43a3503f7fe54a4cd59610 100644 (file)
@@ -1097,11 +1097,14 @@ static int clk_fetch_parent_index(struct clk *clk, struct clk *parent)
         * them now to avoid future calls to __clk_lookup.
         */
        for (i = 0; i < clk->num_parents; i++) {
-               if (clk->parents && clk->parents[i] == parent)
+               if (clk->parents[i] == parent)
                        return i;
-               else if (!strcmp(clk->parent_names[i], parent->name)) {
-                       if (clk->parents)
-                               clk->parents[i] = __clk_lookup(parent->name);
+
+               if (clk->parents[i])
+                       continue;
+
+               if (!strcmp(clk->parent_names[i], parent->name)) {
+                       clk->parents[i] = __clk_lookup(parent->name);
                        return i;
                }
        }