From: David Vrabel Subject: [PATCH 2/8] device tree: correctly ignore unit-address when matching nodes by name Date: Tue, 28 Feb 2012 16:54:18 +0000 Message-ID: <1330448064-32267-3-git-send-email-david.vrabel@citrix.com> References: <1330448064-32267-1-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1330448064-32267-1-git-send-email-david.vrabel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xensource.com Cc: Ian Campbell , David Vrabel List-Id: xen-devel@lists.xenproject.org From: David Vrabel When matching node by their name, correctly ignore the unit address (@...) part of the name. Previously, a "memory-controller" node would be incorrectly matched as a "memory" node. Signed-off-by: David Vrabel --- xen/common/device_tree.c | 19 +++++++++++++++---- 1 files changed, 15 insertions(+), 4 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index d50cb9c..e5df748 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -24,6 +24,20 @@ struct dt_early_info __initdata early_info; void *device_tree_flattened; +static bool_t __init node_matches(const void *fdt, int node, const char *match) +{ + const char *name; + size_t len; + + name = fdt_get_name(fdt, node, NULL); + len = strlen(match); + + /* Match both "match" and "match@..." patterns but not + "match-foo". */ + return strncmp(name, match, len) == 0 + && (name[len] == '@' || name[len] == '\0'); +} + static void __init get_val(const u32 **cell, u32 cells, u64 *val) { *val = 0; @@ -93,13 +107,10 @@ static void __init early_scan(const void *fdt) { int node; int depth; - const char *name; u32 address_cells[MAX_DEPTH]; u32 size_cells[MAX_DEPTH]; for (node = 0; depth >= 0; node = fdt_next_node(fdt, node, &depth)) { - name = fdt_get_name(fdt, node, NULL); - if (depth >= MAX_DEPTH) { early_printk("fdt: node '%s': nested too deep\n", fdt_get_name(fdt, node, NULL)); @@ -109,7 +120,7 @@ static void __init early_scan(const void *fdt) address_cells[depth] = prop_by_name_u32(fdt, node, "#address-cells"); size_cells[depth] = prop_by_name_u32(fdt, node, "#size-cells"); - if (strncmp(name, "memory", 6) == 0) + if (node_matches(fdt, node, "memory")) process_memory_node(fdt, node, address_cells[depth-1], size_cells[depth-1]); } } -- 1.7.2.5