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