Commit 7975059d authored by Rajendra Nayak's avatar Rajendra Nayak Committed by Mike Turquette

clk: Allow late cache allocation for clk->parents

Parent clocks for muxes are cached in clk->parents to
avoid frequent lookups, however the cache allocation happens
only during clock registeration and later clk_set_parent()
assumes a cache space available and allocated.

This is not entirely true for platforms which do early clock
registerations wherein the cache allocation using kzalloc
could fail during clock registeration.

Allow cache allocation to happen later as part of clk_set_parent()
to help such cases and avoid crashes assuming a cache being
available.

While here also replace existing kmalloc() with kzalloc()
in the file.
Signed-off-by: default avatarRajendra Nayak <rnayak@ti.com>
Signed-off-by: default avatarMike Turquette <mturquette@linaro.org>
Cc: stable@kernel.org
parent 3a35fc3a
...@@ -999,7 +999,7 @@ static struct clk *__clk_init_parent(struct clk *clk) ...@@ -999,7 +999,7 @@ static struct clk *__clk_init_parent(struct clk *clk)
if (!clk->parents) if (!clk->parents)
clk->parents = clk->parents =
kmalloc((sizeof(struct clk*) * clk->num_parents), kzalloc((sizeof(struct clk*) * clk->num_parents),
GFP_KERNEL); GFP_KERNEL);
if (!clk->parents) if (!clk->parents)
...@@ -1065,9 +1065,13 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent) ...@@ -1065,9 +1065,13 @@ 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 */ /* find index of new parent clock using cached parent ptrs */
if (clk->parents)
for (i = 0; i < clk->num_parents; i++) for (i = 0; i < clk->num_parents; i++)
if (clk->parents[i] == parent) if (clk->parents[i] == parent)
break; break;
else
clk->parents = kzalloc((sizeof(struct clk*) * clk->num_parents),
GFP_KERNEL);
/* /*
* find index of new parent clock using string name comparison * find index of new parent clock using string name comparison
...@@ -1076,6 +1080,7 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent) ...@@ -1076,6 +1080,7 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent)
if (i == clk->num_parents) if (i == clk->num_parents)
for (i = 0; i < clk->num_parents; i++) for (i = 0; i < clk->num_parents; i++)
if (!strcmp(clk->parent_names[i], parent->name)) { if (!strcmp(clk->parent_names[i], parent->name)) {
if (clk->parents)
clk->parents[i] = __clk_lookup(parent->name); clk->parents[i] = __clk_lookup(parent->name);
break; break;
} }
......
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