devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
To: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Cc: Devicetree Discuss
	<devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org>
Subject: Re: [PATCH] libfdt: Add fdt_next_subnode() to permit easy subnode iteration
Date: Fri, 26 Apr 2013 21:59:51 +1000	[thread overview]
Message-ID: <20130426115951.GD4360@truffula.fritz.box> (raw)
In-Reply-To: <1366914176-28684-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>


[-- Attachment #1.1: Type: text/plain, Size: 1182 bytes --]

On Thu, Apr 25, 2013 at 11:22:56AM -0700, Simon Glass wrote:
> Iterating through subnodes with libfdt is a little painful to write as we
> need something like this:
> 
> for (depth = 0, count = 0,
> 	offset = fdt_next_node(fdt, parent_offset, &depth);
>      (offset >= 0) && (depth > 0);
>      offset = fdt_next_node(fdt, offset, &depth)) {
> 	if (depth == 1) {
> 		/* code body */
> 	}
> }
> 
> Using fdt_next_subnode() we can instead write this, which is shorter and
> easier to get right:
> 
> for (depth = 0, offset = fdt_next_subnode(fdt, parent_offset, &depth);
>      offset >= 0;
>      offset = fdt_next_subnode(fdt, offset, &depth)) {
> 	/* code body */
> }
> 
> Also, it doesn't require two levels of indentation for the loop
> body.

I like the idea in principle.  But if you split this into
find_first_subnode() and find_next_subnode() functions, you should be
able to get rid of the requirement for the caller to provide the depth
variable.

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

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 192 bytes --]

_______________________________________________
devicetree-discuss mailing list
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
https://lists.ozlabs.org/listinfo/devicetree-discuss

  parent reply	other threads:[~2013-04-26 11:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-25 18:22 [PATCH] libfdt: Add fdt_next_subnode() to permit easy subnode iteration Simon Glass
     [not found] ` <1366914176-28684-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2013-04-26 11:59   ` David Gibson [this message]
2013-04-26 12:43   ` [PATCH v2] " Simon Glass
     [not found]     ` <1366980211-30077-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2013-04-26 23:13       ` David Gibson
     [not found]         ` <20130426231345.GA20202-W9XWwYn+TF0XU02nzanrWNbf9cGiqdzd@public.gmane.org>
2013-04-28 12:33           ` Jon Loeliger

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=20130426115951.GD4360@truffula.fritz.box \
    --to=david-xt8fgy+axnrb3ne2bgzf6laj5h9x9tb+@public.gmane.org \
    --cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
    --cc=sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
    /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;
as well as URLs for NNTP newsgroup(s).