From patchwork Tue Aug 22 23:02:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 110700 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp3326167qge; Tue, 22 Aug 2017 16:02:21 -0700 (PDT) X-Received: by 10.98.133.26 with SMTP id u26mr729463pfd.328.1503442940961; Tue, 22 Aug 2017 16:02:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503442940; cv=none; d=google.com; s=arc-20160816; b=Ol5e0wbsctfMcH6SwOvGiAmMMpbfwN1yUtqfXlCiKOFSPlh1w4huWDIb7ddOEtcD0m bQ450pzDoI5xXPSBSrmBt9PZD8W/ppPVMyhc3R5vpZ7xZGGBe6BRjHMFD81nxtyueUkG NSKxM07cF1gjmEnnc4RQiDMoqqG+8FVAu31eV2F7qyu023pdwM1vsU5mEqjG5zXEI5KL +6ucy4hhXJH8WIWqTl4YJz6K9YvN7YHwgxn1Dpoi6Vmo615aTbCEk+QOYPgrOtE7HfcE 6ME4wDyZoQXmB4pWb88udhND7F1GTu++vAI1iCLjAoZPW8vR8FNQ6pYWXfx89OAdWZd8 2prg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=OgKdVy8p2wmQKkA1OUMhelhn7rtBlmuwVAjEMh9S1Ug=; b=abqPZC9e3tbdIPPvNc6Na37bXqstFHhaI4R7cB7q5bhWs3iHcP8zniOC/j32Dfi8dz I0Gp+B3QYCGFukzYI8G6Fzh+obW3oJE/orIfkUgdHpG03DapHpJBt3gR1b+6PJ89gsVX mWIZPEVtL6sK4KDD3ofmEhCtVTn76OAhAJQuIcj8u8gm26ArCl7qAuDp974fARyNtLDK wGZVBU1IzbsYm55SG5KbNHH9tHRbA2FmlM8wWfaiAufL7QBty+p6lQQ+tCtSNaNpOFhg vDUXVW7HBK02t9760uSIi52D1IynHlx9BSzuMgQGPHfh2Qc/bXJLnCO8DHHJITP6IXVa QrNA== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v189si64822pgd.384.2017.08.22.16.02.20; Tue, 22 Aug 2017 16:02:20 -0700 (PDT) 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 S1752794AbdHVXCS (ORCPT + 6 others); Tue, 22 Aug 2017 19:02:18 -0400 Received: from mail-oi0-f66.google.com ([209.85.218.66]:37479 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752742AbdHVXCN (ORCPT ); Tue, 22 Aug 2017 19:02:13 -0400 Received: by mail-oi0-f66.google.com with SMTP id k77so141354oib.4; Tue, 22 Aug 2017 16:02:13 -0700 (PDT) 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:in-reply-to :references; bh=eG8DiI/X5kaMipGmFTflx5/So2Jj6kZ6lNC6LNy8R0I=; b=Exkb9ssaWrm1kpdSLU82G2NrcSZbyAsVXuQyEDlkH1PWsubGJRBxxCea/xpnNcXkP5 +TRzFaavQPBhuq3cWLnJ6sVdHNcq7UWiOOoxkLYcKy1cFb7fVFrdJXFsYqbbHHB76Iam IDeKHLxPRGqoisLXKbZXN89obDHDYvPF1WlmVL0Slv1wWoQRQXFCg9nLhFyATQqKcEm5 Bk9pRFcdAtyxY77Rlvw3DZfWW5ZuyMlr1HiZN2GP0ovHAvuUJQYRr/B6ct+9Wd9OyFZU /zXR6Dh33W91xe0hqiC6dkC/l5sS2pS15DvlmiE20YbKj8AsOmFIDRh/y2Pw2NHGSrLw FMXw== X-Gm-Message-State: AHYfb5jXVAwN8ZwZr3XQ1gHQC1ro8vXcC8tSezDS7ZYXGq0SyiGL3jtU EWs7azXZJEb5tdR2uNo= X-Received: by 10.202.235.210 with SMTP id j201mr1047577oih.15.1503442932414; Tue, 22 Aug 2017 16:02:12 -0700 (PDT) Received: from localhost.localdomain (216-188-254-6.dyn.grandenetworks.net. [216.188.254.6]) by smtp.googlemail.com with ESMTPSA id u196sm108821oia.57.2017.08.22.16.02.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Aug 2017 16:02:11 -0700 (PDT) From: Rob Herring To: David Gibson Cc: devicetree-compiler@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v2 1/3] checks: add phandle with arg property checks Date: Tue, 22 Aug 2017 18:02:06 -0500 Message-Id: <20170822230208.20987-2-robh@kernel.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170822230208.20987-1-robh@kernel.org> References: <20170822230208.20987-1-robh@kernel.org> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Many common bindings follow the same pattern of client properties containing a phandle and N arg cells where N is defined in the provider with a '#-cells' property such as: intc0: interrupt-controller@0 { #interrupt-cells = <3>; }; intc1: interrupt-controller@1 { #interrupt-cells = <2>; }; node { interrupts-extended = <&intc0 1 2 3>, <&intc1 4 5>; }; Add checks for properties following this pattern. Signed-off-by: Rob Herring --- v2: - Make each property a separate check - Iterate over raw cells rather than markers - Fix property length check for 2nd to Nth items - Improve error messages. If cell sizes are wrong, the next iteration can get a bad (but valid) phandle. - Add a test checks.c | 104 ++++++++++++++++++++++++++++++++++++++++++++ dtc.h | 1 + livetree.c | 6 +++ tests/bad-phandle-cells.dts | 11 +++++ tests/run_tests.sh | 1 + 5 files changed, 123 insertions(+) create mode 100644 tests/bad-phandle-cells.dts -- 2.11.0 -- 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 afabf64337d5..548d7e118c42 100644 --- a/checks.c +++ b/checks.c @@ -956,6 +956,93 @@ static void check_obsolete_chosen_interrupt_controller(struct check *c, WARNING(obsolete_chosen_interrupt_controller, check_obsolete_chosen_interrupt_controller, NULL); +struct provider { + const char *prop_name; + const char *cell_name; + bool optional; +}; + +static void check_property_phandle_args(struct check *c, + struct dt_info *dti, + struct node *node, + struct property *prop, + const struct provider *provider) +{ + struct node *root = dti->dt; + int cell, cellsize = 0; + + for (cell = 0; cell < prop->val.len / sizeof(cell_t); cell += cellsize + 1) { + struct node *provider_node; + struct property *cellprop; + int phandle; + + phandle = propval_cell_n(prop, cell); + if (phandle == 0 || phandle == -1) { + cellsize = 0; + continue; + } + + provider_node = get_node_by_phandle(root, phandle); + if (!provider_node) { + FAIL(c, dti, "Could not get phandle node for %s:%s(cell %d)", + node->fullpath, prop->name, cell); + break; + } + + cellprop = get_property(provider_node, provider->cell_name); + if (cellprop) { + cellsize = propval_cell(cellprop); + } else if (provider->optional) { + cellsize = 0; + } else { + FAIL(c, dti, "Missing property '%s' in node %s or bad phandle (referred from %s:%s[%d])", + provider->cell_name, + provider_node->fullpath, + node->fullpath, prop->name, cell); + break; + } + + if (prop->val.len < ((cell + cellsize + 1) * sizeof(cell_t))) { + FAIL(c, dti, "%s property size (%d) too small for cell size %d in %s", + prop->name, prop->val.len, cellsize, node->fullpath); + } + } +} + +static void check_provider_cells_property(struct check *c, + struct dt_info *dti, + struct node *node) +{ + struct provider *provider = c->data; + struct property *prop; + + prop = get_property(node, provider->prop_name); + if (!prop) + return; + + check_property_phandle_args(c, dti, node, prop, provider); +} +#define WARNING_PROPERTY_PHANDLE_CELLS(nm, propname, cells_name, ...) \ + static struct provider nm##_provider = { (propname), (cells_name), __VA_ARGS__ }; \ + WARNING(nm##_property, check_provider_cells_property, &nm##_provider, &phandle_references); + +WARNING_PROPERTY_PHANDLE_CELLS(clocks, "clocks", "#clock-cells"); +WARNING_PROPERTY_PHANDLE_CELLS(cooling_device, "cooling-device", "#cooling-cells"); +WARNING_PROPERTY_PHANDLE_CELLS(dmas, "dmas", "#dma-cells"); +WARNING_PROPERTY_PHANDLE_CELLS(hwlocks, "hwlocks", "#hwlock-cells"); +WARNING_PROPERTY_PHANDLE_CELLS(interrupts_extended, "interrupts-extended", "#interrupt-cells"); +WARNING_PROPERTY_PHANDLE_CELLS(io_channels, "io-channels", "#io-channel-cells"); +WARNING_PROPERTY_PHANDLE_CELLS(iommus, "iommus", "#iommu-cells"); +WARNING_PROPERTY_PHANDLE_CELLS(mboxes, "mboxes", "#mbox-cells"); +WARNING_PROPERTY_PHANDLE_CELLS(msi_parent, "msi-parent", "#msi-cells", true); +WARNING_PROPERTY_PHANDLE_CELLS(mux_controls, "mux-controls", "#mux-control-cells"); +WARNING_PROPERTY_PHANDLE_CELLS(phys, "phys", "#phy-cells"); +WARNING_PROPERTY_PHANDLE_CELLS(power_domains, "power-domains", "#power-domain-cells"); +WARNING_PROPERTY_PHANDLE_CELLS(pwms, "pwms", "#pwm-cells"); +WARNING_PROPERTY_PHANDLE_CELLS(resets, "resets", "#reset-cells"); +WARNING_PROPERTY_PHANDLE_CELLS(sound_dais, "sound-dais", "#sound-dai-cells"); +WARNING_PROPERTY_PHANDLE_CELLS(thermal_sensors, "thermal-sensors", "#thermal-sensor-cells"); + static struct check *check_table[] = { &duplicate_node_names, &duplicate_property_names, &node_name_chars, &node_name_format, &property_name_chars, @@ -987,6 +1074,23 @@ static struct check *check_table[] = { &avoid_default_addr_size, &obsolete_chosen_interrupt_controller, + &clocks_property, + &cooling_device_property, + &dmas_property, + &hwlocks_property, + &interrupts_extended_property, + &io_channels_property, + &iommus_property, + &mboxes_property, + &msi_parent_property, + &mux_controls_property, + &phys_property, + &power_domains_property, + &pwms_property, + &resets_property, + &sound_dais_property, + &thermal_sensors_property, + &always_fail, }; diff --git a/dtc.h b/dtc.h index 409db76c94b7..3c0532a7c3ab 100644 --- a/dtc.h +++ b/dtc.h @@ -216,6 +216,7 @@ void append_to_property(struct node *node, const char *get_unitname(struct node *node); struct property *get_property(struct node *node, const char *propname); cell_t propval_cell(struct property *prop); +cell_t propval_cell_n(struct property *prop, int n); struct property *get_property_by_label(struct node *tree, const char *label, struct node **node); struct marker *get_marker_label(struct node *tree, const char *label, diff --git a/livetree.c b/livetree.c index aecd27875fdd..c815176ec241 100644 --- a/livetree.c +++ b/livetree.c @@ -396,6 +396,12 @@ cell_t propval_cell(struct property *prop) return fdt32_to_cpu(*((fdt32_t *)prop->val.val)); } +cell_t propval_cell_n(struct property *prop, int n) +{ + assert(prop->val.len / sizeof(cell_t) >= n); + return fdt32_to_cpu(*((fdt32_t *)prop->val.val + n)); +} + struct property *get_property_by_label(struct node *tree, const char *label, struct node **node) { diff --git a/tests/bad-phandle-cells.dts b/tests/bad-phandle-cells.dts new file mode 100644 index 000000000000..7f7c6a25fd25 --- /dev/null +++ b/tests/bad-phandle-cells.dts @@ -0,0 +1,11 @@ +/dts-v1/; + +/ { + intc: interrupt-controller { + #interrupt-cells = <3>; + }; + + node { + interrupts-extended = <&intc>; + }; +}; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 3bc5b41ce76d..7cbc6971130a 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -550,6 +550,7 @@ dtc_tests () { check_tests unit-addr-without-reg.dts unit_address_vs_reg check_tests unit-addr-leading-0x.dts unit_address_format check_tests unit-addr-leading-0s.dts unit_address_format + check_tests bad-phandle-cells.dts interrupts_extended_property run_sh_test dtc-checkfails.sh node_name_chars -- -I dtb -O dtb bad_node_char.dtb run_sh_test dtc-checkfails.sh node_name_format -- -I dtb -O dtb bad_node_format.dtb run_sh_test dtc-checkfails.sh prop_name_chars -- -I dtb -O dtb bad_prop_char.dtb From patchwork Tue Aug 22 23:02:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 110701 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp3326197qge; Tue, 22 Aug 2017 16:02:22 -0700 (PDT) X-Received: by 10.98.194.11 with SMTP id l11mr732448pfg.248.1503442941942; Tue, 22 Aug 2017 16:02:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503442941; cv=none; d=google.com; s=arc-20160816; b=0b55dcelXSx7rLcfcLITLngB65Z77exP21bpJoDjIdmoLmXNzx97Y+pK/zPr5thiGM NpzXizxEr7me6UiX9mH0AVU2nseb37zhaO/xhzjBsYhHFD9T+tY8jgWwYY5cU79pXt7v Pw+X8LcnPSW/y9cKfHCeb3Q+8DOaJXicAriEJKmj5XFM8N1e6IsQDWlq7XSswMSxVqFi tKRvoC0KqHEAv2ZjsI2HIRWuzXTB937USwMNOPhs5rdHGWEYGgA2oowRJfFvpvIX3dZu ofRQPF/EdLNHPeCMixJM1ctZjmlOo3//ZHjVHSXXWyJ0zS67VmcHvcRP2iMUT4/OjEpt y5ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=N4yZfMvBGAhQoQiEj1PQdxqQHjt424OTQQTg6/EMMpI=; b=AN3L6dyUODYEaNSJBtR3cRQGMPJYITTcF/NWMQILLiMtyYS6fKHYW+x/va7jj9oSEO EZe+Rev8ULoa+t8BIzl/yf9ECud/RnlwdZ5CsY9gYBjXmlMtlUNoLsDpLfnSVdAMLpmd HQVpjA/xyf9i5NEe3mjY/k2oraaJVjDmzFwJLNFSYQtkAFj0IF+jDFKfMxyzMGCpWkbp 6+1LO6Gww5UXEmchREAkG7M/XXYTNW66YpJAYMiccArSFn3q6qSfQWEDO7QxLfZoSzrv T8s6Khthezbb4hIZvTSPTyaVHdpodeBH9E8CmWJYrwiABtNgthgoRKfyzaK/AESkNcHV /jxw== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v189si64822pgd.384.2017.08.22.16.02.21; Tue, 22 Aug 2017 16:02:21 -0700 (PDT) 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 S1752659AbdHVXCR (ORCPT + 6 others); Tue, 22 Aug 2017 19:02:17 -0400 Received: from mail-oi0-f66.google.com ([209.85.218.66]:38525 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752779AbdHVXCO (ORCPT ); Tue, 22 Aug 2017 19:02:14 -0400 Received: by mail-oi0-f66.google.com with SMTP id j144so126794oib.5; Tue, 22 Aug 2017 16:02:13 -0700 (PDT) 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:in-reply-to :references; bh=oE5V2QktCQ9tb31TzF4s3p2U+X2bxys4/jBe1IRR428=; b=lCcReWsuK6ojvqDtKqcdlMoIBFEgnzbfyBO6M5vQhdosguPYfbTMvrNiopcxKV1en6 Ym/nuF/YcHflyE0ftKyOXHxwV8Plr8xyDjJdeR4UDZDjek8sA9md6FNmct/yHPYn6Dt8 OOXVaW0mmnE67FDFLQFsDfDMNiu//W/iG4hPJZ01VrZUatvztemCwgSjtMG8OSw8AyNl DDthuhzNi2g+GMBYJlrtioHMxTRreNhAWBsmvqjtI3+oGdlbtGj2FB5trXb+zYEGtVXo BoNe9HQrjExVTKSMxIPtvlEz0shTrKNRKHb3K6RmUodcWTXlP7y2Jl1Xl3xSWbI41u5w Tt/g== X-Gm-Message-State: AHYfb5gtBJuqq6vwm1QMRS/7xzj2WHVS7rDX6fLWvPnGcCqXF4T1rbDH +un4ctxVnycfRP0LwVg= X-Received: by 10.202.205.204 with SMTP id d195mr943263oig.229.1503442933434; Tue, 22 Aug 2017 16:02:13 -0700 (PDT) Received: from localhost.localdomain (216-188-254-6.dyn.grandenetworks.net. [216.188.254.6]) by smtp.googlemail.com with ESMTPSA id u196sm108821oia.57.2017.08.22.16.02.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Aug 2017 16:02:12 -0700 (PDT) From: Rob Herring To: David Gibson Cc: devicetree-compiler@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v2 2/3] checks: add gpio binding properties check Date: Tue, 22 Aug 2017 18:02:07 -0500 Message-Id: <20170822230208.20987-3-robh@kernel.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170822230208.20987-1-robh@kernel.org> References: <20170822230208.20987-1-robh@kernel.org> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The GPIO binding is different compared to other phandle plus args properties in that the property name has a variable, optional prefix. The format of the property name is [-]gpio{s} where can be any legal property string. Therefore, custom matching of property names is needed, but the common check_property_phandle_args() function can still be used. It's possible that there are property names matching which are not GPIO binding specifiers. There's only been one case found in testing which is "[,]nr-gpio{s}". This property has been blacklisted and the same should be done to any others we find. This check will prevent getting any more of these, too. Signed-off-by: Rob Herring --- v2: - New patch with GPIO checks split to separate patch - Add check for deprecated [-]gpio form - Rework property name matching to include "gpio" and "gpios" - Skip the "gpios" property in gpio hogs binding - Improve the blacklisting comment - Add a test checks.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/bad-gpio.dts | 13 ++++++++++ tests/run_tests.sh | 2 ++ 3 files changed, 88 insertions(+) create mode 100644 tests/bad-gpio.dts -- 2.11.0 -- 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 Reviewed-by: David Gibson diff --git a/checks.c b/checks.c index 548d7e118c42..3315a4646497 100644 --- a/checks.c +++ b/checks.c @@ -1043,6 +1043,76 @@ WARNING_PROPERTY_PHANDLE_CELLS(resets, "resets", "#reset-cells"); WARNING_PROPERTY_PHANDLE_CELLS(sound_dais, "sound-dais", "#sound-dai-cells"); WARNING_PROPERTY_PHANDLE_CELLS(thermal_sensors, "thermal-sensors", "#thermal-sensor-cells"); +static bool prop_is_gpio(struct property *prop) +{ + char *str; + + /* + * *-gpios and *-gpio can appear in property names, + * so skip over any false matches (only one known ATM) + */ + if (strstr(prop->name, "nr-gpio")) + return false; + + str = strrchr(prop->name, '-'); + if (str) + str++; + else + str = prop->name; + if (!(streq(str, "gpios") || streq(str, "gpio"))) + return false; + + return true; +} + +static void check_gpios_property(struct check *c, + struct dt_info *dti, + struct node *node) +{ + struct property *prop; + + /* Skip GPIO hog nodes which have 'gpios' property */ + if (get_property(node, "gpio-hog")) + return; + + for_each_property(node, prop) { + struct provider provider; + + if (!prop_is_gpio(prop)) + continue; + + provider.prop_name = prop->name; + provider.cell_name = "#gpio-cells"; + provider.optional = false; + check_property_phandle_args(c, dti, node, prop, &provider); + } + +} +WARNING(gpios_property, check_gpios_property, NULL, &phandle_references); + +static void check_deprecated_gpio_property(struct check *c, + struct dt_info *dti, + struct node *node) +{ + struct property *prop; + + for_each_property(node, prop) { + char *str; + + if (!prop_is_gpio(prop)) + continue; + + str = strstr(prop->name, "gpio"); + if (!streq(str, "gpio")) + continue; + + FAIL(c, dti, "'[*-]gpio' is deprecated, use '[*-]gpios' instead for %s:%s", + node->fullpath, prop->name); + } + +} +CHECK(deprecated_gpio_property, check_deprecated_gpio_property, NULL); + static struct check *check_table[] = { &duplicate_node_names, &duplicate_property_names, &node_name_chars, &node_name_format, &property_name_chars, @@ -1091,6 +1161,9 @@ static struct check *check_table[] = { &sound_dais_property, &thermal_sensors_property, + &deprecated_gpio_property, + &gpios_property, + &always_fail, }; diff --git a/tests/bad-gpio.dts b/tests/bad-gpio.dts new file mode 100644 index 000000000000..6b77be447b82 --- /dev/null +++ b/tests/bad-gpio.dts @@ -0,0 +1,13 @@ +/dts-v1/; + +/ { + gpio: gpio-controller { + #gpio-cells = <3>; + }; + + node { + nr-gpios = <1>; + foo-gpios = <&gpio>; + bar-gpio = <&gpio 1 2 3>; + }; +}; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 7cbc6971130a..2a29fa4ee451 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -551,6 +551,8 @@ dtc_tests () { check_tests unit-addr-leading-0x.dts unit_address_format check_tests unit-addr-leading-0s.dts unit_address_format check_tests bad-phandle-cells.dts interrupts_extended_property + check_tests bad-gpio.dts gpios_property + run_sh_test dtc-checkfails.sh deprecated_gpio_property -- -Wdeprecated_gpio_property -I dts -O dtb bad-gpio.dts run_sh_test dtc-checkfails.sh node_name_chars -- -I dtb -O dtb bad_node_char.dtb run_sh_test dtc-checkfails.sh node_name_format -- -I dtb -O dtb bad_node_format.dtb run_sh_test dtc-checkfails.sh prop_name_chars -- -I dtb -O dtb bad_prop_char.dtb From patchwork Tue Aug 22 23:02:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 110699 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp3326133qge; Tue, 22 Aug 2017 16:02:19 -0700 (PDT) X-Received: by 10.84.231.9 with SMTP id f9mr740487plk.257.1503442939049; Tue, 22 Aug 2017 16:02:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503442939; cv=none; d=google.com; s=arc-20160816; b=Qtohhe1ouxaXF61UiGHP+ur50B3fDngiyAc7HrNuEl3HTYVenPSBErPcguf5PRgV1x aI9rasrtIWDE47fHJTDtiem4/TITcnptCoLf/7w8J8UY+HAkZvm0BeJ8U1uwcDTP4POU nsUoZoneJkwiCL+lHx9Gh68JYG/opYPBri5Avo7V9up/hDJp1TmrqChw4TiYLCPR5Ja0 f3RAQgHdpBgDwG5Ypr+zaCHb5n9jjeiGksY86pjeLpMVB5CGulMaqLaij0Q/EVAvkqu1 gMADXLSeu6fyywCEqHFgR6v/rWsVIU8Zb5xzWzLwzNqufIclkikx/fUEzVS86jg8GMOk z23Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=hbnCw2d8GWlj//yDuEEQxILHXwnHiJ1UA8om5YcQwI4=; b=rs6UVmDg4WOH/3DYmeUzRT1O54lwB2z+AfPYEUbuF9BpvC5TPkUdcc3tRIi1Wc6TLE RpYaDWzfCaJZiHA1BMHsCIb5/d3gMncWF4IMwiRPzZBeO20b8LBb1PY6Pd/uMmM9yEv+ aeLDxxWPGQ0jErnHkm6DkUu0/wRGZ3gEa+QUuTlVLRaNyMuOmBxiPQxIxQBrYoWvBurE UjxZKv+N4qNTv5A0Y8GCfL51p5ceesDWTGyitiH4dChw5ldoOeNQZf81h5oqRQdqkloK PNUuIXnUkQrVgLF4uEVoMkVBzx0jgHHAZxtYjTgVpeCStxXUR41SzwEG7XRV1frUBP1E tF9A== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v189si64822pgd.384.2017.08.22.16.02.18; Tue, 22 Aug 2017 16:02:19 -0700 (PDT) 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 S1752784AbdHVXCQ (ORCPT + 6 others); Tue, 22 Aug 2017 19:02:16 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:35908 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752659AbdHVXCP (ORCPT ); Tue, 22 Aug 2017 19:02:15 -0400 Received: by mail-oi0-f68.google.com with SMTP id p62so151547oih.3; Tue, 22 Aug 2017 16:02:15 -0700 (PDT) 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:in-reply-to :references; bh=bmNV42p5jp2UF8qEf45/ZUptC7CNy4dPBduVokx2V5M=; b=YLXc9q6xKklFXkSjiDDKKzUNShyZvd3ySbQHpPiApMfep5A26KXEs5TJUBcYQYYqEZ p0ApG1Mo+LAFN/TAziALw53mn56kivj+l2g94GnYDhsfe45yIqb6s9yNA7aDYiZc0wxF q5N1T6NS6odvNpNtbgfognR7cuBwadbUwD19xshcd9XmLa5ETbG3JqXuLsIuXG9qTEMM w/+pBGKG5uRrtgC/r4KApizMWrLSyzDSuh0k6RDEQHebAvQn5n+CcDqvoQaVhOtx1NHZ +bNDHfJM5SnWDk9xH9Cgf3cECwS2mbNYr3SfWRan3GD0McVn58rEFVzGRNhZjJHFl9U6 EUuQ== X-Gm-Message-State: AHYfb5jrkiLZTAVIpCm3VVB32FK8iR31KepPYaX1LdB3dtwnxNI4ShsF liYC+6xXDqGJag== X-Received: by 10.202.77.212 with SMTP id a203mr1031676oib.184.1503442934550; Tue, 22 Aug 2017 16:02:14 -0700 (PDT) Received: from localhost.localdomain (216-188-254-6.dyn.grandenetworks.net. [216.188.254.6]) by smtp.googlemail.com with ESMTPSA id u196sm108821oia.57.2017.08.22.16.02.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Aug 2017 16:02:13 -0700 (PDT) From: Rob Herring To: David Gibson Cc: devicetree-compiler@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v2 3/3] checks: add interrupts property check Date: Tue, 22 Aug 2017 18:02:08 -0500 Message-Id: <20170822230208.20987-4-robh@kernel.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170822230208.20987-1-robh@kernel.org> References: <20170822230208.20987-1-robh@kernel.org> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add a check for nodes with interrupts property that they have a valid parent, the parent has #interrupt-cells property, and the size is a valid multiple of #interrupt-cells. This may not handle every possible case and doesn't deal with translation thru interrupt-map properties, but should be enough for modern dts files. Signed-off-by: Rob Herring --- v2: - Add a test - Check for interrupt-map when looking for interrupt parent. - Check that explicit interrupt-parent node has an interrupt-controller or interrupt-map property. checks.c | 76 +++++++++++++++++++++++++++++++++++++++++++ tests/bad-interrupt-cells.dts | 12 +++++++ tests/run_tests.sh | 1 + 3 files changed, 89 insertions(+) create mode 100644 tests/bad-interrupt-cells.dts -- 2.11.0 -- 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 Reviewed-by: David Gibson diff --git a/checks.c b/checks.c index 3315a4646497..6b505e9c49d8 100644 --- a/checks.c +++ b/checks.c @@ -1113,6 +1113,81 @@ static void check_deprecated_gpio_property(struct check *c, } CHECK(deprecated_gpio_property, check_deprecated_gpio_property, NULL); +static bool node_is_interrupt_provider(struct node *node) +{ + struct property *prop; + + prop = get_property(node, "interrupt-controller"); + if (prop) + return true; + + prop = get_property(node, "interrupt-map"); + if (prop) + return true; + + return false; +} +static void check_interrupts_property(struct check *c, + struct dt_info *dti, + struct node *node) +{ + struct node *root = dti->dt; + struct node *irq_node = NULL, *parent = node; + struct property *irq_prop, *prop = NULL; + int irq_cells, phandle; + + irq_prop = get_property(node, "interrupts"); + if (!irq_prop) + return; + + while (parent && !prop) { + if (parent != node && node_is_interrupt_provider(parent)) { + irq_node = parent; + break; + } + + prop = get_property(parent, "interrupt-parent"); + if (prop) { + phandle = propval_cell(prop); + irq_node = get_node_by_phandle(root, phandle); + if (!irq_node) { + FAIL(c, dti, "Bad interrupt-parent phandle for %s", + node->fullpath); + return; + } + if (!node_is_interrupt_provider(irq_node)) + FAIL(c, dti, + "Missing interrupt-controller or interrupt-map property in %s", + irq_node->fullpath); + + break; + } + + parent = parent->parent; + } + + if (!irq_node) { + FAIL(c, dti, "Missing interrupt-parent for %s", node->fullpath); + return; + } + + prop = get_property(irq_node, "#interrupt-cells"); + if (!prop) { + FAIL(c, dti, "Missing #interrupt-cells in interrupt-parent %s", + irq_node->fullpath); + return; + } + + irq_cells = propval_cell(prop); + if (irq_prop->val.len % (irq_cells * sizeof(cell_t))) { + FAIL(c, dti, + "interrupts size is (%d), expected multiple of %d in %s", + irq_prop->val.len, (int)(irq_cells * sizeof(cell_t)), + node->fullpath); + } +} +WARNING(interrupts_property, check_interrupts_property, &phandle_references); + static struct check *check_table[] = { &duplicate_node_names, &duplicate_property_names, &node_name_chars, &node_name_format, &property_name_chars, @@ -1163,6 +1238,7 @@ static struct check *check_table[] = { &deprecated_gpio_property, &gpios_property, + &interrupts_property, &always_fail, }; diff --git a/tests/bad-interrupt-cells.dts b/tests/bad-interrupt-cells.dts new file mode 100644 index 000000000000..39fc78fdc11d --- /dev/null +++ b/tests/bad-interrupt-cells.dts @@ -0,0 +1,12 @@ +/dts-v1/; + +/ { + interrupt-parent = <&intc>; + intc: interrupt-controller { + #interrupt-cells = <3>; + }; + + node { + interrupts = <1>; + }; +}; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 2a29fa4ee451..cc35205f5768 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -553,6 +553,7 @@ dtc_tests () { check_tests bad-phandle-cells.dts interrupts_extended_property check_tests bad-gpio.dts gpios_property run_sh_test dtc-checkfails.sh deprecated_gpio_property -- -Wdeprecated_gpio_property -I dts -O dtb bad-gpio.dts + check_tests bad-interrupt-cells.dts interrupts_property run_sh_test dtc-checkfails.sh node_name_chars -- -I dtb -O dtb bad_node_char.dtb run_sh_test dtc-checkfails.sh node_name_format -- -I dtb -O dtb bad_node_format.dtb run_sh_test dtc-checkfails.sh prop_name_chars -- -I dtb -O dtb bad_prop_char.dtb