xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: David Vrabel <david.vrabel@citrix.com>
To: Ian Campbell <Ian.Campbell@citrix.com>
Cc: "xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>
Subject: Re: [PATCH 3/8] device tree: add device_tree_for_each_node()
Date: Wed, 14 Mar 2012 11:01:24 +0000	[thread overview]
Message-ID: <4F607A84.6060109@citrix.com> (raw)
In-Reply-To: <1331719680.23971.365.camel@zakaz.uk.xensource.com>

On 14/03/12 10:08, Ian Campbell wrote:
> On Tue, 2012-02-28 at 16:54 +0000, David Vrabel wrote:
>> From: David Vrabel <david.vrabel@citrix.com>
>>
>> Add device_tree_for_each_node() to iterate over all nodes in a flat
>> device tree.  Use this in device_tree_early_init().
>>
>> Signed-off-by: David Vrabel <david.vrabel@citrix.com>
>> ---
>>  xen/common/device_tree.c      |   71 ++++++++++++++++++++++++++---------------
>>  xen/include/xen/device_tree.h |    8 +++++
>>  2 files changed, 53 insertions(+), 26 deletions(-)
>>
>> diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
>> index e5df748..e95ff3c 100644
>> --- a/xen/common/device_tree.c
>> +++ b/xen/common/device_tree.c
>> @@ -66,7 +66,42 @@ static u32 __init prop_by_name_u32(const void *fdt, int node, const char *prop_n
>>      return fdt32_to_cpu(*(uint32_t*)prop->data);
>>  }
>>  
>> -static void __init process_memory_node(const void *fdt, int node,
>> +#define MAX_DEPTH 16
>> +
>> +/**
>> + * device_tree_for_each_node - iterate over all device tree nodes
>> + * @fdt: flat device tree.
>> + * @func: function to call for each node.
>> + * @data: data to pass to @func.
>> + */
>> +int device_tree_for_each_node(const void *fdt,
>> +                              device_tree_node_func func, void *data)
>> +{
>> +    int node;
>> +    int depth;
>> +    u32 address_cells[MAX_DEPTH];
>> +    u32 size_cells[MAX_DEPTH];
>> +    int ret;
>> +
>> +    for (node = 0, depth = 0;
>> +         node >=0 && depth >= 0;
>> +         node = fdt_next_node(fdt, node, &depth))
> 
> Xen coding style has spaces both sides of the outermost "(" and ")" of a
> for loop (similarly for if / while etc)

This is a minor difference between the Linux and Xen coding styles.
Given people often work on both can we not aim for more consistency
between the two?

I personally think the additional spaces reduce readability (but this is
probably mostly because I'm more familiar with Linux style rather than
any inherent improvement).

My recommendation would be to allow both styles of spacing withing Xen
but make it consistent within a file.

>> +    {
>> +        if (depth >= MAX_DEPTH)
> 
> Some sort of warning or error message would be useful here?

Tricky as this function is called early before printk() works and later
(when it does).

>> +            continue;
>> +
>> +        address_cells[depth] = prop_by_name_u32(fdt, node, "#address-cells");
>> +        size_cells[depth] = prop_by_name_u32(fdt, node, "#size-cells");
>> +
>> +        ret = func(fdt, node, fdt_get_name(fdt, node, NULL), depth,
>> +                   address_cells[depth-1], size_cells[depth-1], data);
> 
> I suppose this function could have been written recursively and avoided
> the arbitrary MAX_DEPTH, but actually in the hypervisor an iterative
> version with explicit maximum stack usage seems like a reasonable idea.

This is why I used a loop.

> I should have spotted this before, coding style needs a space inside the
> () and { should be on the next line. There's a bunch of this in both the
> context and the new code added by this patch. Obviously the new code
> should be fixed, I don't mind if you deal with the existing bits by a
> cleanup sweep or by picking it up as you go along.

See comment above.

David

  reply	other threads:[~2012-03-14 11:01 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-28 16:54 [PATCH 0/8] arm: pass a device tree to dom0 David Vrabel
2012-02-28 16:54 ` [PATCH 1/8] arm: add generated files to .gitignore and .hgignore David Vrabel
2012-03-14  9:53   ` Ian Campbell
2012-02-28 16:54 ` [PATCH 2/8] device tree: correctly ignore unit-address when matching nodes by name David Vrabel
2012-03-14 10:00   ` Ian Campbell
2012-03-14 10:48     ` David Vrabel
2012-02-28 16:54 ` [PATCH 3/8] device tree: add device_tree_for_each_node() David Vrabel
2012-03-14 10:08   ` Ian Campbell
2012-03-14 11:01     ` David Vrabel [this message]
2012-03-14 11:09       ` Ian Campbell
2012-02-28 16:54 ` [PATCH 4/8] device tree: add device_tree_dump() to print a flat device tree David Vrabel
2012-03-14 10:11   ` Ian Campbell
2012-02-28 16:54 ` [PATCH 5/8] arm: remove the hack for loading vmlinux images David Vrabel
2012-03-14 10:17   ` Ian Campbell
2012-03-14 10:51     ` David Vrabel
2012-02-28 16:54 ` [PATCH 6/8] device tree, arm: supply a flat device tree to dom0 David Vrabel
2012-03-14 10:44   ` Ian Campbell
2012-03-14 11:17     ` David Vrabel
2012-03-14 13:00       ` Ian Campbell
2012-02-28 16:54 ` [PATCH 7/8] arm: use bootargs for the command line David Vrabel
2012-03-14 10:46   ` Ian Campbell
2012-03-14 11:26     ` David Vrabel
2012-02-28 16:54 ` [PATCH 8/8] arm: add dom0_mem command line argument David Vrabel
2012-03-14 10:48   ` Ian Campbell
2012-03-14 11:27     ` David Vrabel

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=4F607A84.6060109@citrix.com \
    --to=david.vrabel@citrix.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /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).