summaryrefslogtreecommitdiff
path: root/livetree.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2010-02-23 19:56:41 +1100
committerJon Loeliger <jdl@jdl.com>2010-02-23 09:04:48 -0600
commit329055dbbc3c09e21386ceae788256991f4c8aec (patch)
tree92d2c0fee03699a262080183cc2f4c756972a24e /livetree.c
parent15ad6d862ec7f66dc00783798705a8db1c5d9aca (diff)
downloaddtc-329055dbbc3c09e21386ceae788256991f4c8aec.tar.gz
Disallow re-use of the same label within a dts file
Currently, nothing will stop you from re-using the same label string multiple times in a dts, e.g.: / { samelabel: prop1 = "foo"; samelabel: prop2 = "bar"; }; or / { samelabel: prop1 = "foo"; samelabel: subnode { }; }; When using node references by label, this could lead to confusing results (with no warning), and in -Oasm mode will result in output which the assembler will complain about (since it too will have duplicate labels). This patch, therefore, adds code to checks.c to give errors if you attempt to re-use the same label. It treats all labels (node, property, and value) as residing in the same namespace, since the assembler will treat them so for -Oasm mode. Testcases for the new code are also added. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'livetree.c')
-rw-r--r--livetree.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/livetree.c b/livetree.c
index 0230949..aa0edf1 100644
--- a/livetree.c
+++ b/livetree.c
@@ -208,6 +208,57 @@ cell_t propval_cell(struct property *prop)
return fdt32_to_cpu(*((cell_t *)prop->val.val));
}
+struct property *get_property_by_label(struct node *tree, const char *label,
+ struct node **node)
+{
+ struct property *prop;
+ struct node *c;
+
+ *node = tree;
+
+ for_each_property(tree, prop) {
+ if (prop->label && streq(prop->label, label))
+ return prop;
+ }
+
+ for_each_child(tree, c) {
+ prop = get_property_by_label(c, label, node);
+ if (prop)
+ return prop;
+ }
+
+ *node = NULL;
+ return NULL;
+}
+
+struct marker *get_marker_label(struct node *tree, const char *label,
+ struct node **node, struct property **prop)
+{
+ struct marker *m;
+ struct property *p;
+ struct node *c;
+
+ *node = tree;
+
+ for_each_property(tree, p) {
+ *prop = p;
+ m = p->val.markers;
+ for_each_marker_of_type(m, LABEL)
+ if (streq(m->ref, label))
+ return m;
+ }
+
+ for_each_child(tree, c) {
+ m = get_marker_label(c, label, node, prop);
+ if (m)
+ return m;
+ }
+
+ *prop = NULL;
+ *node = NULL;
+ return NULL;
+}
+
struct node *get_subnode(struct node *node, const char *nodename)
{
struct node *child;