From patchwork Fri Feb 10 16:08:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 93790 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp576443qgi; Fri, 10 Feb 2017 08:15:40 -0800 (PST) X-Received: by 10.98.155.155 with SMTP id e27mr11079386pfk.140.1486743340492; Fri, 10 Feb 2017 08:15:40 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g18si2046424pge.324.2017.02.10.08.15.40; Fri, 10 Feb 2017 08:15:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753147AbdBJQPa (ORCPT + 7 others); Fri, 10 Feb 2017 11:15:30 -0500 Received: from mail-ot0-f196.google.com ([74.125.82.196]:32983 "EHLO mail-ot0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751712AbdBJQP0 (ORCPT ); Fri, 10 Feb 2017 11:15:26 -0500 Received: by mail-ot0-f196.google.com with SMTP id f9so4297112otd.0; Fri, 10 Feb 2017 08:15:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=y8gIeJ9Xjga7xbkEUS5rGu7YHPB5GFJIKV5Ey5Vx6E0=; b=A9I2GlGMK8DHpCMCvZla6S70yx/lZvSIFZ7y87iVKB8GSCwXIh4DVHrxZxoKzzdSv8 mQHVuK6+qw6nJJ+jNDpeDQYTW8hzDXUFurLjv5IUHZ5kePi6eUQj5/2J9tGuc4PyIgLz WFAGICNlGF9NHmS/+Il8kMyfpPwDAqIOzJAn0GtoqbeLKB+x45rbF7zbzNdey81+tjYy irqpkEFdBewnfQvmzvFjHqZtOikPaNSp1dMvxEbkdeXcOPKqUweTirlanvBW4DNVjGqa JXH8Y9Hw0xMNWMAj584jKCCzoJXzdgnbntyYUah4AXgOb3+AdZMX5oatlB3uYUI9b5c3 XgBg== X-Gm-Message-State: AMke39k+55ImjsnLS9Hs94Gcmx6mVae99Zxkrq2ol6JdRKtYJ1VfZAX1Bx1tvP5EuFLdXg== X-Received: by 10.157.3.209 with SMTP id f75mr4854716otf.261.1486742938906; Fri, 10 Feb 2017 08:08:58 -0800 (PST) Received: from rob-hp-laptop.herring.priv (66-90-148-125.dyn.grandenetworks.net. [66.90.148.125]) by smtp.googlemail.com with ESMTPSA id d131sm1086716oia.27.2017.02.10.08.08.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Feb 2017 08:08:58 -0800 (PST) From: Rob Herring To: David Gibson Cc: devicetree@vger.kernel.org, devicetree-compiler@vger.kernel.org Subject: [RFC PATCH] checks: Add check for standard node names Date: Fri, 10 Feb 2017 10:08:57 -0600 Message-Id: <20170210160857.23963-1-robh@kernel.org> X-Mailer: git-send-email 2.10.1 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org 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 --- 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 --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,