diff mbox series

[5/5] checks: add aliases node checks

Message ID 20171117144515.10870-6-robh@kernel.org
State New
Headers show
Series Another batch of dtc checks | expand

Commit Message

Rob Herring (Arm) Nov. 17, 2017, 2:45 p.m. UTC
Add checks for aliases node that properties are a valid path and that the
alias property names are a known, standard name.

Signed-off-by: Rob Herring <robh@kernel.org>

---
 checks.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

-- 
2.14.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

David Gibson Nov. 20, 2017, 12:24 a.m. UTC | #1
On Fri, Nov 17, 2017 at 08:45:15AM -0600, Rob Herring wrote:
> Add checks for aliases node that properties are a valid path and that the

> alias property names are a known, standard name.

> 

> Signed-off-by: Rob Herring <robh@kernel.org>


The check for valid paths is definitely good.  I'm not convinced by
the restrictive list of alias names though.

It's true that in trees originating from dts files, aliases don't have
a lot of purpose, but in trees from real OF that's not so.  It's
pretty reasonable for those to define arbitrary aliases for user
convenience - and the names here aren't even the common ones for that
purpose: those are "net", "disk" and "cd" so you can do things like
"boot disk" from the user interface without having to enter a hideous
path giving PCI and SCSI addresses.

> ---

>  checks.c | 44 ++++++++++++++++++++++++++++++++++++++++++++

>  1 file changed, 44 insertions(+)

> 

> diff --git a/checks.c b/checks.c

> index a785b81bea07..2c5b6c2eacb3 100644

> --- a/checks.c

> +++ b/checks.c

> @@ -637,6 +637,48 @@ static void check_names_is_string_list(struct check *c, struct dt_info *dti,

>  }

>  WARNING(names_is_string_list, check_names_is_string_list, NULL);

>  

> +static void check_alias_paths(struct check *c, struct dt_info *dti,

> +				    struct node *node)

> +{

> +	struct property *prop;

> +

> +	if (!streq(node->name, "aliases"))

> +		return;

> +

> +	for_each_property(node, prop) {

> +		if (!prop->val.val || !get_node_by_path(dti->dt, prop->val.val))

> +			FAIL(c, dti, "aliases property '%s' is not a valid node (%s)",

> +			     prop->name, prop->val.val);

> +	}

> +}

> +WARNING(alias_paths, check_alias_paths, NULL);

> +

> +static void check_known_aliases(struct check *c, struct dt_info *dti,

> +				    struct node *node)

> +{

> +	int i;

> +	struct property *prop;

> +	static char *aliases_strings[] = {

> +		"ethernet", "gpio", "i2c", "rtc", "serial", "spi"

> +	};

> +

> +	if (!streq(node->name, "aliases"))

> +		return;

> +

> +	for_each_property(node, prop) {

> +		for (i = 0; i < ARRAY_SIZE(aliases_strings); i++) {

> +			if (strstarts(prop->name, aliases_strings[i]))

> +				break;

> +		}

> +

> +		if (i == ARRAY_SIZE(aliases_strings)) {

> +			FAIL(c, dti, "unknown alias name %s", prop->name);

> +			continue;

> +		}

> +	}

> +}

> +WARNING(known_aliases, check_known_aliases, NULL);

> +

>  static void fixup_addr_size_cells(struct check *c, struct dt_info *dti,

>  				  struct node *node)

>  {

> @@ -1355,6 +1397,8 @@ static struct check *check_table[] = {

>  	&gpios_property,

>  	&interrupts_property,

>  

> +	&known_aliases,	&alias_paths,

> +

>  	&always_fail,

>  };

>  


-- 
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
diff mbox series

Patch

diff --git a/checks.c b/checks.c
index a785b81bea07..2c5b6c2eacb3 100644
--- a/checks.c
+++ b/checks.c
@@ -637,6 +637,48 @@  static void check_names_is_string_list(struct check *c, struct dt_info *dti,
 }
 WARNING(names_is_string_list, check_names_is_string_list, NULL);
 
+static void check_alias_paths(struct check *c, struct dt_info *dti,
+				    struct node *node)
+{
+	struct property *prop;
+
+	if (!streq(node->name, "aliases"))
+		return;
+
+	for_each_property(node, prop) {
+		if (!prop->val.val || !get_node_by_path(dti->dt, prop->val.val))
+			FAIL(c, dti, "aliases property '%s' is not a valid node (%s)",
+			     prop->name, prop->val.val);
+	}
+}
+WARNING(alias_paths, check_alias_paths, NULL);
+
+static void check_known_aliases(struct check *c, struct dt_info *dti,
+				    struct node *node)
+{
+	int i;
+	struct property *prop;
+	static char *aliases_strings[] = {
+		"ethernet", "gpio", "i2c", "rtc", "serial", "spi"
+	};
+
+	if (!streq(node->name, "aliases"))
+		return;
+
+	for_each_property(node, prop) {
+		for (i = 0; i < ARRAY_SIZE(aliases_strings); i++) {
+			if (strstarts(prop->name, aliases_strings[i]))
+				break;
+		}
+
+		if (i == ARRAY_SIZE(aliases_strings)) {
+			FAIL(c, dti, "unknown alias name %s", prop->name);
+			continue;
+		}
+	}
+}
+WARNING(known_aliases, check_known_aliases, NULL);
+
 static void fixup_addr_size_cells(struct check *c, struct dt_info *dti,
 				  struct node *node)
 {
@@ -1355,6 +1397,8 @@  static struct check *check_table[] = {
 	&gpios_property,
 	&interrupts_property,
 
+	&known_aliases,	&alias_paths,
+
 	&always_fail,
 };