diff mbox series

[2/5] checks: Add Warning for stricter node name character checking

Message ID 20170124174534.3865-3-robh@kernel.org
State Superseded
Headers show
Series dtc unit-address and character set checks | expand

Commit Message

Rob Herring Jan. 24, 2017, 5:45 p.m. UTC
While '#', '?', '.', '+', '*', and '_' are considered valid characters,
their use is discouraged in recommended practices.

Testing this found a few cases of '.'. The majority of the warnings were
all from underscores.

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

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

-- 
2.10.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 Jan. 31, 2017, 3:14 a.m. UTC | #1
On Tue, Jan 24, 2017 at 11:45:31AM -0600, Rob Herring wrote:
> While '#', '?', '.', '+', '*', and '_' are considered valid characters,

> their use is discouraged in recommended practices.

> 

> Testing this found a few cases of '.'. The majority of the warnings were

> all from underscores.


Hmm.  The Opal firmware on POWER8 machines uses both '.' and '#' in
node names in some places.  So I'm not terribly convinced this is a
good idea.

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

> ---

>  checks.c | 12 ++++++++++++

>  1 file changed, 12 insertions(+)

> 

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

> index a0d4a9d968d7..0c78d69316bc 100644

> --- a/checks.c

> +++ b/checks.c

> @@ -252,6 +252,17 @@ static void check_node_name_chars(struct check *c, struct dt_info *dti,

>  }

>  ERROR(node_name_chars, check_node_name_chars, PROPNODECHARS "@");

>  

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

> +					 struct node *node)

> +{

> +	int n = strspn(node->name, c->data);

> +

> +	if (n < node->basenamelen)

> +		FAIL(c, "Character '%c' not recommended in node %s",

> +		     node->name[n], node->fullpath);

> +}

> +WARNING(node_name_chars_strict, check_node_name_chars_strict, PROPNODECHARSSTRICT);

> +

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

>  				   struct node *node)

>  {

> @@ -737,6 +748,7 @@ static struct check *check_table[] = {

>  	&device_type_is_string, &model_is_string, &status_is_string,

>  

>  	&property_name_chars_strict,

> +	&node_name_chars_strict,

>  

>  	&addr_size_cells, &reg_format, &ranges_format,

>  


-- 
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
Rob Herring Jan. 31, 2017, 1:46 p.m. UTC | #2
On Mon, Jan 30, 2017 at 9:14 PM, David Gibson
<david@gibson.dropbear.id.au> wrote:
> On Tue, Jan 24, 2017 at 11:45:31AM -0600, Rob Herring wrote:

>> While '#', '?', '.', '+', '*', and '_' are considered valid characters,

>> their use is discouraged in recommended practices.

>>

>> Testing this found a few cases of '.'. The majority of the warnings were

>> all from underscores.

>

> Hmm.  The Opal firmware on POWER8 machines uses both '.' and '#' in

> node names in some places.  So I'm not terribly convinced this is a

> good idea.


When would it be using a flat tree and dtc? I know the DT is more
dynamic on these systems, but it would be nice if a dts was published
as reference.

These checks are more something I want to discourage new uses of, not
necessarily fix existing cases. I've thought about making the warnings
be levels rather than true/false. Or perhaps something like -Wall.
Then these checks can be off by default. The kernel build is doing
that already for the unit address checks.

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

Patch

diff --git a/checks.c b/checks.c
index a0d4a9d968d7..0c78d69316bc 100644
--- a/checks.c
+++ b/checks.c
@@ -252,6 +252,17 @@  static void check_node_name_chars(struct check *c, struct dt_info *dti,
 }
 ERROR(node_name_chars, check_node_name_chars, PROPNODECHARS "@");
 
+static void check_node_name_chars_strict(struct check *c, struct dt_info *dti,
+					 struct node *node)
+{
+	int n = strspn(node->name, c->data);
+
+	if (n < node->basenamelen)
+		FAIL(c, "Character '%c' not recommended in node %s",
+		     node->name[n], node->fullpath);
+}
+WARNING(node_name_chars_strict, check_node_name_chars_strict, PROPNODECHARSSTRICT);
+
 static void check_node_name_format(struct check *c, struct dt_info *dti,
 				   struct node *node)
 {
@@ -737,6 +748,7 @@  static struct check *check_table[] = {
 	&device_type_is_string, &model_is_string, &status_is_string,
 
 	&property_name_chars_strict,
+	&node_name_chars_strict,
 
 	&addr_size_cells, &reg_format, &ranges_format,