linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clk: Fix cached parent ptrs allocation
@ 2012-07-04 13:15 Prashant Gaikwad
  2012-07-05  1:10 ` Prashant Gaikwad
  2012-07-05 16:07 ` Stephen Warren
  0 siblings, 2 replies; 5+ messages in thread
From: Prashant Gaikwad @ 2012-07-04 13:15 UTC (permalink / raw)
  To: linux-arm-kernel

Compiler optimizes code someway that even if clk->parents
is not NULL it tries to allocate parents array. Change the
condition so that compiler does not optimize it in wrong
way.

Also, initialize i to num_parents to make sure parent
is searched using parent name if parents is NULL.

Signed-off-by: Prashant Gaikwad <pgaikwad@nvidia.com>
---
Mike,

There could be some other way to fix problem. I have not
debugged it in detail but I think this simple change should do.

 drivers/clk/clk.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 026d901..b28f2ae 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -1066,18 +1066,18 @@ static int __clk_set_parent(struct clk *clk, struct clk *parent)
 	struct clk *old_parent;
 	unsigned long flags;
 	int ret = -EINVAL;
-	u8 i;
+	u8 i = clk->num_parents;
 
 	old_parent = clk->parent;
 
 	/* find index of new parent clock using cached parent ptrs */
-	if (clk->parents)
+	if (!clk->parents)
+		clk->parents = kzalloc((sizeof(struct clk*) * clk->num_parents),
+								GFP_KERNEL);
+	else
 		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
-- 
1.7.4.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-07-05 18:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-04 13:15 [PATCH] clk: Fix cached parent ptrs allocation Prashant Gaikwad
2012-07-05  1:10 ` Prashant Gaikwad
2012-07-05 16:07 ` Stephen Warren
2012-07-05 17:21   ` Prashant Gaikwad
2012-07-05 18:44     ` Stephen Warren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).