public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Jerry Van Baren <gerald.vanbaren@smiths-aerospace.com>
To: u-boot@lists.denx.de
Subject: [U-Boot-Users] fdt_find_compatible_node() and friends
Date: Thu, 17 May 2007 08:04:38 -0400	[thread overview]
Message-ID: <464C44D6.7060002@smiths-aerospace.com> (raw)
In-Reply-To: <464C3D3A.5020409@grandegger.com>

Wolfgang Grandegger wrote:
> Hi Jerry,
> 
> Jerry Van Baren wrote:
> [...]
>> Hi Wolfgang G,
>>
>> I've applied your patches to my local (working) repository and will push 
>> the changes tonight (my tonight, your tomorrow ;-).  I created a 
>> subroutine out of three snippets of code in cmd_fdt.c which your 
>> fdt_find_node_by_path() change  fixed up so I had to fix one line in the 
>> new subroutine by hand.  Not bad at all considering the changes I made 
>> in that file.
> 
> Thanks. In the meantime I observed, that
> 
>    fdt_find_node_by_path(fdt, 0, "/");
> 
> returns an error. Is that by purpose?
[snip]
> Wolfgang.

Hmm, interesting observation.  The character '/' is a figment of our 
imagination, offset 0 in the tree is the root node.  The character '/' 
is the path separator and doesn't actually exist anywhere in the fdt - 
when parsing paths, the stuff between the slashes is searched for and 
the slashes themselves are skipped over.

What you asked in the above call is a node with no name under the root 
node, i.e. "//" in human-speak.  That wasn't found, of course.  On the 
other hand, it is a pretty obvious "mistake" (I was guilty of making the 
same mistake when I first tried to use fdt_path_offset()).

It seems like I was forever doing a conditional:

59     if (strcmp(pathp, "/") == 0) {
60             nodeoffset = 0;
61     } else {
62             nodeoffset = fdt_path_offset (fdt, pathp);
63             if (nodeoffset < 0) {

<http://www.denx.de/cgi-bin/gitweb.cgi?p=u-boot/u-boot-fdt.git;a=blob;f=common/cmd_fdt.c;h=bf0aef70cedea6ec4a2a446af54c9e1467617a96;hb=HEAD#l55>

Trivia: Your patch we are discussing changed exactly this 
fdt_path_offset() into fdt_find_node_by_path() - this is the one place 
your patch didn't apply, because I refactored the three conditionals 
into a single wrapper subroutine.

At the risk of being accused of codling our users, I would propose we 
add the equivalent "/" detection code (above) to 
fdt_find_node_by_path(), (I will do that tonight unless you beat me to 
it).  It seems silly to have the caller replicate or wrap the 
conditional since it is going to be such a common idiom/mistake.

Thanks,
gvb

  reply	other threads:[~2007-05-17 12:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-03 14:47 [U-Boot-Users] fdt_find_compatible_node() and friends Wolfgang Grandegger
2007-05-03 15:14 ` Jerry Van Baren
2007-05-05 13:03   ` Wolfgang Grandegger
2007-05-16 10:40     ` Wolfgang Grandegger
2007-05-16 13:33       ` Jerry Van Baren
2007-05-17 10:38     ` Jerry Van Baren
2007-05-17 11:32       ` Wolfgang Grandegger
2007-05-17 12:04         ` Jerry Van Baren [this message]
2007-05-17 12:31           ` Wolfgang Grandegger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=464C44D6.7060002@smiths-aerospace.com \
    --to=gerald.vanbaren@smiths-aerospace.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox