2014-06-13 05:53:45

by Frank Rowand

[permalink] [raw]
Subject: [RFC PATCH] OF: fix of_find_node_by_path() assumption that of_allnodes is root

From: Frank Rowand <[email protected]>

Pantelis Antoniou reports that of_find_node_by_path() is borked because
of_allnodes is not guaranteed to contain the root of the tree after using
any of the dynamic update functions because some other nodes ends up as
of_allnodes.

Fixes: c22e650e66b8 of: Make of_find_node_by_path() handle /aliases

Signed-off-by: Frank Rowand <[email protected]>
---


Pantelis,

Can you test whether the problem you reported in irc?

This patch has not been tested, not even compile tested.


drivers/of/base.c | 8 6 + 2 - 0 !
1 file changed, 6 insertions(+), 2 deletions(-)

Index: b/drivers/of/base.c
===================================================================
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1948,6 +1948,9 @@ int of_reconfig_notify(unsigned long act

/**
* of_attach_node - Plug a device node into the tree and global list.
+ *
+ * Put the device node after of_allnodes in the global list so that
+ * of_allnodes remains the root.
*/
int of_attach_node(struct device_node *np)
{
@@ -1958,11 +1961,12 @@ int of_attach_node(struct device_node *n
if (rc)
return rc;

+ BUG_ON(!of_allnodes);
raw_spin_lock_irqsave(&devtree_lock, flags);
np->sibling = np->parent->child;
- np->allnext = of_allnodes;
+ np->allnext = of_allnodes->allnext;
np->parent->child = np;
- of_allnodes = np;
+ of_allnodes->allnext = np;
of_node_clear_flag(np, OF_DETACHED);
raw_spin_unlock_irqrestore(&devtree_lock, flags);


2014-06-13 07:07:40

by Pantelis Antoniou

[permalink] [raw]
Subject: Re: [RFC PATCH] OF: fix of_find_node_by_path() assumption that of_allnodes is root

Hi Frank,

On Jun 13, 2014, at 8:53 AM, Frank Rowand wrote:

> From: Frank Rowand <[email protected]>
>
> Pantelis Antoniou reports that of_find_node_by_path() is borked because
> of_allnodes is not guaranteed to contain the root of the tree after using
> any of the dynamic update functions because some other nodes ends up as
> of_allnodes.
>
> Fixes: c22e650e66b8 of: Make of_find_node_by_path() handle /aliases
>
> Signed-off-by: Frank Rowand <[email protected]>
> ---
>
>
> Pantelis,
>
> Can you test whether the problem you reported in irc?
>
> This patch has not been tested, not even compile tested.
>

I can verify that this fixes the problem. Please make sure this gets
applied to mainline otherwise every arch which updates DT on runtime
is going to break in subtle ways.

Regards

-- Pantelis

Tested-by: Pantelis Antoniou <[email protected]>

>
> drivers/of/base.c | 8 6 + 2 - 0 !
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> Index: b/drivers/of/base.c
> ===================================================================
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -1948,6 +1948,9 @@ int of_reconfig_notify(unsigned long act
>
> /**
> * of_attach_node - Plug a device node into the tree and global list.
> + *
> + * Put the device node after of_allnodes in the global list so that
> + * of_allnodes remains the root.
> */
> int of_attach_node(struct device_node *np)
> {
> @@ -1958,11 +1961,12 @@ int of_attach_node(struct device_node *n
> if (rc)
> return rc;
>
> + BUG_ON(!of_allnodes);
> raw_spin_lock_irqsave(&devtree_lock, flags);
> np->sibling = np->parent->child;
> - np->allnext = of_allnodes;
> + np->allnext = of_allnodes->allnext;
> np->parent->child = np;
> - of_allnodes = np;
> + of_allnodes->allnext = np;
> of_node_clear_flag(np, OF_DETACHED);
> raw_spin_unlock_irqrestore(&devtree_lock, flags);
>
> --
> To unsubscribe from this list: send the line "unsubscribe devicetree" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2014-06-13 13:52:39

by Rob Herring

[permalink] [raw]
Subject: Re: [RFC PATCH] OF: fix of_find_node_by_path() assumption that of_allnodes is root

On Fri, Jun 13, 2014 at 12:53 AM, Frank Rowand <[email protected]> wrote:
> From: Frank Rowand <[email protected]>
>
> Pantelis Antoniou reports that of_find_node_by_path() is borked because
> of_allnodes is not guaranteed to contain the root of the tree after using
> any of the dynamic update functions because some other nodes ends up as
> of_allnodes.
>
> Fixes: c22e650e66b8 of: Make of_find_node_by_path() handle /aliases

Is it not possible to do a fix in of_find_node_by_path instead? I just
wonder if this could have any other unintended side-effects on
of_attach_node's behavior.

Rob

>
> Signed-off-by: Frank Rowand <[email protected]>
> ---
>
>
> Pantelis,
>
> Can you test whether the problem you reported in irc?
>
> This patch has not been tested, not even compile tested.
>
>
> drivers/of/base.c | 8 6 + 2 - 0 !
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> Index: b/drivers/of/base.c
> ===================================================================
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -1948,6 +1948,9 @@ int of_reconfig_notify(unsigned long act
>
> /**
> * of_attach_node - Plug a device node into the tree and global list.
> + *
> + * Put the device node after of_allnodes in the global list so that
> + * of_allnodes remains the root.
> */
> int of_attach_node(struct device_node *np)
> {
> @@ -1958,11 +1961,12 @@ int of_attach_node(struct device_node *n
> if (rc)
> return rc;
>
> + BUG_ON(!of_allnodes);
> raw_spin_lock_irqsave(&devtree_lock, flags);
> np->sibling = np->parent->child;
> - np->allnext = of_allnodes;
> + np->allnext = of_allnodes->allnext;
> np->parent->child = np;
> - of_allnodes = np;
> + of_allnodes->allnext = np;
> of_node_clear_flag(np, OF_DETACHED);
> raw_spin_unlock_irqrestore(&devtree_lock, flags);
>

2014-06-13 15:06:49

by Grant Likely

[permalink] [raw]
Subject: Re: [RFC PATCH] OF: fix of_find_node_by_path() assumption that of_allnodes is root

On Fri, Jun 13, 2014 at 2:52 PM, Rob Herring <[email protected]> wrote:
> On Fri, Jun 13, 2014 at 12:53 AM, Frank Rowand <[email protected]> wrote:
>> From: Frank Rowand <[email protected]>
>>
>> Pantelis Antoniou reports that of_find_node_by_path() is borked because
>> of_allnodes is not guaranteed to contain the root of the tree after using
>> any of the dynamic update functions because some other nodes ends up as
>> of_allnodes.
>>
>> Fixes: c22e650e66b8 of: Make of_find_node_by_path() handle /aliases
>
> Is it not possible to do a fix in of_find_node_by_path instead? I just
> wonder if this could have any other unintended side-effects on
> of_attach_node's behavior.

Given that I'm going to replace the custom list with list_head which
makes this problem go away, I think this solution is fine.

Acked-by: Grant Likely <[email protected]>

g.

>
> Rob
>
>>
>> Signed-off-by: Frank Rowand <[email protected]>
>> ---
>>
>>
>> Pantelis,
>>
>> Can you test whether the problem you reported in irc?
>>
>> This patch has not been tested, not even compile tested.
>>
>>
>> drivers/of/base.c | 8 6 + 2 - 0 !
>> 1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> Index: b/drivers/of/base.c
>> ===================================================================
>> --- a/drivers/of/base.c
>> +++ b/drivers/of/base.c
>> @@ -1948,6 +1948,9 @@ int of_reconfig_notify(unsigned long act
>>
>> /**
>> * of_attach_node - Plug a device node into the tree and global list.
>> + *
>> + * Put the device node after of_allnodes in the global list so that
>> + * of_allnodes remains the root.
>> */
>> int of_attach_node(struct device_node *np)
>> {
>> @@ -1958,11 +1961,12 @@ int of_attach_node(struct device_node *n
>> if (rc)
>> return rc;
>>
>> + BUG_ON(!of_allnodes);
>> raw_spin_lock_irqsave(&devtree_lock, flags);
>> np->sibling = np->parent->child;
>> - np->allnext = of_allnodes;
>> + np->allnext = of_allnodes->allnext;
>> np->parent->child = np;
>> - of_allnodes = np;
>> + of_allnodes->allnext = np;
>> of_node_clear_flag(np, OF_DETACHED);
>> raw_spin_unlock_irqrestore(&devtree_lock, flags);
>>

2014-06-13 16:49:08

by Frank Rowand

[permalink] [raw]
Subject: Re: [RFC PATCH] OF: fix of_find_node_by_path() assumption that of_allnodes is root

On 6/13/2014 6:52 AM, Rob Herring wrote:
> On Fri, Jun 13, 2014 at 12:53 AM, Frank Rowand <[email protected]> wrote:
>> From: Frank Rowand <[email protected]>
>>
>> Pantelis Antoniou reports that of_find_node_by_path() is borked because
>> of_allnodes is not guaranteed to contain the root of the tree after using
>> any of the dynamic update functions because some other nodes ends up as
>> of_allnodes.
>>
>> Fixes: c22e650e66b8 of: Make of_find_node_by_path() handle /aliases
>
> Is it not possible to do a fix in of_find_node_by_path instead? I just

Yes, the code for that is in https://lkml.org/lkml/2014/5/20/758

Or as Grant said in his reply, just use the fix in of_attach_node() for
now since he is going to replace the custom list.

> wonder if this could have any other unintended side-effects on
> of_attach_node's behavior.
>
> Rob
>
>>
>> Signed-off-by: Frank Rowand <[email protected]>
>> ---
>>
>>
>> Pantelis,
>>
>> Can you test whether the problem you reported in irc?
>>
>> This patch has not been tested, not even compile tested.
>>
>>
>> drivers/of/base.c | 8 6 + 2 - 0 !
>> 1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> Index: b/drivers/of/base.c
>> ===================================================================
>> --- a/drivers/of/base.c
>> +++ b/drivers/of/base.c
>> @@ -1948,6 +1948,9 @@ int of_reconfig_notify(unsigned long act
>>
>> /**
>> * of_attach_node - Plug a device node into the tree and global list.
>> + *
>> + * Put the device node after of_allnodes in the global list so that
>> + * of_allnodes remains the root.
>> */
>> int of_attach_node(struct device_node *np)
>> {
>> @@ -1958,11 +1961,12 @@ int of_attach_node(struct device_node *n
>> if (rc)
>> return rc;
>>
>> + BUG_ON(!of_allnodes);
>> raw_spin_lock_irqsave(&devtree_lock, flags);
>> np->sibling = np->parent->child;
>> - np->allnext = of_allnodes;
>> + np->allnext = of_allnodes->allnext;
>> np->parent->child = np;
>> - of_allnodes = np;
>> + of_allnodes->allnext = np;
>> of_node_clear_flag(np, OF_DETACHED);
>> raw_spin_unlock_irqrestore(&devtree_lock, flags);
>>
> .
>

2014-06-13 21:13:18

by Rob Herring

[permalink] [raw]
Subject: Re: [RFC PATCH] OF: fix of_find_node_by_path() assumption that of_allnodes is root

On Fri, Jun 13, 2014 at 11:49 AM, Frank Rowand <[email protected]> wrote:
> On 6/13/2014 6:52 AM, Rob Herring wrote:
>> On Fri, Jun 13, 2014 at 12:53 AM, Frank Rowand <[email protected]> wrote:
>>> From: Frank Rowand <[email protected]>
>>>
>>> Pantelis Antoniou reports that of_find_node_by_path() is borked because
>>> of_allnodes is not guaranteed to contain the root of the tree after using
>>> any of the dynamic update functions because some other nodes ends up as
>>> of_allnodes.
>>>
>>> Fixes: c22e650e66b8 of: Make of_find_node_by_path() handle /aliases
>>
>> Is it not possible to do a fix in of_find_node_by_path instead? I just
>
> Yes, the code for that is in https://lkml.org/lkml/2014/5/20/758
>
> Or as Grant said in his reply, just use the fix in of_attach_node() for
> now since he is going to replace the custom list.

Okay, I've applied.

Rob

2014-06-14 15:00:26

by Grant Likely

[permalink] [raw]
Subject: Re: [RFC PATCH] OF: fix of_find_node_by_path() assumption that of_allnodes is root

On Fri, Jun 13, 2014 at 4:06 PM, Grant Likely <[email protected]> wrote:
> On Fri, Jun 13, 2014 at 2:52 PM, Rob Herring <[email protected]> wrote:
>> On Fri, Jun 13, 2014 at 12:53 AM, Frank Rowand <[email protected]> wrote:
>>> From: Frank Rowand <[email protected]>
>>>
>>> Pantelis Antoniou reports that of_find_node_by_path() is borked because
>>> of_allnodes is not guaranteed to contain the root of the tree after using
>>> any of the dynamic update functions because some other nodes ends up as
>>> of_allnodes.
>>>
>>> Fixes: c22e650e66b8 of: Make of_find_node_by_path() handle /aliases
>>
>> Is it not possible to do a fix in of_find_node_by_path instead? I just
>> wonder if this could have any other unintended side-effects on
>> of_attach_node's behavior.
>
> Given that I'm going to replace the custom list with list_head which
> makes this problem go away, I think this solution is fine.
>
> Acked-by: Grant Likely <[email protected]>

That said, the following might be better because it would guarantee
that children always appear after parents...

>> Rob
>>
>>>
>>> Signed-off-by: Frank Rowand <[email protected]>
>>> ---
>>>
>>>
>>> Pantelis,
>>>
>>> Can you test whether the problem you reported in irc?
>>>
>>> This patch has not been tested, not even compile tested.
>>>
>>>
>>> drivers/of/base.c | 8 6 + 2 - 0 !
>>> 1 file changed, 6 insertions(+), 2 deletions(-)
>>>
>>> Index: b/drivers/of/base.c
>>> ===================================================================
>>> --- a/drivers/of/base.c
>>> +++ b/drivers/of/base.c
>>> @@ -1948,6 +1948,9 @@ int of_reconfig_notify(unsigned long act
>>>
>>> /**
>>> * of_attach_node - Plug a device node into the tree and global list.
>>> + *
>>> + * Put the device node after of_allnodes in the global list so that
>>> + * of_allnodes remains the root.
>>> */
>>> int of_attach_node(struct device_node *np)
>>> {
>>> @@ -1958,11 +1961,12 @@ int of_attach_node(struct device_node *n
>>> if (rc)
>>> return rc;
>>>
>>> + BUG_ON(!of_allnodes);
>>> raw_spin_lock_irqsave(&devtree_lock, flags);
>>> np->sibling = np->parent->child;
>>> - np->allnext = of_allnodes;
>>> + np->allnext = of_allnodes->allnext;

np->allnext = np->parent->allnext;
np->parent->allnext = np;

>>> np->parent->child = np;
>>> - of_allnodes = np;
>>> + of_allnodes->allnext = np;
>>> of_node_clear_flag(np, OF_DETACHED);
>>> raw_spin_unlock_irqrestore(&devtree_lock, flags);
>>>

2014-06-15 03:36:47

by Frank Rowand

[permalink] [raw]
Subject: Re: [RFC PATCH] OF: fix of_find_node_by_path() assumption that of_allnodes is root

On 6/14/2014 8:00 AM, Grant Likely wrote:
> On Fri, Jun 13, 2014 at 4:06 PM, Grant Likely <[email protected]> wrote:
>> On Fri, Jun 13, 2014 at 2:52 PM, Rob Herring <[email protected]> wrote:
>>> On Fri, Jun 13, 2014 at 12:53 AM, Frank Rowand <[email protected]> wrote:
>>>> From: Frank Rowand <[email protected]>
>>>>
>>>> Pantelis Antoniou reports that of_find_node_by_path() is borked because
>>>> of_allnodes is not guaranteed to contain the root of the tree after using
>>>> any of the dynamic update functions because some other nodes ends up as
>>>> of_allnodes.
>>>>
>>>> Fixes: c22e650e66b8 of: Make of_find_node_by_path() handle /aliases
>>>
>>> Is it not possible to do a fix in of_find_node_by_path instead? I just
>>> wonder if this could have any other unintended side-effects on
>>> of_attach_node's behavior.
>>
>> Given that I'm going to replace the custom list with list_head which
>> makes this problem go away, I think this solution is fine.
>>
>> Acked-by: Grant Likely <[email protected]>
>
> That said, the following might be better because it would guarantee
> that children always appear after parents...

< snip >

I agree, I like that better. Patch respun, v2 will be sent as a reply
to this email.

Pantelis, can you test v2 please?

Thanks,

Frank

2014-06-15 03:39:09

by Frank Rowand

[permalink] [raw]
Subject: Re: [RFC PATCH] OF: fix of_find_node_by_path() assumption that of_allnodes is root

From: Frank Rowand <[email protected]>

of_find_node_by_path() is borked because of_allnodes is not guaranteed to
contain the root of the tree after using any of the dynamic update functions
because some other nodes ends up as of_allnodes.

Fixes: c22e650e66b8 of: Make of_find_node_by_path() handle /aliases
Reported-by: [email protected]
Signed-off-by: Frank Rowand <[email protected]>
---

v2:
Remove change to function header, no longer needed.
Remove BUG_ON(), no longer needed.
Add np as np->parent->allnext instead of np->parent->allnext, as suggested
by Grant Likely.


drivers/of/base.c | 4 2 + 2 - 0 !
1 file changed, 2 insertions(+), 2 deletions(-)

Index: b/drivers/of/base.c
===================================================================
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1960,9 +1960,9 @@ int of_attach_node(struct device_node *n

raw_spin_lock_irqsave(&devtree_lock, flags);
np->sibling = np->parent->child;
- np->allnext = of_allnodes;
+ np->allnext = np->parent->allnext;
+ np->parent->allnext = np;
np->parent->child = np;
- of_allnodes = np;
of_node_clear_flag(np, OF_DETACHED);
raw_spin_unlock_irqrestore(&devtree_lock, flags);

2014-06-15 03:42:10

by Frank Rowand

[permalink] [raw]
Subject: Re: [RFC PATCH] OF: fix of_find_node_by_path() assumption that of_allnodes is root

On 6/14/2014 8:39 PM, Frank Rowand wrote:
> From: Frank Rowand <[email protected]>
>
> of_find_node_by_path() is borked because of_allnodes is not guaranteed to
> contain the root of the tree after using any of the dynamic update functions
> because some other nodes ends up as of_allnodes.
>
> Fixes: c22e650e66b8 of: Make of_find_node_by_path() handle /aliases
> Reported-by: [email protected]
> Signed-off-by: Frank Rowand <[email protected]>
> ---
>
> v2:
> Remove change to function header, no longer needed.
> Remove BUG_ON(), no longer needed.
> Add np as np->parent->allnext instead of np->parent->allnext, as suggested

Aaaargh, cut and paste error, that should be:

Add np as np->parent->allnext instead of of_allnodes->allnext, as suggested

> by Grant Likely.
>
>
> drivers/of/base.c | 4 2 + 2 - 0 !
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> Index: b/drivers/of/base.c
> ===================================================================
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -1960,9 +1960,9 @@ int of_attach_node(struct device_node *n
>
> raw_spin_lock_irqsave(&devtree_lock, flags);
> np->sibling = np->parent->child;
> - np->allnext = of_allnodes;
> + np->allnext = np->parent->allnext;
> + np->parent->allnext = np;
> np->parent->child = np;
> - of_allnodes = np;
> of_node_clear_flag(np, OF_DETACHED);
> raw_spin_unlock_irqrestore(&devtree_lock, flags);
>
>