b4-sent.feeds.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] dt-check-style support for indented include fragments
@ 2026-08-30 18:24 Sven Peter
  2026-08-30 18:24 ` [PATCH 1/2] dt-check-style: Handle indented fragments in indent-unit-dts Sven Peter
  2026-08-30 18:24 ` [PATCH 2/2] dt-check-style: Handle indented fragments in indent-consistent Sven Peter
  0 siblings, 2 replies; 3+ messages in thread
From: Sven Peter @ 2026-08-30 18:24 UTC (permalink / raw)
  To: Rob Herring, Saravana Kannan
  Cc: Daniel Golle, Krzysztof Kozlowski, linux-kernel, devicetree,
	asahi, Sven Peter

Hi,

Some .dtsi files are included from inside a node and carry the
indentation of that context. This is e.g. used for the multi-die
Apple SoCs and dt-check-style currently interprets that as part
of the indent unit and reports spurious warnings for otherwise
correctly indented Apple and Broadcom fragments.

Teach indent-unit-dts to detect and validate the inherited prefix and
make indent-consistent account for it as well. Also add fixtures to
test this.

With this all arm64 device trees pass the relaxed checks.

Best,

Sven

Signed-off-by: Sven Peter <sven@kernel.org>
---
Sven Peter (2):
      dt-check-style: Handle indented fragments in indent-unit-dts
      dt-check-style: Handle indented fragments in indent-consistent

 scripts/dtc/dt-check-style                         | 72 +++++++++++++++++-----
 .../dt-style-selftest/bad/dts-fragment-indent.dtsi | 12 ++++
 .../bad/dts-fragment-missing-prefix.dtsi           |  6 ++
 .../bad/dts-indented-ref-node.dtsi                 |  6 ++
 .../expected/dts-fragment-indent.dtsi.txt          |  3 +
 .../expected/dts-fragment-missing-prefix.dtsi.txt  |  2 +
 .../expected/dts-indented-ref-node.dtsi.txt        |  2 +
 .../dtc/dt-style-selftest/good/dts-fragment.dtsi   | 19 ++++++
 8 files changed, 106 insertions(+), 16 deletions(-)
---
base-commit: a23cbb05744b22719efdc34f9e329a120e81e617
change-id: 20260830-b4-dts-check-fix-db992ba0a7dd

Best regards,
--  
Sven Peter <sven@kernel.org>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] dt-check-style: Handle indented fragments in indent-unit-dts
  2026-08-30 18:24 [PATCH 0/2] dt-check-style support for indented include fragments Sven Peter
@ 2026-08-30 18:24 ` Sven Peter
  2026-08-30 18:24 ` [PATCH 2/2] dt-check-style: Handle indented fragments in indent-consistent Sven Peter
  1 sibling, 0 replies; 3+ messages in thread
From: Sven Peter @ 2026-08-30 18:24 UTC (permalink / raw)
  To: Rob Herring, Saravana Kannan
  Cc: Daniel Golle, Krzysztof Kozlowski, linux-kernel, devicetree,
	asahi, Sven Peter

The multi-die Apple SoCs contain most of their nodes in a file that is
included to instantiate the same nodes across both dies. These included
fragments all have a tabs-only prefix that is correct in the final
composed file. dt-check-style however finds the first line starting with
two (or more) tabs and then indent-unit-dts rejects those correctly
indented files.

Fix that by detecing a tabs-only prefix shared by rootless files and
treat that as a constant offset. Also add fixtures to test this.

Signed-off-by: Sven Peter <sven@kernel.org>
---
 scripts/dtc/dt-check-style                         | 69 +++++++++++++++++-----
 .../bad/dts-fragment-missing-prefix.dtsi           |  6 ++
 .../bad/dts-indented-ref-node.dtsi                 |  6 ++
 .../expected/dts-fragment-missing-prefix.dtsi.txt  |  2 +
 .../expected/dts-indented-ref-node.dtsi.txt        |  2 +
 5 files changed, 70 insertions(+), 15 deletions(-)

