From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Vrabel Subject: Re: [PATCH 2/8] device tree: correctly ignore unit-address when matching nodes by name Date: Wed, 14 Mar 2012 10:48:58 +0000 Message-ID: <4F60779A.2090905@citrix.com> References: <1330448064-32267-1-git-send-email-david.vrabel@citrix.com> <1330448064-32267-3-git-send-email-david.vrabel@citrix.com> <1331719214.23971.359.camel@zakaz.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1331719214.23971.359.camel@zakaz.uk.xensource.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: Ian Campbell Cc: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org On 14/03/12 10:00, Ian Campbell wrote: > On Tue, 2012-02-28 at 16:54 +0000, David Vrabel wrote: >> 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. > > Are we reinventing this ourselves or is this derived from the Linux (or > other) version of similar code? Linux doesn't have an equivalent node_matches() function. Linux could do with one as it open-codes a bunch of these comparisons. >> 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'); > > How can name[len] == '@' when len came from strlen? Wouldn't you need > some sort of strchr construct? I can rename len to match_len if you think it makes it clearer. David