From: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
To: Maxime Ripard
<maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
Cc: "Pantelis Antoniou"
<pantelis.antoniou-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>,
"Simon Glass" <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
"Boris Brezillon"
<boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>,
"Alexander Kaplan" <alex-MflLfwwFzuz+yO7R74ARew@public.gmane.org>,
"Thomas Petazzoni"
<thomas.petazzoni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>,
devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
"Antoine Ténart"
<antoine.tenart-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>,
"Stefan Agner" <stefan-XLVq0VzYD2Y@public.gmane.org>,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v2 2/6] libfdt: Add iterator over properties
Date: Tue, 12 Jul 2016 11:53:35 +1000 [thread overview]
Message-ID: <20160712015335.GO16355@voom.fritz.box> (raw)
In-Reply-To: <20160711195623.12840-3-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 7389 bytes --]
On Mon, Jul 11, 2016 at 09:56:19PM +0200, Maxime Ripard wrote:
> Implement a macro based on fdt_first_property_offset and
> fdt_next_property_offset that provides a convenience to iterate over all
> the properties of a given node.
>
> Signed-off-by: Maxime Ripard <maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
> Acked-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
As with 1/6 code looks ok, but there are a couple of nits in the comment.
> ---
> libfdt/libfdt.h | 24 ++++++++++++
> tests/.gitignore | 1 +
> tests/Makefile.tests | 1 +
> tests/property_iterate.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++
> tests/property_iterate.dts | 24 ++++++++++++
> tests/run_tests.sh | 3 ++
> 6 files changed, 150 insertions(+)
> create mode 100644 tests/property_iterate.c
> create mode 100644 tests/property_iterate.dts
>
> diff --git a/libfdt/libfdt.h b/libfdt/libfdt.h
> index 0cf46872b54e..9d3c9b234274 100644
> --- a/libfdt/libfdt.h
> +++ b/libfdt/libfdt.h
> @@ -455,6 +455,30 @@ int fdt_first_property_offset(const void *fdt, int nodeoffset);
> */
> int fdt_next_property_offset(const void *fdt, int offset);
>
> +/**
> + * fdt_for_each_property - iterate over all properties of a node
> + * @property_offset: property offset (int)
> + * @fdt: FDT blob (const void *)
> + * @node: node offset (int)
> + *
> + * This is actually a wrapper around a for loop and would be used like so:
> + *
> + * fdt_for_each_property(fdt, node, property) {
Again, parameter order is out of date.
> + * ...
> + * use property
> + * ...
> + * }
Again add an error handling clause.
> + *
> + * Note that this is implemented as a macro and property is used as
> + * iterator in the loop. It should therefore be a locally allocated
> + * variable. The node variable on the other hand is never modified, so
> + * it can be constant or even a literal.
Similar edits for brevity as 1/6.
> + */
> +#define fdt_for_each_property_offset(property, fdt, node) \
> + for (property = fdt_first_property_offset(fdt, node); \
> + property >= 0; \
> + property = fdt_next_property_offset(fdt, property))
> +
> /**
> * fdt_get_property_by_offset - retrieve the property at a given offset
> * @fdt: pointer to the device tree blob
> diff --git a/tests/.gitignore b/tests/.gitignore
> index e4532da30bf5..fa4616ba28c2 100644
> --- a/tests/.gitignore
> +++ b/tests/.gitignore
> @@ -40,6 +40,7 @@ tmp.*
> /path_offset
> /path_offset_aliases
> /phandle_format
> +/property_iterate
> /propname_escapes
> /references
> /root_node
> diff --git a/tests/Makefile.tests b/tests/Makefile.tests
> index f7c3a4b00ead..196518c83eda 100644
> --- a/tests/Makefile.tests
> +++ b/tests/Makefile.tests
> @@ -23,6 +23,7 @@ LIB_TESTS_L = get_mem_rsv \
> add_subnode_with_nops path_offset_aliases \
> utilfdt_test \
> integer-expressions \
> + property_iterate \
> subnode_iterate
> LIB_TESTS = $(LIB_TESTS_L:%=$(TESTS_PREFIX)%)
>
> diff --git a/tests/property_iterate.c b/tests/property_iterate.c
> new file mode 100644
> index 000000000000..0f3959cb8c22
> --- /dev/null
> +++ b/tests/property_iterate.c
> @@ -0,0 +1,97 @@
> +/*
> + * libfdt - Flat Device Tree manipulation
> + * Tests that fdt_next_subnode() works as expected
> + *
> + * Copyright (C) 2013 Google, Inc
> + *
> + * Copyright (C) 2007 David Gibson, IBM Corporation.
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public License
> + * as published by the Free Software Foundation; either version 2.1 of
> + * the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include <stdlib.h>
> +#include <stdio.h>
> +#include <string.h>
> +#include <stdint.h>
> +
> +#include <libfdt.h>
> +
> +#include "tests.h"
> +#include "testdata.h"
> +
> +static void test_node(void *fdt, int parent_offset)
> +{
> + fdt32_t properties;
> + const fdt32_t *prop;
> + int offset, property;
> + int count;
> + int len;
> +
> + /*
> + * This property indicates the number of properties in our
> + * test node to expect
> + */
> + prop = fdt_getprop(fdt, parent_offset, "test-properties", &len);
> + if (!prop || len != sizeof(fdt32_t)) {
> + FAIL("Missing/invalid test-properties property at '%s'",
> + fdt_get_name(fdt, parent_offset, NULL));
> + }
> + properties = cpu_to_fdt32(*prop);
> +
> + count = 0;
> + offset = fdt_first_subnode(fdt, parent_offset);
> + if (offset < 0)
> + FAIL("Missing test node\n");
> +
> + fdt_for_each_property_offset(property, fdt, offset)
> + count++;
> +
> + if (count != properties) {
> + FAIL("Node '%s': Expected %d properties, got %d\n",
> + fdt_get_name(fdt, parent_offset, NULL), properties,
> + count);
> + }
> +}
> +
> +static void check_fdt_next_subnode(void *fdt)
> +{
> + int offset;
> + int count = 0;
> +
> + fdt_for_each_subnode(offset, fdt, 0) {
> + test_node(fdt, offset);
> + count++;
> + }
> +
> + if (count != 2)
> + FAIL("Expected %d tests, got %d\n", 2, count);
> +}
> +
> +int main(int argc, char *argv[])
> +{
> + void *fdt;
> +
> + test_init(argc, argv);
> + if (argc != 2)
> + CONFIG("Usage: %s <dtb file>", argv[0]);
> +
> + fdt = load_blob(argv[1]);
> + if (!fdt)
> + FAIL("No device tree available");
> +
> + check_fdt_next_subnode(fdt);
> +
> + PASS();
> +}
> diff --git a/tests/property_iterate.dts b/tests/property_iterate.dts
> new file mode 100644
> index 000000000000..2ed677e7e6ea
> --- /dev/null
> +++ b/tests/property_iterate.dts
> @@ -0,0 +1,24 @@
> +/dts-v1/;
> +
> +/ {
> + #address-cells = <1>;
> + #size-cells = <0>;
> +
> + test1 {
> + test-properties = <3>;
> +
> + test {
> + linux,phandle = <0x1>;
> + #address-cells = <1>;
> + #size-cells = <0>;
> + };
> + };
> +
> + test2 {
> + test-properties = <0>;
> +
> + test {
> + };
> + };
> +};
> +
> diff --git a/tests/run_tests.sh b/tests/run_tests.sh
> index 7eb9b3d33108..6a2662b2abaf 100755
> --- a/tests/run_tests.sh
> +++ b/tests/run_tests.sh
> @@ -269,6 +269,9 @@ libfdt_tests () {
> run_dtc_test -I dts -O dtb -o subnode_iterate.dtb subnode_iterate.dts
> run_test subnode_iterate subnode_iterate.dtb
>
> + run_dtc_test -I dts -O dtb -o property_iterate.dtb property_iterate.dts
> + run_test property_iterate property_iterate.dtb
> +
> # Tests for behaviour on various sorts of corrupted trees
> run_test truncated_property
>
--
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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
next prev parent reply other threads:[~2016-07-12 1:53 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-11 19:56 [PATCH v2 0/6] libfdt: Add support for device tree overlays Maxime Ripard
[not found] ` <20160711195623.12840-1-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-07-11 19:56 ` [PATCH v2 1/6] libfdt: Add a subnodes iterator macro Maxime Ripard
[not found] ` <20160711195623.12840-2-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-07-12 1:52 ` David Gibson
2016-07-11 19:56 ` [PATCH v2 2/6] libfdt: Add iterator over properties Maxime Ripard
[not found] ` <20160711195623.12840-3-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-07-12 1:53 ` David Gibson [this message]
[not found] ` <20160712015335.GO16355-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
2016-07-12 1:57 ` Robert P. J. Day
[not found] ` <alpine.LFD.2.20.1607111856210.14522-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2016-07-12 2:29 ` David Gibson
2016-07-11 19:56 ` [PATCH v2 3/6] libfdt: Add max phandle retrieval function Maxime Ripard
[not found] ` <20160711195623.12840-4-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-07-12 2:02 ` David Gibson
2016-07-11 19:56 ` [PATCH v2 4/6] libfdt: Add fdt_getprop_namelen_w Maxime Ripard
[not found] ` <20160711195623.12840-5-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-07-12 2:03 ` David Gibson
2016-07-11 19:56 ` [PATCH v2 5/6] libfdt: Add fdt_setprop_inplace_namelen_partial Maxime Ripard
[not found] ` <20160711195623.12840-6-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-07-12 11:45 ` David Gibson
[not found] ` <20160712114520.GB16355-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
2016-07-18 13:45 ` Maxime Ripard
2016-07-21 13:04 ` David Gibson
2016-07-11 19:56 ` [PATCH v2 6/6] libfdt: Add overlay application function Maxime Ripard
[not found] ` <20160711195623.12840-7-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-07-11 20:20 ` Phil Elwell
[not found] ` <ed025e59-ddb3-0309-b2da-f6c2d1fa95d0-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-07-12 14:34 ` David Gibson
[not found] ` <20160712143404.GD16355-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
2016-07-12 15:07 ` Phil Elwell
[not found] ` <CAPhXvM5nCbP81ujx3dhy9GvibdoBDy+N8EuArJj2-RFKO3ixfQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-07-13 4:45 ` David Gibson
2016-07-13 8:38 ` Maxime Ripard
2016-07-13 15:07 ` David Gibson
[not found] ` <20160713150745.GG14615-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
2016-07-13 19:37 ` Maxime Ripard
2016-07-14 8:30 ` David Gibson
[not found] ` <20160714083058.GN14615-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
2016-07-15 9:18 ` Phil Elwell
[not found] ` <CAPhXvM53bMUypbUYSgC6BbAar2=dD8Y=Ktpu3LQzRTGx=yJesQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-07-18 4:39 ` David Gibson
2016-07-18 13:07 ` Maxime Ripard
2016-07-12 14:31 ` David Gibson
[not found] ` <20160712143120.GC16355-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
2016-07-13 20:12 ` Maxime Ripard
2016-07-14 9:02 ` David Gibson
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=20160712015335.GO16355@voom.fritz.box \
--to=david-xt8fgy+axnrb3ne2bgzf6laj5h9x9tb+@public.gmane.org \
--cc=alex-MflLfwwFzuz+yO7R74ARew@public.gmane.org \
--cc=antoine.tenart-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
--cc=boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
--cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
--cc=pantelis.antoniou-OWPKS81ov/FWk0Htik3J/w@public.gmane.org \
--cc=sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
--cc=stefan-XLVq0VzYD2Y@public.gmane.org \
--cc=thomas.petazzoni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.