[PATCH v3 6/6] dtc: dt-check-style: Handle properly DTC-style includes
From: Krzysztof Kozlowski <hidden>
Date: 2026-07-06 15:54:05
Also in:
lkml
Subsystem:
open firmware and flattened device tree, the rest · Maintainers:
Rob Herring, Saravana Kannan, Linus Torvalds
dt-check-style was not properly handling DTC directives (starting with '/', e.g. /dts-v1/ or /include/), thus a few DTS files had false positive like: apm/apm-merlin.dts:1: [indent-unit-dts] indent unit must be 1 tab in DTS, got '\t\t' Signed-off-by: Krzysztof Kozlowski <redacted> --- Changes in v3: New patch --- scripts/dtc/dt-check-style | 11 ++++-- scripts/dtc/dt-style-selftest/good/dts-dtc.dts | 20 +++++++++++ .../dt-style-selftest/good/dts-preprocessor.dts | 20 +++++++++++ scripts/dtc/dt-style-selftest/good/soc.dtsi | 40 ++++++++++++++++++++++ 4 files changed, 89 insertions(+), 2 deletions(-)
diff --git a/scripts/dtc/dt-check-style b/scripts/dtc/dt-check-style
index 3c1aa9e28347..b8ba6dbee86d 100755
--- a/scripts/dtc/dt-check-style
+++ b/scripts/dtc/dt-check-style@@ -49,6 +49,9 @@ re_cpp_directive = re.compile( r'^#\s*(include|define|undef|ifdef|ifndef|if|else|elif|endif|' r'pragma|error|warning)\b') +re_dtc_directive = re.compile( + r'^/(dts-v1|include)/[;\s]') + # label: name@addr { -- label and addr optional; name can be "/" # Per the DT spec a node name may start with a digit (e.g. 1wire@...). # The address part is captured loosely (any non-space, non-brace run) so
@@ -66,7 +69,11 @@ re_ref_node = re.compile( def is_preprocessor(stripped): """Tell C preprocessor directives apart from DTS '#'-prefixed props.""" - return re_cpp_directive.match(stripped) is not None + if re_cpp_directive.match(stripped) is not None: + return True + if re_dtc_directive.match(stripped) is not None: + return True + return False class DtsLine:
@@ -178,7 +185,7 @@ def classify_lines(text): out.append(dl) continue - if stripped.startswith('#') and is_preprocessor(stripped): + if (stripped.startswith('#') or stripped.startswith('/')) and is_preprocessor(stripped): dl = DtsLine(i, raw, LineType.PREPROCESSOR, indent_str, stripped) dl.depth = depth
diff --git a/scripts/dtc/dt-style-selftest/good/dts-dtc.dts b/scripts/dtc/dt-style-selftest/good/dts-dtc.dts
new file mode 100644
index 000000000000..4f249e9406c7
--- /dev/null
+++ b/scripts/dtc/dt-style-selftest/good/dts-dtc.dts@@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +/* + * Test fixture: dtc directive + */ + +/dts-v1/; + +/include/ "soc.dtsi" + +/ { + compatible = "example,test-board"; + #address-cells = <1>; + #size-cells = <1>; + + leds { + led-0 { + compatible = "example,led"; + }; + }; +};
diff --git a/scripts/dtc/dt-style-selftest/good/dts-preprocessor.dts b/scripts/dtc/dt-style-selftest/good/dts-preprocessor.dts
new file mode 100644
index 000000000000..86cfd33086ee
--- /dev/null
+++ b/scripts/dtc/dt-style-selftest/good/dts-preprocessor.dts@@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +/* + * Test fixture: preprocessor directive + */ + +/dts-v1/; + +#include "soc.dtsi" + +/ { + compatible = "example,test-board"; + #address-cells = <1>; + #size-cells = <1>; + + leds { + led-0 { + compatible = "example,led"; + }; + }; +};
diff --git a/scripts/dtc/dt-style-selftest/good/soc.dtsi b/scripts/dtc/dt-style-selftest/good/soc.dtsi
new file mode 100644
index 000000000000..af7477cb8e3d
--- /dev/null
+++ b/scripts/dtc/dt-style-selftest/good/soc.dtsi@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +/ { + #address-cells = <1>; + #size-cells = <1>; + + memory@a0000000 { + device_type = "memory"; + reg = <0x0 0xa0000000 0x0 0x0>; + }; + + pmu { + compatible = "example,pmu"; + }; + + soc@0 { + compatible = "simple-bus"; + ranges = <0 0 0 0xc0000000>; + + #address-cells = <1>; + #size-cells = <1>; + + interrupt-controller@10000 { + compatible = "example,intc"; + reg = <0x10000 0x1000>; + interrupts = <1 2 3>, + <4 5 6>, + <7 8 9>; + }; + + serial@20000 { + compatible = "example,serial"; + reg = <0x20000 0x1000>; + }; + + serial@30000 { + compatible = "example,serial"; + reg = <0x30000 0x1000>; + }; + }; +};
--
2.53.0