From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Gibson Subject: Re: [PATCH v2] libfdt: Add fdt_next_subnode() to permit easy subnode iteration Date: Sat, 27 Apr 2013 09:13:45 +1000 Message-ID: <20130426231345.GA20202@truffula.fritz.box> References: <1366914176-28684-1-git-send-email-sjg@chromium.org> <1366980211-30077-1-git-send-email-sjg@chromium.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2148040430410744533==" Return-path: In-Reply-To: <1366980211-30077-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: devicetree-discuss-bounces+gldd-devicetree-discuss=m.gmane.org-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org Sender: "devicetree-discuss" To: Simon Glass Cc: Devicetree Discuss List-Id: devicetree@vger.kernel.org --===============2148040430410744533== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="BOKacYhQ+x31HxR3" Content-Disposition: inline --BOKacYhQ+x31HxR3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Apr 26, 2013 at 05:43:31AM -0700, Simon Glass wrote: > Iterating through subnodes with libfdt is a little painful to write as we > need something like this: >=20 > for (depth =3D 0, count =3D 0, > offset =3D fdt_next_node(fdt, parent_offset, &depth); > (offset >=3D 0) && (depth > 0); > offset =3D fdt_next_node(fdt, offset, &depth)) { > if (depth =3D=3D 1) { > /* code body */ > } > } >=20 > Using fdt_next_subnode() we can instead write this, which is shorter and > easier to get right: >=20 > for (offset =3D fdt_first_subnode(fdt, parent_offset); > offset >=3D 0; > offset =3D fdt_next_subnode(fdt, offset)) { > /* code body */ > } >=20 > Also, it doesn't require two levels of indentation for the loop body. >=20 > Signed-off-by: Simon Glass Nice! Acked-by: David Gibson Jon, please apply. --=20 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 --BOKacYhQ+x31HxR3 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlF7CikACgkQaILKxv3ab8bUsQCfc3+FeT+IMcBN5sP5HT7K6RoT gI0Anjcy9IqDI3uB5PNKhHl59VjFRwwE =vm3p -----END PGP SIGNATURE----- --BOKacYhQ+x31HxR3-- --===============2148040430410744533== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org https://lists.ozlabs.org/listinfo/devicetree-discuss --===============2148040430410744533==--