diff --git a/scripts/dtc/dt-check-style b/scripts/dtc/dt-check-style
index 96deffc0d8a7..2afc05fa6602 100755
--- a/scripts/dtc/dt-check-style
+++ b/scripts/dtc/dt-check-style
@@ -380,12 +380,43 @@ def check_mixed_indent_chars(ctx):
                 yield (cont.lineno, 'mixed tabs and spaces in indent')
 
 
+def detect_fragment_offset(ctx):
+    """Return the indentation inherited from an include context.
+
+    A fragment has neither a root nor top-level reference nodes and all
+    its top-level lines share the same tabs-only indentation.
+    """
+    if ctx.file_type != 'dts':
+        return ''
+    offset = None
+    for dl in ctx.lines:
+        if dl.depth != 0:
+            continue
+        if dl.linetype not in (LineType.NODE_OPEN, LineType.NODE_CLOSE,
+                               LineType.PROPERTY):
+            continue
+        if dl.linetype == LineType.NODE_OPEN and \
+                (dl.node_name == '/' or dl.ref_name is not None):
+            return ''
+        if offset is None:
+            offset = dl.indent_str
+        elif dl.indent_str != offset:
+            return ''
+    if not offset:
+        return ''
+    if any(char != '\t' for char in offset):
+        return ''
+    return offset
+
+
 def detect_indent_unit(ctx):
     """Find the indent unit used at depth 1 in this block.
 
     Returns tuple of string (one of: '  ' (2 spaces), '    ' (4 spaces),
-    '\\t' (tab), or None if depth-1 is empty or ambiguous) and line number when
-    detection was made)."""
+    '\\t' (tab), or None if depth-1 is empty or ambiguous), line number when
+    detection was made, and whether the detected fragment prefix is valid.
+    """
+    prefix = detect_fragment_offset(ctx)
     for dl in ctx.lines:
         if dl.depth != 1:
             continue
@@ -395,20 +426,25 @@ def detect_indent_unit(ctx):
             continue
         if not dl.indent_str:
             continue
-        if dl.indent_str == '\t':
-            return ('\t', dl.lineno)
-        if dl.indent_str == '    ':
-            return ('    ', dl.lineno)
-        if dl.indent_str == '  ':
-            return ('  ', dl.lineno)
+        indent = dl.indent_str
+        if prefix and not indent.startswith(prefix):
+            return (indent, dl.lineno, False)
+        if prefix:
+            indent = indent[len(prefix):]
+        if indent == '\t':
+            return ('\t', dl.lineno, True)
+        if indent == '    ':
+            return ('    ', dl.lineno, True)
+        if indent == '  ':
+            return ('  ', dl.lineno, True)
         # Anything else at depth 1 is non-canonical; flag elsewhere.
-        return (dl.indent_str, dl.lineno)
-    return (None, None)
+        return (indent, dl.lineno, True)
+    return (None, None, True)
 
 
 def check_indent_unit_relaxed(ctx):
     """YAML examples: 2 or 4 spaces. Never tabs or other widths."""
-    (unit, lineno) = detect_indent_unit(ctx)
+    (unit, lineno, _) = detect_indent_unit(ctx)
     if unit is None:
         return
     if unit not in ('  ', '    '):
@@ -417,7 +453,10 @@ def check_indent_unit_relaxed(ctx):
 
 def check_indent_unit_dts(ctx):
     """DTS files: 1 tab per level. Always required."""
-    (unit, lineno) = detect_indent_unit(ctx)
+    (unit, lineno, prefix_valid) = detect_indent_unit(ctx)
+    if not prefix_valid:
+        yield (lineno, 'indent does not start with fragment offset')
+        return
     if unit is None:
         return
     if unit != '\t':
@@ -426,7 +465,7 @@ def check_indent_unit_dts(ctx):
 
 def check_indent_unit_strict(ctx):
     """YAML: must be exactly 4 spaces. DTS: 1 tab (same as relaxed)."""
-    (unit, lineno) = detect_indent_unit(ctx)
+    (unit, lineno, _) = detect_indent_unit(ctx)
     if unit is None:
         return
     if ctx.file_type == 'yaml':
@@ -437,8 +476,8 @@ def check_indent_unit_strict(ctx):
 
 def check_indent_consistent(ctx):
     """All indented lines must be a multiple of the detected unit."""
-    (unit, lineno) = detect_indent_unit(ctx)
-    if unit is None:
+    (unit, lineno, prefix_valid) = detect_indent_unit(ctx)
+    if unit is None or not prefix_valid:
         return
     if ctx.file_type == 'yaml':
         if unit not in ('  ', '    '):
diff --git a/scripts/dtc/dt-style-selftest/bad/dts-fragment-missing-prefix.dtsi b/scripts/dtc/dt-style-selftest/bad/dts-fragment-missing-prefix.dtsi
new file mode 100644
index 000000000000..a72735e0884b
--- /dev/null
+++ b/scripts/dtc/dt-style-selftest/bad/dts-fragment-missing-prefix.dtsi
@@ -0,0 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+/* Include fragment whose child does not contain the inherited indentation. */
+
+		bus@10000 {
+	compatible = "simple-bus";
+		};
diff --git a/scripts/dtc/dt-style-selftest/bad/dts-indented-ref-node.dtsi b/scripts/dtc/dt-style-selftest/bad/dts-indented-ref-node.dtsi
new file mode 100644
index 000000000000..cabe4ee96d10
--- /dev/null
+++ b/scripts/dtc/dt-style-selftest/bad/dts-indented-ref-node.dtsi
@@ -0,0 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+/* Reference nodes must remain at column zero. */
+
+	&example {
+		status = "okay";
+	};
diff --git a/scripts/dtc/dt-style-selftest/expected/dts-fragment-missing-prefix.dtsi.txt b/scripts/dtc/dt-style-selftest/expected/dts-fragment-missing-prefix.dtsi.txt
new file mode 100644
index 000000000000..eb525dddd904
--- /dev/null
+++ b/scripts/dtc/dt-style-selftest/expected/dts-fragment-missing-prefix.dtsi.txt
@@ -0,0 +1,2 @@
+# mode=relaxed
+bad/dts-fragment-missing-prefix.dtsi:5: [indent-unit-dts] indent does not start with fragment offset
diff --git a/scripts/dtc/dt-style-selftest/expected/dts-indented-ref-node.dtsi.txt b/scripts/dtc/dt-style-selftest/expected/dts-indented-ref-node.dtsi.txt
new file mode 100644
index 000000000000..ed86cc9b36c6
--- /dev/null
+++ b/scripts/dtc/dt-style-selftest/expected/dts-indented-ref-node.dtsi.txt
@@ -0,0 +1,2 @@
+# mode=strict
+bad/dts-indented-ref-node.dtsi:5: [indent-unit-dts] indent unit must be 1 tab in DTS, got '\t\t'

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] dt-check-style: Handle indented fragments in indent-consistent
  2026-08-30 18:24 [PATCH 0/2] dt-check-style support for indented include fragments Sven Peter
  2026-08-30 18:24 ` [PATCH 1/2] dt-check-style: Handle indented fragments in indent-unit-dts Sven Peter
@ 2026-08-30 18:24 ` Sven Peter
  1 sibling, 0 replies; 3+ messages in thread
From: Sven Peter @ 2026-08-30 18:24 UTC (permalink / raw)
  To: Rob Herring, Saravana Kannan
  Cc: Daniel Golle, Krzysztof Kozlowski, linux-kernel, devicetree,
	asahi, Sven Peter

indent-consistent compares every line against its nesting depth without
accounting for the constant indentation prefix used for include fragments.
It thus rejects otherwise valid fragments.

Fix that by adding the fragment prefix to the expected indentation and add
test fixtures.

Signed-off-by: Sven Peter <sven@kernel.org>
---
 scripts/dtc/dt-check-style                            |  3 ++-
 .../dt-style-selftest/bad/dts-fragment-indent.dtsi    | 12 ++++++++++++
 .../expected/dts-fragment-indent.dtsi.txt             |  3 +++
 scripts/dtc/dt-style-selftest/good/dts-fragment.dtsi  | 19 +++++++++++++++++++
 4 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/scripts/dtc/dt-check-style b/scripts/dtc/dt-check-style
index 2afc05fa6602..f867cb6d8070 100755
--- a/scripts/dtc/dt-check-style
+++ b/scripts/dtc/dt-check-style
@@ -486,6 +486,7 @@ def check_indent_consistent(ctx):
         if unit != '\t':
             return
 
+    prefix = detect_fragment_offset(ctx)
     for dl in ctx.lines:
         if dl.linetype in (LineType.BLANK, LineType.PREPROCESSOR):
             continue
@@ -498,7 +499,7 @@ def check_indent_consistent(ctx):
         # The indent must be 'unit' repeated dl.depth times, exactly.
         # NODE_CLOSE lines have depth equal to the post-decrement value,
         # which matches the indent expected.
-        expected = unit * dl.depth
+        expected = prefix + unit * dl.depth
         if dl.indent_str != expected:
             yield (dl.lineno,
                    'indent mismatch (expected depth %d * %r)' %
diff --git a/scripts/dtc/dt-style-selftest/bad/dts-fragment-indent.dtsi b/scripts/dtc/dt-style-selftest/bad/dts-fragment-indent.dtsi
new file mode 100644
index 000000000000..6d143c4dd9b2
--- /dev/null
+++ b/scripts/dtc/dt-style-selftest/bad/dts-fragment-indent.dtsi
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+/* Incorrect indentation inside an indented include fragment. */
+
+	bus@10000 {
+		compatible = "simple-bus";
+		reg = <0x10000 0x1000>;
+
+		device@100 {
+				compatible = "example,test";
+				reg = <0x100 0x10>;
+		};
+	};
diff --git a/scripts/dtc/dt-style-selftest/expected/dts-fragment-indent.dtsi.txt b/scripts/dtc/dt-style-selftest/expected/dts-fragment-indent.dtsi.txt
new file mode 100644
index 000000000000..84ec8eb73468
--- /dev/null
+++ b/scripts/dtc/dt-style-selftest/expected/dts-fragment-indent.dtsi.txt
@@ -0,0 +1,3 @@
+# mode=strict
+bad/dts-fragment-indent.dtsi:9: [indent-consistent] indent mismatch (expected depth 2 * '\t')
+bad/dts-fragment-indent.dtsi:10: [indent-consistent] indent mismatch (expected depth 2 * '\t')
diff --git a/scripts/dtc/dt-style-selftest/good/dts-fragment.dtsi b/scripts/dtc/dt-style-selftest/good/dts-fragment.dtsi
new file mode 100644
index 000000000000..58735112d3aa
--- /dev/null
+++ b/scripts/dtc/dt-style-selftest/good/dts-fragment.dtsi
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+/* Include fragment indented for its inclusion context. */
+
+	bus@10000 {
+		compatible = "simple-bus";
+		reg = <0x10000 0x1000>;
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		device@100 {
+			compatible = "example,test";
+			reg = <0x100 0x10>;
+		};
+	};
+
+	bus@20000 {
+		compatible = "simple-bus";
+		reg = <0x20000 0x1000>;
+	};

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-08-30 18:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-30 18:24 [PATCH 0/2] dt-check-style support for indented include fragments Sven Peter
2026-08-30 18:24 ` [PATCH 1/2] dt-check-style: Handle indented fragments in indent-unit-dts Sven Peter
2026-08-30 18:24 ` [PATCH 2/2] dt-check-style: Handle indented fragments in indent-consistent Sven Peter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).