devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [RFC PATCH] checks: Add check for standard node names
Date: Fri, 10 Feb 2017 10:08:57 -0600	[thread overview]
Message-ID: <20170210160857.23963-1-robh@kernel.org> (raw)

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, &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,
 
-- 
2.10.1

                 reply	other threads:[~2017-02-10 16:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170210160857.23963-1-robh@kernel.org \
    --to=robh-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
    --cc=david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org \
    --cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).