summaryrefslogtreecommitdiff
path: root/drivers/clk
diff options
context:
space:
mode:
authorRajendra Nayak <rnayak@ti.com>2012-06-06 14:41:31 +0530
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-07-16 09:04:09 -0700
commitc10f88285e2daf11ef8ec9726a25804abb9a84be (patch)
treed0095c1559c4ffddcc9f63c3e178c20cd77c9b7d /drivers/clk
parentd5b8efa118c7bf1b88e0f6f0185fbdd3c0ee67ed (diff)
clk: Allow late cache allocation for clk->parents
commit 7975059db572eb47f0fb272a62afeae272a4b209 upstream. 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: Rajendra Nayak <rnayak@ti.com> Signed-off-by: Mike Turquette <mturquette@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/clk')
-rw-r--r--drivers/clk/clk.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 9cf6f59e3e19..3ff9377a49eb 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -997,7 +997,7 @@ static struct clk *__clk_init_parent(struct clk *clk)
if (!clk->parents)
clk->parents =
- kmalloc((sizeof(struct clk*) * clk->num_parents),
+ kzalloc((sizeof(struct clk*) * clk->num_parents),
GFP_KERNEL);
if (!clk->parents)
@@ -1063,9 +1063,13 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent)
old_parent = clk->parent;
/* find index of new parent clock using cached parent ptrs */
- for (i = 0; i < clk->num_parents; i++)
- if (clk->parents[i] == parent)
- break;
+ 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),
+ GFP_KERNEL);
/*
* find index of new parent clock using string name comparison
@@ -1074,7 +1078,8 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent)
if (i == clk->num_parents)
for (i = 0; i < clk->num_parents; i++)
if (!strcmp(clk->parent_names[i], parent->name)) {
- clk->parents[i] = __clk_lookup(parent->name);
+ if (clk->parents)
+ clk->parents[i] = __clk_lookup(parent->name);
break;
}