dtc: dt-check-style: Handle properly DTC-style includes
authorKrzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Thu, 9 Jul 2026 17:41:33 +0000 (19:41 +0200)
committerRob Herring (Arm) <robh@kernel.org>
Mon, 20 Jul 2026 20:50:57 +0000 (15:50 -0500)
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 <krzysztof.kozlowski@oss.qualcomm.com>
Link: https://patch.msgid.link/20260709-dts-style-checker-v5-5-fcc147cb697d@oss.qualcomm.com
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
scripts/dtc/dt-check-style
scripts/dtc/dt-style-selftest/good/dts-dtc.dts [new file with mode: 0644]
scripts/dtc/dt-style-selftest/good/dts-preprocessor.dts [new file with mode: 0644]
scripts/dtc/dt-style-selftest/good/soc.dtsi [new file with mode: 0644]

index d19ef26..ad07b0d 100755 (executable)
@@ -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)/')
+
 # 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 (file)
index 0000000..a320719
--- /dev/null
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+/*
+ * Test fixture: dtc directive
+ */
+
+/dts-v1/;
+
+/include/ "soc.dtsi"
+/include/"soc-other.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 (file)
index 0000000..bd6d9dd
--- /dev/null
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+/*
+ * Test fixture: preprocessor directive
+ */
+
+/dts-v1/;
+
+#include "soc.dtsi"
+#include<dt-bindings/gpio/gpio.h>
+
+/ {
+       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 (file)
index 0000000..c602744
--- /dev/null
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+/ {
+       #address-cells = <1>;
+       #size-cells = <1>;
+
+       cpus {
+               #address-cells = <1>;
+               #size-cells = <0>;
+
+               cpu@0 {
+                       device_type = "cpu";
+                       compatible = "arm,cortex-a57";
+                       reg = <0x0 0x0>;
+                       enable-method = "psci";
+               };
+       };
+
+       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>;
+               };
+       };
+};