Skip to contentSkip to conversation

Another batch of dtc checks

PATCH In review Rob Herring 3 participants 18 messages Nov 17, 2017 – Nov 22, 2017 12 messages not in the archive

lore
Share & tools
lore
#0 lore raw

cover Another batch of dtc checks

Here's another batch of dtc checks. The first 3 patches are pretty straightforward. The last 2 patches are a bit more subjective.

For aliases, I would like to see them restricted to a documented list of names. There are some platforms I've seen that seem to just define aliases for many devices and most are not needed. The main use of aliases in the Linux kernel is to provide fixed device numbers to userspace, but this is an anti-goal of in the kernel.

Rob

Rob Herring (5):
checks: add a string checks for label, bootargs and stdout-path
checks: add string list check
checks: add string list check for *-names properties
checks: check for #{size,address}-cells without child nodes
checks: add aliases node checks

 checks.c                   | 123 +++++++++++++++++++++++++++++++++++++++++++++
 tests/bad-string-props.dts |  11 ++++
 tests/run_tests.sh         |   2 +-
 3 files changed, 135 insertions(+), 1 deletion(-)
Signature · 1 line
2.14.1

A message that is not in the archive (sent off-list or not yet received): 20171117144515.10870-1-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org

#2 lore raw

PATCH 1/5 checks: add a string checks for label, bootargs and stdout-path

Add more string property checks for label, bootargs, and stdout-path.

---
 checks.c                   | 4 ++++
 tests/bad-string-props.dts | 3 +++
 tests/run_tests.sh         | 2 +-
 3 files changed, 8 insertions(+), 1 deletion(-)
checks.c +4 -0
index f5bf5f97a3ad..a4a9d37ca19b 100644
@@ -586,6 +586,9 @@ WARNING_IF_NOT_CELL(interrupt_cells_is_cell, "#interrupt-cells");
 WARNING_IF_NOT_STRING(device_type_is_string, "device_type");
 WARNING_IF_NOT_STRING(model_is_string, "model");
 WARNING_IF_NOT_STRING(status_is_string, "status");
+WARNING_IF_NOT_STRING(label_is_string, "label");
+WARNING_IF_NOT_STRING(bootargs_is_string, "bootargs");
+WARNING_IF_NOT_STRING(stdout_path_is_string, "stdout-path");
 
 static void fixup_addr_size_cells(struct check *c, struct dt_info *dti,
 				  struct node *node)
@@ -1236,6 +1239,7 @@ static struct check *check_table[] = {
 
 	&address_cells_is_cell, &size_cells_is_cell, &interrupt_cells_is_cell,
 	&device_type_is_string, &model_is_string, &status_is_string,
+	&label_is_string, &bootargs_is_string, &stdout_path_is_string,
 
 	&property_name_chars_strict,
 	&node_name_chars_strict,
tests/bad-string-props.dts +3 -0
index 396f82069cf7..9b5a7a1736ee 100644
@@ -4,4 +4,7 @@
 	device_type = <0xdeadbeef>;
 	model = <0xdeadbeef>;
 	status = <0xdeadbeef>;
+	bootargs = <0xdeadbeef>;
+	stdout-path = <0xdeadbeef>;
+	label = <0xdeadbeef>;
 };
