On Wed, Oct 20, 2010 at 02:45:13PM -0700, John Bonesio wrote:
> Changes to allow us to specify a node by it's path. A path can be used in
> place of a label.
> 
> This is particularly useful when overriding existing nodes.
> This way we don't have to label every possible node in a device tree we know
> is a base device tree for a class of systems, and we know the tree will be
> modified for the specific systems.

[snip]
> diff --git a/livetree.c b/livetree.c
> index 21a4c48..bf8796b 100644
> --- a/livetree.c
> +++ b/livetree.c
> @@ -429,10 +429,28 @@ struct node *get_node_by_phandle(struct node *tree, 
> cell_t phandle)
>  
>  struct node *get_node_by_ref(struct node *tree, const char *ref)
>  {
> +     struct node *node;
> +
>       if (ref[0] == '/')
>               return get_node_by_path(tree, ref);
> -     else
> +     else {
> +             /*
> +              * Support finding a node reference that is rooted by
> +              * a label reference.
> +              *
> +              * References rooted by a label have a '/' in them.
> +              */
> +             char *p = strchr(ref, '/');

So, this line is effectively un-const-ing part of the string that ref
points to.

> +
> +             if (p) {
> +                     *p = '\0';

And, then you write to it.  Not good at all.  I'm afraid you're going
to have to use a strndup() here.  Or else modify get_node_by_label()
to ignore text after a /.

> +                     node = get_node_by_label(tree, ref);
> +                     *p = '/';
> +                     return get_node_by_path(node, p+1);
> +             }
> +
>               return get_node_by_label(tree, ref);
> +     }
>  }
>  
>  cell_t get_node_phandle(struct node *root, struct node *node)
> 

-- 
David Gibson                    | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
                                | _way_ _around_!
http://www.ozlabs.org/~dgibson
_______________________________________________
devicetree-discuss mailing list
[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss

Reply via email to