* [RFC PATCH] checks: Add check for standard node names
@ 2017-02-10 16:08 Rob Herring
0 siblings, 0 replies; only message in thread
From: Rob Herring @ 2017-02-10 16:08 UTC (permalink / raw)
To: David Gibson
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA,
devicetree-compiler-u79uwXL29TY76Z2rM5mHXA
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-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.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(+)
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, ®_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,
--
2.10.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2017-02-10 16:08 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-10 16:08 [RFC PATCH] checks: Add check for standard node names Rob Herring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).