tests/run_tests.sh +1 -1
index 850bc165e757..c610aaeb053e 100755
@@ -546,7 +546,7 @@ dtc_tests () {
     check_tests bad-name-property.dts name_properties
 
     check_tests bad-ncells.dts address_cells_is_cell size_cells_is_cell interrupt_cells_is_cell
-    check_tests bad-string-props.dts device_type_is_string model_is_string status_is_string
+    check_tests bad-string-props.dts device_type_is_string model_is_string status_is_string bootargs_is_string stdout_path_is_string label_is_string
     check_tests bad-reg-ranges.dts reg_format ranges_format
     check_tests bad-empty-ranges.dts ranges_format
     check_tests reg-ranges-root.dts reg_format ranges_format
Signature · 1 line
2.14.1

A message that is not in the archive (sent off-list or not yet received): 20171117144515.10870-2-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org

#4 lore raw

Re: [PATCH 1/5] checks: add a string checks for label, bootargs and stdout-path

Quoted 1 line · Rob Herring

Add more string property checks for label, bootargs, and stdout-path.

Where does 'label' appear? I'm not immediately recalling it as a property with global meaning.

bootargs and stdout-path are from /chosen of course. I have some mixed feelings about whether it's reasonable to check it's a string everywhere, rather than specifically just in /chosen.

Quoted 54 lines
---
 checks.c                   | 4 ++++
 tests/bad-string-props.dts | 3 +++
 tests/run_tests.sh         | 2 +-
 3 files changed, 8 insertions(+), 1 deletion(-)
checks.c +4 -0
index f5bf5f97a3ad..a4a9d37ca19b 100644
@@ -586,6 +586,9 @@ WARNING_IF_NOT_CELL(interrupt_cells_is_cell, "#interrupt-cells");
 WARNING_IF_NOT_STRING(device_type_is_string, "device_type");
 WARNING_IF_NOT_STRING(model_is_string, "model");
 WARNING_IF_NOT_STRING(status_is_string, "status");
+WARNING_IF_NOT_STRING(label_is_string, "label");
+WARNING_IF_NOT_STRING(bootargs_is_string, "bootargs");
+WARNING_IF_NOT_STRING(stdout_path_is_string, "stdout-path");
 
 static void fixup_addr_size_cells(struct check *c, struct dt_info *dti,
 				  struct node *node)
@@ -1236,6 +1239,7 @@ static struct check *check_table[] = {
 
 	&address_cells_is_cell, &size_cells_is_cell, &interrupt_cells_is_cell,
 	&device_type_is_string, &model_is_string, &status_is_string,
+	&label_is_string, &bootargs_is_string, &stdout_path_is_string,
 
 	&property_name_chars_strict,
 	&node_name_chars_strict,
tests/bad-string-props.dts +3 -0
index 396f82069cf7..9b5a7a1736ee 100644
@@ -4,4 +4,7 @@
 	device_type = <0xdeadbeef>;
 	model = <0xdeadbeef>;
 	status = <0xdeadbeef>;
+	bootargs = <0xdeadbeef>;
+	stdout-path = <0xdeadbeef>;
+	label = <0xdeadbeef>;
 };
tests/run_tests.sh +1 -1
index 850bc165e757..c610aaeb053e 100755
@@ -546,7 +546,7 @@ dtc_tests () {
     check_tests bad-name-property.dts name_properties
 
     check_tests bad-ncells.dts address_cells_is_cell size_cells_is_cell interrupt_cells_is_cell
-    check_tests bad-string-props.dts device_type_is_string model_is_string status_is_string
+    check_tests bad-string-props.dts device_type_is_string model_is_string status_is_string bootargs_is_string stdout_path_is_string label_is_string
     check_tests bad-reg-ranges.dts reg_format ranges_format
     check_tests bad-empty-ranges.dts ranges_format
     check_tests reg-ranges-root.dts reg_format ranges_format
Signature · 4 lines
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

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

Re: [PATCH 1/5] checks: add a string checks for label, bootargs and stdout-path

Quoted 5 lines · David Gibson
Quoted 1 line · Rob Herring

Add more string property checks for label, bootargs, and stdout-path.

Where does 'label' appear? I'm not immediately recalling it as a property with global meaning.

It's documented in DT spec/ePAPR. It can be anywhere. It's the property for the human readable identifiers such as the label on ethernet ports, serial ports, LEDs, etc.

Quoted 3 lines

bootargs and stdout-path are from /chosen of course. I have some mixed feelings about whether it's reasonable to check it's a string everywhere, rather than specifically just in /chosen.

We don't really want to see the same property names with different meanings. I think checking the location is a separate check. You've generally suggested splitting up tests rather than have all in one tests. Not sure if we should check known properties only appear in chosen or that chosen only has known properties (assuming we can enumerate that list. Maybe we allow things like "linux,*").

Rob

A message that is not in the archive (sent off-list or not yet received): CAL_JsqJUpgBC1awgTZgz3pwhYUL02ES=E-ogqVONxDFjg8eSag-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#8 lore raw

Re: [PATCH 1/5] checks: add a string checks for label, bootargs and stdout-path

Quoted 11 lines · Rob Herring
Quoted 5 lines · David Gibson
Quoted 1 line · Rob Herring

Add more string property checks for label, bootargs, and stdout-path.

Where does 'label' appear? I'm not immediately recalling it as a property with global meaning.

It's documented in DT spec/ePAPR. It can be anywhere. It's the property for the human readable identifiers such as the label on ethernet ports, serial ports, LEDs, etc.

Ah, ok. I'd completely forgotten about that one. Ok, that's a fine check then.

Quoted 6 lines
Quoted 3 lines

bootargs and stdout-path are from /chosen of course. I have some mixed feelings about whether it's reasonable to check it's a string everywhere, rather than specifically just in /chosen.

We don't really want to see the same property names with different meanings.

Hm. As a rule of thumb, yes, but I don't know that it's super important for properties that aren't very common. Even then /chosen is really special.

Quoted 5 lines

I think checking the location is a separate check. You've generally suggested splitting up tests rather than have all in one tests. Not sure if we should check known properties only appear in chosen or that chosen only has known properties (assuming we can enumerate that list. Maybe we allow things like "linux,*").

I think for now a better approach would be to add one or more checks specifically to validate the /chosen node.

Signature · 4 lines
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
#9 lore raw

PATCH 2/5 checks: add string list check

In reply to a message not in the archive

Add a check for string list properties with compatible being the first check.

---
 checks.c                   | 34 ++++++++++++++++++++++++++++++++++
 tests/bad-string-props.dts |  8 ++++++++
 tests/run_tests.sh         |  2 +-
 3 files changed, 43 insertions(+), 1 deletion(-)
checks.c +34 -0
index a4a9d37ca19b..4e23f29486bb 100644
@@ -179,6 +179,36 @@ static void check_is_string(struct check *c, struct dt_info *dti,
 #define ERROR_IF_NOT_STRING(nm, propname) \
 	ERROR(nm, check_is_string, (propname))
 
+static void check_is_string_list(struct check *c, struct dt_info *dti,
+				 struct node *node)
+{
+	int rem, l;
+	struct property *prop;
+	char *propname = c->data;
+	char *str;
+
+	prop = get_property(node, propname);
+	if (!prop)
+		return; /* Not present, assumed ok */
+
+	str = prop->val.val;
+	rem = prop->val.len;
+	while (rem > 0) {
+		l = strnlen(str, rem);
+		if (l == rem) {
+			FAIL(c, dti, "\"%s\" property in %s is not a string list",
+			     propname, node->fullpath);
+			break;
+		}
+		rem -= l + 1;
+		str += l + 1;
+	}
+}
+#define WARNING_IF_NOT_STRING_LIST(nm, propname) \
+	WARNING(nm, check_is_string_list, (propname))
+#define ERROR_IF_NOT_STRING_LIST(nm, propname) \
+	ERROR(nm, check_is_string_list, (propname))
+
 static void check_is_cell(struct check *c, struct dt_info *dti,
 			  struct node *node)
 {
@@ -590,6 +620,8 @@ WARNING_IF_NOT_STRING(label_is_string, "label");
 WARNING_IF_NOT_STRING(bootargs_is_string, "bootargs");
 WARNING_IF_NOT_STRING(stdout_path_is_string, "stdout-path");
 
+WARNING_IF_NOT_STRING_LIST(compatible_is_string_list, "compatible");
+
 static void fixup_addr_size_cells(struct check *c, struct dt_info *dti,
 				  struct node *node)
 {
@@ -1241,6 +1273,8 @@ static struct check *check_table[] = {
 	&device_type_is_string, &model_is_string, &status_is_string,
 	&label_is_string, &bootargs_is_string, &stdout_path_is_string,
 
+	&compatible_is_string_list,
+
 	&property_name_chars_strict,
 	&node_name_chars_strict,
 
tests/bad-string-props.dts +8 -0
index 9b5a7a1736ee..5e226ce0c736 100644
@@ -7,4 +7,12 @@
 	bootargs = <0xdeadbeef>;
 	stdout-path = <0xdeadbeef>;
 	label = <0xdeadbeef>;
+
+	node1 {
+		compatible = <0xdeadbeef>;
+	};
+
+	node2 {
+		compatible = "good", <0xdeadbeef>;
+	};
 };
tests/run_tests.sh +1 -1
index c610aaeb053e..f492cf78ae84 100755
@@ -546,7 +546,7 @@ dtc_tests () {
     check_tests bad-name-property.dts name_properties
 
     check_tests bad-ncells.dts address_cells_is_cell size_cells_is_cell interrupt_cells_is_cell
-    check_tests bad-string-props.dts device_type_is_string model_is_string status_is_string bootargs_is_string stdout_path_is_string label_is_string
+    check_tests bad-string-props.dts device_type_is_string model_is_string status_is_string bootargs_is_string stdout_path_is_string label_is_string compatible_is_string_list
     check_tests bad-reg-ranges.dts reg_format ranges_format
     check_tests bad-empty-ranges.dts ranges_format
     check_tests reg-ranges-root.dts reg_format ranges_format
Signature · 1 line
2.14.1

A message that is not in the archive (sent off-list or not yet received): 20171117144515.10870-3-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org

Reviewed-by
#11 lore raw

Re: [PATCH 2/5] checks: add string list check

Quoted 4 lines · Rob Herring

Add a check for string list properties with compatible being the first check.

Not applying right now, while resolving queries on 1/5.

Quoted 95 lines
---
 checks.c                   | 34 ++++++++++++++++++++++++++++++++++
 tests/bad-string-props.dts |  8 ++++++++
 tests/run_tests.sh         |  2 +-
 3 files changed, 43 insertions(+), 1 deletion(-)
checks.c +34 -0
index a4a9d37ca19b..4e23f29486bb 100644
@@ -179,6 +179,36 @@ static void check_is_string(struct check *c, struct dt_info *dti,
 #define ERROR_IF_NOT_STRING(nm, propname) \
 	ERROR(nm, check_is_string, (propname))
 
+static void check_is_string_list(struct check *c, struct dt_info *dti,
+				 struct node *node)
+{
+	int rem, l;
+	struct property *prop;
+	char *propname = c->data;
+	char *str;
+
+	prop = get_property(node, propname);
+	if (!prop)
+		return; /* Not present, assumed ok */
+
+	str = prop->val.val;
+	rem = prop->val.len;
+	while (rem > 0) {
+		l = strnlen(str, rem);
+		if (l == rem) {
+			FAIL(c, dti, "\"%s\" property in %s is not a string list",
+			     propname, node->fullpath);
+			break;
+		}
+		rem -= l + 1;
+		str += l + 1;
+	}
+}
+#define WARNING_IF_NOT_STRING_LIST(nm, propname) \
+	WARNING(nm, check_is_string_list, (propname))
+#define ERROR_IF_NOT_STRING_LIST(nm, propname) \
+	ERROR(nm, check_is_string_list, (propname))
+
 static void check_is_cell(struct check *c, struct dt_info *dti,
 			  struct node *node)
 {
@@ -590,6 +620,8 @@ WARNING_IF_NOT_STRING(label_is_string, "label");
 WARNING_IF_NOT_STRING(bootargs_is_string, "bootargs");
 WARNING_IF_NOT_STRING(stdout_path_is_string, "stdout-path");
 
+WARNING_IF_NOT_STRING_LIST(compatible_is_string_list, "compatible");
+
 static void fixup_addr_size_cells(struct check *c, struct dt_info *dti,
 				  struct node *node)
 {
@@ -1241,6 +1273,8 @@ static struct check *check_table[] = {
 	&device_type_is_string, &model_is_string, &status_is_string,
 	&label_is_string, &bootargs_is_string, &stdout_path_is_string,
 
+	&compatible_is_string_list,
+
 	&property_name_chars_strict,
 	&node_name_chars_strict,
 
tests/bad-string-props.dts +8 -0
index 9b5a7a1736ee..5e226ce0c736 100644
@@ -7,4 +7,12 @@
 	bootargs = <0xdeadbeef>;
 	stdout-path = <0xdeadbeef>;
 	label = <0xdeadbeef>;
+
+	node1 {
+		compatible = <0xdeadbeef>;
+	};
+
+	node2 {
+		compatible = "good", <0xdeadbeef>;
+	};
 };
tests/run_tests.sh +1 -1
index c610aaeb053e..f492cf78ae84 100755
@@ -546,7 +546,7 @@ dtc_tests () {
     check_tests bad-name-property.dts name_properties
 
     check_tests bad-ncells.dts address_cells_is_cell size_cells_is_cell interrupt_cells_is_cell
-    check_tests bad-string-props.dts device_type_is_string model_is_string status_is_string bootargs_is_string stdout_path_is_string label_is_string
+    check_tests bad-string-props.dts device_type_is_string model_is_string status_is_string bootargs_is_string stdout_path_is_string label_is_string compatible_is_string_list
     check_tests bad-reg-ranges.dts reg_format ranges_format
     check_tests bad-empty-ranges.dts ranges_format
     check_tests reg-ranges-root.dts reg_format ranges_format
Signature · 4 lines
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
#12 lore raw

PATCH 3/5 checks: add string list check for *-names properties

In reply to a message not in the archive

Add a string list check for common properties ending in "-names" such as reg-names or interrupt-names.

---
 checks.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
checks.c +16 -1
index 4e23f29486bb..346b0256f9cb 100644
@@ -622,6 +622,21 @@ WARNING_IF_NOT_STRING(stdout_path_is_string, "stdout-path");
 
 WARNING_IF_NOT_STRING_LIST(compatible_is_string_list, "compatible");
 
+static void check_names_is_string_list(struct check *c, struct dt_info *dti,
+				       struct node *node)
+{
+	struct property *prop;
+
+	for_each_property(node, prop) {
+		if (!strstr(prop->name, "-names"))
+			continue;
+
+		c->data = prop->name;
+		check_is_string_list(c, dti, node);
+	}
+}
+WARNING(names_is_string_list, check_names_is_string_list, NULL);
+
 static void fixup_addr_size_cells(struct check *c, struct dt_info *dti,
 				  struct node *node)
 {
@@ -1273,7 +1288,7 @@ static struct check *check_table[] = {
 	&device_type_is_string, &model_is_string, &status_is_string,
 	&label_is_string, &bootargs_is_string, &stdout_path_is_string,
 
-	&compatible_is_string_list,
+	&compatible_is_string_list, &names_is_string_list,
 
 	&property_name_chars_strict,
 	&node_name_chars_strict,
Signature · 1 line
2.14.1

A message that is not in the archive (sent off-list or not yet received): 20171117144515.10870-4-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org

#14 lore raw

Re: [PATCH 3/5] checks: add string list check for *-names properties

Hi,

Quoted 13 lines · Rob Herring

Add a string list check for common properties ending in "-names" such as reg-names or interrupt-names.

---
 checks.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
checks.c +0 -0
index 4e23f29486bb..346b0256f9cb 100644

checks.c WARNING_IF_NOT_STRING(stdout_path_is_string, "stdout-path"); · line 631

Quoted 10 lines
checks.c +7 -0
@@ -622,6 +622,21 @@ WARNING_IF_NOT_STRING(stdout_path_is_string, "stdout-path");
 
 WARNING_IF_NOT_STRING_LIST(compatible_is_string_list, "compatible");
 
+static void check_names_is_string_list(struct check *c, struct dt_info *dti,
+				       struct node *node)
+{
+	struct property *prop;
+
+	for_each_property(node, prop) {
+		if (!strstr(prop->name, "-names"))

But that would match "actually-names-dont-matter" as well, resulting in a false positive? Should we check if the string appears at the *end* of the property name?

Cheers,
Andre.

Quoted 13 lines
checks.c +8 -0
+			continue;
+
+		c->data = prop->name;
+		check_is_string_list(c, dti, node);
+	}
+}
+WARNING(names_is_string_list, check_names_is_string_list, NULL);
+
 static void fixup_addr_size_cells(struct check *c, struct dt_info *dti,
 				  struct node *node)
 {

checks.c static struct check *check_table[] = { · line 1294

Quoted 8 lines
checks.c +1 -1
@@ -1273,7 +1288,7 @@ static struct check *check_table[] = {
 	&device_type_is_string, &model_is_string, &status_is_string,
 	&label_is_string, &bootargs_is_string, &stdout_path_is_string,
 
-	&compatible_is_string_list,
+	&compatible_is_string_list, &names_is_string_list,
 
 	&property_name_chars_strict,
 	&node_name_chars_strict,

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

A message that is not in the archive (sent off-list or not yet received): 8eea3f9e-5512-dc6c-f755-58cc333db732-5wv7dgnIgG8@public.gmane.org

#16 lore raw

Re: [PATCH 3/5] checks: add string list check for *-names properties

Quoted 19 lines · Andre Przywara

Hi,

Quoted 16 lines · Rob Herring

Add a string list check for common properties ending in "-names" such as reg-names or interrupt-names.

---
 checks.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
checks.c +0 -0
index 4e23f29486bb..346b0256f9cb 100644
@@ -622,6 +622,21 @@ WARNING_IF_NOT_STRING(stdout_path_is_string, "stdout-path");
 
 WARNING_IF_NOT_STRING_LIST(compatible_is_string_list, "compatible");
 
Quoted 11 lines

checks.c WARNING_IF_NOT_STRING(stdout_path_is_string, "stdout-path"); · line 631

Quoted 7 lines
checks.c +7 -0
+static void check_names_is_string_list(struct check *c, struct dt_info *dti,
+                                    struct node *node)
+{
+     struct property *prop;
+
+     for_each_property(node, prop) {
+             if (!strstr(prop->name, "-names"))

But that would match "actually-names-dont-matter" as well, resulting in a false positive? Should we check if the string appears at the *end* of the property name?

Perhaps. IMO, once a word is used, it needs to be reserved for that purpose. For example, the gpio hogs binding use of "gpios" with just numbers and no phandle is bad because we have a mixture of types for a given property name or suffix. So we should really enforce that "-names" only appears as a suffix and use anywhere else is a warning.

Rob

A message that is not in the archive (sent off-list or not yet received): CAL_JsqLQwZ=grCDwjUORaE0NnmC_qJBBtJtT7X0-Z2BGujcfmA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#18 lore raw

Re: [PATCH 3/5] checks: add string list check for *-names properties

Quoted 32 lines · Rob Herring
Quoted 19 lines · Andre Przywara

Hi,

Quoted 16 lines · Rob Herring

Add a string list check for common properties ending in "-names" such as reg-names or interrupt-names.

---
 checks.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
checks.c +0 -0
index 4e23f29486bb..346b0256f9cb 100644
@@ -622,6 +622,21 @@ WARNING_IF_NOT_STRING(stdout_path_is_string, "stdout-path");
 
 WARNING_IF_NOT_STRING_LIST(compatible_is_string_list, "compatible");
 
Quoted 11 lines

checks.c WARNING_IF_NOT_STRING(stdout_path_is_string, "stdout-path"); · line 631

Quoted 7 lines
checks.c +7 -0
+static void check_names_is_string_list(struct check *c, struct dt_info *dti,
+                                    struct node *node)
+{
+     struct property *prop;
+
+     for_each_property(node, prop) {
+             if (!strstr(prop->name, "-names"))

But that would match "actually-names-dont-matter" as well, resulting in a false positive? Should we check if the string appears at the *end* of the property name?

Quoted 5 lines

Perhaps. IMO, once a word is used, it needs to be reserved for that purpose. For example, the gpio hogs binding use of "gpios" with just numbers and no phandle is bad because we have a mixture of types for a given property name or suffix. So we should really enforce that "-names" only appears as a suffix and use anywhere else is a warning.

That sounds... overly restrictive to me. The grabbing of a whole bunch of gpios words is an example of poor - or at least nonstandard - binding design IMO.

Signature · 4 lines
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
#19 lore raw

Re: [PATCH 3/5] checks: add string list check for *-names properties

In reply to a message not in the archive
Quoted 19 lines · Andre Przywara

Hi,

Quoted 16 lines · Rob Herring

Add a string list check for common properties ending in "-names" such as reg-names or interrupt-names.

---
 checks.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
checks.c +0 -0
index 4e23f29486bb..346b0256f9cb 100644
@@ -622,6 +622,21 @@ WARNING_IF_NOT_STRING(stdout_path_is_string, "stdout-path");
 
 WARNING_IF_NOT_STRING_LIST(compatible_is_string_list, "compatible");
 
Quoted 11 lines

checks.c WARNING_IF_NOT_STRING(stdout_path_is_string, "stdout-path"); · line 631

Quoted 7 lines
checks.c +7 -0
+static void check_names_is_string_list(struct check *c, struct dt_info *dti,
+				       struct node *node)
+{
+	struct property *prop;
+
+	for_each_property(node, prop) {
+		if (!strstr(prop->name, "-names"))

But that would match "actually-names-dont-matter" as well, resulting in a false positive? Should we check if the string appears at the *end* of the property name?

Yes, we should.

Signature · 4 lines
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
#20 lore raw

PATCH 4/5 checks: check for #{size,address}-cells without child nodes

In reply to a message not in the archive

nodes with a 'reg' property nor a ranges property.

An exception may be an overlay that adds nodes, but this case would need

---
 checks.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
checks.c +26 -0
index 346b0256f9cb..a785b81bea07 100644
@@ -982,6 +982,31 @@ static void check_avoid_default_addr_size(struct check *c, struct dt_info *dti,
 WARNING(avoid_default_addr_size, check_avoid_default_addr_size, NULL,
 	&addr_size_cells);
 
+static void check_avoid_unecessary_addr_size(struct check *c, struct dt_info *dti,
+					     struct node *node)
+{
+	struct property *prop;
+	struct node *child;
+	bool has_reg = false;
+
+	if (!node->parent || node->addr_cells < 0 || node->size_cells < 0)
+		return;
+
+	if (get_property(node, "ranges") || !node->children)
+		return;
+
+	for_each_child(node, child) {
+		prop = get_property(child, "reg");
+		if (prop)
+			has_reg = true;
+	}
+
+	if (!has_reg)
+		FAIL(c, dti, "unnecessary #address-cells/#size-cells without \"ranges\" or child \"reg\" property in %s",
+		     node->fullpath);
+}
+WARNING(avoid_unecessary_addr_size, check_avoid_unecessary_addr_size, NULL, &avoid_default_addr_size);
+
 static void check_obsolete_chosen_interrupt_controller(struct check *c,
 						       struct dt_info *dti,
 						       struct node *node)
@@ -1306,6 +1331,7 @@ static struct check *check_table[] = {
 	&simple_bus_reg,
 
 	&avoid_default_addr_size,
+	&avoid_unecessary_addr_size,
 	&obsolete_chosen_interrupt_controller,
 
 	&clocks_property,
Signature · 1 line
2.14.1

A message that is not in the archive (sent off-list or not yet received): 20171117144515.10870-5-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org

#22 lore raw

Re: [PATCH 4/5] checks: check for #{size,address}-cells without child nodes

Quoted 4 lines · Rob Herring

nodes with a 'reg' property nor a ranges property.

An exception may be an overlay that adds nodes, but this case would need

Sentence doesn't seem finished..

In any case, I'm not sure this is a good idea. It's not uncommon to have bus bridge nodes that ought to have a well defined #address and #size cells, but just don't happen to have any plugged devices yet. An overlay that adds nodes is one possibility, but a bus where the children can be probed is another.

The check for 'ranges' will get some of those cases, but a bus bridge which doesn't directly map the child address space into the parents (e.g. indirect access) is perfectly legitimate still.

Quoted 50 lines
---
 checks.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
checks.c +26 -0
index 346b0256f9cb..a785b81bea07 100644
@@ -982,6 +982,31 @@ static void check_avoid_default_addr_size(struct check *c, struct dt_info *dti,
 WARNING(avoid_default_addr_size, check_avoid_default_addr_size, NULL,
 	&addr_size_cells);
 
+static void check_avoid_unecessary_addr_size(struct check *c, struct dt_info *dti,
+					     struct node *node)
+{
+	struct property *prop;
+	struct node *child;
+	bool has_reg = false;
+
+	if (!node->parent || node->addr_cells < 0 || node->size_cells < 0)
+		return;
+
+	if (get_property(node, "ranges") || !node->children)
+		return;
+
+	for_each_child(node, child) {
+		prop = get_property(child, "reg");
+		if (prop)
+			has_reg = true;
+	}
+
+	if (!has_reg)
+		FAIL(c, dti, "unnecessary #address-cells/#size-cells without \"ranges\" or child \"reg\" property in %s",
+		     node->fullpath);
+}
+WARNING(avoid_unecessary_addr_size, check_avoid_unecessary_addr_size, NULL, &avoid_default_addr_size);
+
 static void check_obsolete_chosen_interrupt_controller(struct check *c,
 						       struct dt_info *dti,
 						       struct node *node)
@@ -1306,6 +1331,7 @@ static struct check *check_table[] = {
 	&simple_bus_reg,
 
 	&avoid_default_addr_size,
+	&avoid_unecessary_addr_size,
 	&obsolete_chosen_interrupt_controller,
 
 	&clocks_property,
Signature · 4 lines
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

A message that is not in the archive (sent off-list or not yet received): [email protected]

#24 lore raw

Re: [PATCH 4/5] checks: check for #{size,address}-cells without child nodes

Quoted 7 lines · David Gibson
Quoted 4 lines · Rob Herring

nodes with a 'reg' property nor a ranges property.

An exception may be an overlay that adds nodes, but this case would need

Sentence doesn't seem finished..

It was there until I rebased. Since the line started with #, git dropped it...

"#{size,address}-cells in the overlay to properly compile already."

Quoted 5 lines

In any case, I'm not sure this is a good idea. It's not uncommon to have bus bridge nodes that ought to have a well defined #address and #size cells, but just don't happen to have any plugged devices yet. An overlay that adds nodes is one possibility, but a bus where the children can be probed is another.

Wouldn't an overlay without #{size,address}-cells have warnings from avoid_default_addr_size?

As long as there are no child nodes, the check is not run. So we're limited to false positives if we have a mixture of nodes with and without unit addresses and only the nodes without unit addresses are populated. I have seen this with PCI hosts with an interrupt controller child node.

In general, I'm struggling with how to have tests that check for things that we generally want to avoid, but we still allow exceptions. Some of these may be things we want to avoid in new bindings, but wouldn't fix for existing cases. Another example is things that were/are valid for OF, but not FDT.

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

A message that is not in the archive (sent off-list or not yet received): CAL_JsqJoiBvD-QE5bgk5ob3qc65ar371xWxx-1D+fKGh7+P=Zw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#26 lore raw

Re: [PATCH 4/5] checks: check for #{size,address}-cells without child nodes

Quoted 5 lines · Rob Herring
Quoted 3 lines · David Gibson
Quoted 2 lines · Rob Herring

nodes with a 'reg' property nor a ranges property.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

An exception may be an overlay that adds nodes, but this case would need

Sentence doesn't seem finished..

It was there until I rebased. Since the line started with #, git dropped it...

"#{size,address}-cells in the overlay to properly compile already."

Ah, right.

Quoted 8 lines
Quoted 5 lines

In any case, I'm not sure this is a good idea. It's not uncommon to have bus bridge nodes that ought to have a well defined #address and #size cells, but just don't happen to have any plugged devices yet. An overlay that adds nodes is one possibility, but a bus where the children can be probed is another.

Wouldn't an overlay without #{size,address}-cells have warnings from avoid_default_addr_size?

Well, yes. The checks are pretty much designed for whole trees and don't work well on overlays at the moment. That's a rather more substantial change to fix.

Quoted 1 line

As long as there are no child nodes, the check is not run.

Ah! Sorry, I missed that. Objection withdrawn in that case.

Quoted 5 lines

So we're
limited to false positives if we have a mixture of nodes with and without unit addresses and only the nodes without unit addresses are populated. I have seen this with PCI hosts with an interrupt controller child node.

Sounds like an incorrect representation if the intrrupt controller doesn't have a PCI config space presence.

Quoted 5 lines

In general, I'm struggling with how to have tests that check for things that we generally want to avoid, but we still allow exceptions. Some of these may be things we want to avoid in new bindings, but wouldn't fix for existing cases. Another example is things that were/are valid for OF, but not FDT.

Signature · 4 lines
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
#27 lore raw

PATCH 5/5 checks: add aliases node checks

In reply to a message not in the archive

Add checks for aliases node that properties are a valid path and that the alias property names are a known, standard name.

---
 checks.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
checks.c +44 -0
index a785b81bea07..2c5b6c2eacb3 100644
@@ -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,
 };
 
Signature · 6 lines
2.14.1

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

A message that is not in the archive (sent off-list or not yet received): 20171117144515.10870-6-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org

#29 lore raw

Re: [PATCH 5/5] checks: add aliases node checks

Quoted 4 lines · Rob Herring

Add checks for aliases node that properties are a valid path and that the alias property names are a known, standard name.

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.

Quoted 66 lines
---
 checks.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
checks.c +44 -0
index a785b81bea07..2c5b6c2eacb3 100644
@@ -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,
 };
 
Signature · 4 lines
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