diff mbox

[RFC] checks: Add check for standard node names

Message ID 20170210160857.23963-1-robh@kernel.org
State New
Headers show

Commit Message

Rob Herring Feb. 10, 2017, 4:08 p.m. UTC
Add a check for standard node name based on the presence of specific
properties associated with the standard node type. For example, a
node with "#mbox-cells" property should have a node name of "mailbox"
and vice-versa. The check is off by default.

This check can generate false positives particularly for multi-function
devices. This is partially handled for common cases like nodes which are
both interrupt and gpio controllers or pinctrl and gpio controllers.
Therefore, warnings generated by this check should not be blindly fixed,
but used as a guide.

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

---
Along similar lines of my other checks, this is intended to help catch 
common problems I find in binding reviews. This one can never really be 
complete as it generally only checks providers. For nodes that are 
only consumers, the only thing we can key off of would be compatible 
strings.

For ARM dts files, I'm seeing this warning on ~700 unique node names. 
I'd guess at least ~75% of those are valid. 

Rob

 checks.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 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
diff mbox

Patch

diff --git a/checks.c b/checks.c
index 1bec0b4d0ee3..ac86f04e04a0 100644
--- a/checks.c
+++ b/checks.c
@@ -781,6 +781,66 @@  static void check_pci_device(struct check *c, struct dt_info *dti, struct node *
 }
 WARNING(pci_device, check_pci_device, NULL, &reg_format);
 
+static const char *node_name_list[] = {
+	/*
+	 * In cases of multiple matching properties, the preferred node name
+	 * must come last.
+	 */
+	"mailbox", "#mbox-cells",
+	"pwm", "#pwm-cells",
+	"iommu", "#iommu-cells",
+	"pcie-phy", "#phy-cells",
+	"sata-phy", "#phy-cells",
+	"usb-phy", "#phy-cells",
+	"phy", "#phy-cells",
+	"interrupt-controller", "interrupt-controller",
+	"gpio", "gpio-controller",
+	"pinctrl", NULL,
+	"pmic", NULL,
+	"system-controller", NULL,
+	NULL, NULL
+};
+
+static void check_node_names(struct check *c, struct dt_info *dti,
+					  struct node *node)
+{
+	bool has_std_node_name = false;
+	const char *node_name = NULL;
+	struct property *prop;
+	int i;
+
+	if (!node->parent)
+		return; /* Ignore root node */
+
+	for (i = 0; node_name_list[i]; i += 2) {
+		if (node_name_list[i + 1])
+			prop = get_property(node, node_name_list[i + 1]);
+		else
+			prop = NULL;
+
+		if (!strncmp(node->name, node_name_list[i], node->basenamelen) &&
+			(strlen(node_name_list[i]) == node->basenamelen)) {
+			has_std_node_name = true;
+			if (prop)
+				break;
+			else if (node_name_list[i + 1])
+				FAIL(c, "Node %s missing property \"%s\"",
+				     node->fullpath,
+				     node_name_list[i + 1]);
+
+		} else if (prop && !has_std_node_name) {
+			/* Possible error, save desired node name */
+			node_name = node_name_list[i];
+		}
+
+	}
+
+	if (!has_std_node_name && node_name)
+		FAIL(c, "Node %s node name should be \"%s\"",
+		     node->fullpath, node_name);
+}
+CHECK(node_names, check_node_names, NULL);
+
 /*
  * Style checks
  */
@@ -857,6 +917,8 @@  static struct check *check_table[] = {
 	&pci_bridge,
 	&pci_device,
 
+	&node_names,
+
 	&avoid_default_addr_size,
 	&obsolete_chosen_interrupt_controller,