Commit 863b1327 authored by Rajendra Nayak's avatar Rajendra Nayak Committed by Mike Turquette

clk: fix parent validation in __clk_set_parent()

The below commit introduced a bug in __clk_set_parent()
which could cause it to *skip* the parent validation
which makes sure the parent passed to the api is a valid
one.

    commit 7975059d
    Author: Rajendra Nayak <rnayak@ti.com>
    Date:   Wed Jun 6 14:41:31 2012 +0530

        clk: Allow late cache allocation for clk->parents

This was identified by the following compiler warning..

    drivers/clk/clk.c: In function '__clk_set_parent':
    drivers/clk/clk.c:1083:5: warning: 'i' may be used uninitialized in this function [-Wuninitialized]

.. as reported by Marc Kleine-Budde.

There were various options discussed on how to fix this, one
being initing 'i' to clk->num_parents, but the below approach
was found to be more appropriate as it also makes the 'parent
validation' code simpler to read.
Reported-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: default avatarRajendra Nayak <rnayak@ti.com>
Signed-off-by: default avatarMike Turquette <mturquette@linaro.org>
Cc: stable@kernel.org
parent 6887a413
...@@ -1067,26 +1067,24 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent) ...@@ -1067,26 +1067,24 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent)
old_parent = clk->parent; old_parent = clk->parent;
/* find index of new parent clock using cached parent ptrs */ if (!clk->parents)
if (clk->parents)
for (i = 0; i < clk->num_parents; i++)
if (clk->parents[i] == parent)
break;
else
clk->parents = kzalloc((sizeof(struct clk*) * clk->num_parents), clk->parents = kzalloc((sizeof(struct clk*) * clk->num_parents),
GFP_KERNEL); GFP_KERNEL);
/* /*
* find index of new parent clock using string name comparison * find index of new parent clock using cached parent ptrs,
* also try to cache the parent to avoid future calls to __clk_lookup * or if not yet cached, use string name comparison and cache
* them now to avoid future calls to __clk_lookup.
*/ */
if (i == clk->num_parents) for (i = 0; i < clk->num_parents; i++) {
for (i = 0; i < clk->num_parents; i++) if (clk->parents && clk->parents[i] == parent)
if (!strcmp(clk->parent_names[i], parent->name)) { break;
else if (!strcmp(clk->parent_names[i], parent->name)) {
if (clk->parents) if (clk->parents)
clk->parents[i] = __clk_lookup(parent->name); clk->parents[i] = __clk_lookup(parent->name);
break; break;
} }
}
if (i == clk->num_parents) { if (i == clk->num_parents) {
pr_debug("%s: clock %s is not a possible parent of clock %s\n", pr_debug("%s: clock %s is not a possible parent of clock %s\n",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment