Help!

[PATCH] clk: Fix cached parent ptrs allocation

 
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> Kernel RSS
Next:  Accepted upgrade-system 1.6.2.2 (source all)  
Author Message
Prashant Gaikwad
External


Since: Jun 28, 2012
Posts: 24



PostPosted: Wed Jul 04, 2012 10:10 am    Post subject: [PATCH] clk: Fix cached parent ptrs allocation
Archived from groups: linux>kernel (more info?)


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
---
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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo.RemoveThis@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to top
Prashant Gaikwad
External


Since: Jun 28, 2012
Posts: 24



PostPosted: Wed Jul 04, 2012 10:10 pm    Post subject: Re: [PATCH] clk: Fix cached parent ptrs allocation [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Wednesday 04 July 2012 06:45 PM, Prashant Gaikwad wrote:
> 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
> ---
> 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.
Mike,

Please ignore this patch as Rajendra has already sent patch to fix.

http://git.linaro.org/gitweb?p=people/mturquette/linux.git;a=commitdif...=863b13

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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo DeleteThis @vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to top
Stephen Warren
External


Since: Oct 16, 2009
Posts: 194



PostPosted: Thu Jul 05, 2012 1:10 pm    Post subject: Re: [PATCH] clk: Fix cached parent ptrs allocation [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On 07/04/2012 07:15 AM, Prashant Gaikwad wrote:
> 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.

If simply inverting the if test and swapping the if/else blocks solves
some problem, that sounds like a compiler bug that we need to track down
and file/fix.

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

Are you sure the change to initialize i wasn't all that was required to
solve the problem though? Mike has applied a patch for this that'll be
applied to 3.5-rcX and hence trickle into 3.6.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo.TakeThisOut@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to top
Prashant Gaikwad
External


Since: Jun 28, 2012
Posts: 24



PostPosted: Thu Jul 05, 2012 2:10 pm    Post subject: Re: [PATCH] clk: Fix cached parent ptrs allocation [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Thursday 05 July 2012 09:37 PM, Stephen Warren wrote:
> On 07/04/2012 07:15 AM, Prashant Gaikwad wrote:
>> 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.
> If simply inverting the if test and swapping the if/else blocks solves
> some problem, that sounds like a compiler bug that we need to track down
> and file/fix.
>
>> Also, initialize i to num_parents to make sure parent
>> is searched using parent name if parents is NULL.
> Are you sure the change to initialize i wasn't all that was required to
> solve the problem though? Mike has applied a patch for this that'll be
> applied to 3.5-rcX and hence trickle into 3.6.
Just initializing i does not fix problem. The patch Mike has applied
does two things
1. remove warning for uninitialized i
2. invert the if test
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo.DeleteThis@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to top
Stephen Warren
External


Since: Oct 16, 2009
Posts: 194



PostPosted: Thu Jul 05, 2012 4:10 pm    Post subject: Re: [PATCH] clk: Fix cached parent ptrs allocation [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On 07/05/2012 11:21 AM, Prashant Gaikwad wrote:
> On Thursday 05 July 2012 09:37 PM, Stephen Warren wrote:
>> On 07/04/2012 07:15 AM, Prashant Gaikwad wrote:
>>> 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.
>> If simply inverting the if test and swapping the if/else blocks solves
>> some problem, that sounds like a compiler bug that we need to track down
>> and file/fix.
>>
>>> Also, initialize i to num_parents to make sure parent
>>> is searched using parent name if parents is NULL.
>> Are you sure the change to initialize i wasn't all that was required to
>> solve the problem though? Mike has applied a patch for this that'll be
>> applied to 3.5-rcX and hence trickle into 3.6.
>
> Just initializing i does not fix problem. The patch Mike has applied
> does two things
> 1. remove warning for uninitialized i
> 2. invert the if test

Yes, but Mike's patch is very different to yours. Your patch description
says that you need to invert the if test to work around the compiler
optimizer so that it doesn't "optimize it in wrong way", whereas the
patch Mike applied was for a legitimate bug in the code; those are two
entirely different things.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo.TakeThisOut@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to top
Display posts from previous:   
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> Kernel All times are: Eastern Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum