[PATCH 6/9] dtc: dt-check-style: Fix alignment of values in continued property lines

From: Krzysztof Kozlowski

Date: Sun Jul 26 2026 - 11:51:46 EST


Continued lines in property assignments should be indented to opening
'<' or '"' if they also start with that character, e.g.:

reg = <0x1000 0x100>,
<0x2000 0x100>;

If the continued line is part of previous phandle, then alignment should
be to inner values to make it more readable, e.g.:

reg = <0x1000 0x100
0x2000 0x100>;

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@xxxxxxxxxxxxxxxx>
---
scripts/dtc/dt-check-style | 20 ++++++++------
.../dtc/dt-style-selftest/bad/dts-cont-align.dts | 23 ++++++++++++++++
.../dtc/dt-style-selftest/bad/yaml-cont-align.yaml | 4 ++-
.../expected/dts-cont-align.dts.txt | 8 ++++++
.../expected/yaml-cont-align.yaml.txt | 1 +
.../expected/yaml-value-ws-multiline.yaml.txt | 1 +
.../dtc/dt-style-selftest/good/dts-cont-align.dts | 11 +++++---
.../dt-style-selftest/good/yaml-cont-align.yaml | 32 ++++++++++++++++++++++
8 files changed, 87 insertions(+), 13 deletions(-)

diff --git a/scripts/dtc/dt-check-style b/scripts/dtc/dt-check-style
index 4d90fbec0e39..171a5e12fcbd 100755
--- a/scripts/dtc/dt-check-style
+++ b/scripts/dtc/dt-check-style
@@ -914,10 +914,11 @@ def check_line_length(ctx):

def check_continuation_alignment(ctx):
"""A multi-line property's continuation lines must align their
- first non-whitespace character to the display column of the first
- '<' or '"' after the '=' in the leading line. Display columns are
- used so tab-indented .dts files (where a continuation aligns with
- tabs plus spaces) are compared correctly."""
+ first non-whitespace character to the display column of:
+ 1. the first '<' or '"' after the '=' in the leading line, if continuation is with '<' or '"'
+ 2. the first value, if the continuation is still the same phandle.
+ Display columns are used so tab-indented .dts files (where a continuation
+ aligns with tabs plus spaces) are compared correctly."""
for dl in ctx.lines:
if dl.linetype != LineType.PROPERTY:
continue
@@ -928,15 +929,18 @@ def check_continuation_alignment(ctx):
continue
# First '<' or '"' after '='
rest = dl.raw[eq + 1:]
- m = re.search(r'[<"]', rest)
+ m = re.search(r'\s*([<"])', rest)
if not m:
continue
- target_col = _display_col(dl.raw[:eq + 1 + m.start()])
+ target_col = _display_col(dl.raw[:eq + 1 + m.start(1)])
for cont in dl.continuations:
- if _display_col(cont.indent_str) != target_col:
+ target_offset = 0
+ if not re.match(r'[<"]', cont.stripped):
+ target_offset = 1
+ if _display_col(cont.indent_str) != target_col + target_offset:
yield (cont.lineno,
'continuation should align to column %d '
- '(under < or ")' % (target_col + 1))
+ '(under < or ")' % (target_col + target_offset + 1))


def check_unclosed_block_comment(ctx):
diff --git a/scripts/dtc/dt-style-selftest/bad/dts-cont-align.dts b/scripts/dtc/dt-style-selftest/bad/dts-cont-align.dts
new file mode 100644
index 000000000000..2087dac23d96
--- /dev/null
+++ b/scripts/dtc/dt-style-selftest/bad/dts-cont-align.dts
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+/dts-v1/;
+
+/ {
+ compatible = "example,test-board";
+ #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>;
+ pinmux = <0x01
+ 0x02>,
+ <0x03
+ 0x04>;
+ power-domain-names = "foo",
+ "bar",
+ "baz";
+ };
+};
diff --git a/scripts/dtc/dt-style-selftest/bad/yaml-cont-align.yaml b/scripts/dtc/dt-style-selftest/bad/yaml-cont-align.yaml
index 92778540b056..d4662acc7b8f 100644
--- a/scripts/dtc/dt-style-selftest/bad/yaml-cont-align.yaml
+++ b/scripts/dtc/dt-style-selftest/bad/yaml-cont-align.yaml
@@ -26,5 +26,7 @@ examples:
foo@1000 {
compatible = "example,test-cont-align";
reg = <0x1000 0x100>,
- <0x2000 0x100>;
+ <0x2000 0x100>,
+ <0x3000
+ 0x100>;
};
diff --git a/scripts/dtc/dt-style-selftest/expected/dts-cont-align.dts.txt b/scripts/dtc/dt-style-selftest/expected/dts-cont-align.dts.txt
new file mode 100644
index 000000000000..4619d44ff98d
--- /dev/null
+++ b/scripts/dtc/dt-style-selftest/expected/dts-cont-align.dts.txt
@@ -0,0 +1,8 @@
+# mode=strict
+bad/dts-cont-align.dts:13: [continuation-alignment] continuation should align to column 30 (under < or ")
+bad/dts-cont-align.dts:14: [continuation-alignment] continuation should align to column 30 (under < or ")
+bad/dts-cont-align.dts:16: [continuation-alignment] continuation should align to column 27 (under < or ")
+bad/dts-cont-align.dts:17: [continuation-alignment] continuation should align to column 26 (under < or ")
+bad/dts-cont-align.dts:18: [continuation-alignment] continuation should align to column 27 (under < or ")
+bad/dts-cont-align.dts:20: [continuation-alignment] continuation should align to column 38 (under < or ")
+bad/dts-cont-align.dts:21: [continuation-alignment] continuation should align to column 38 (under < or ")
diff --git a/scripts/dtc/dt-style-selftest/expected/yaml-cont-align.yaml.txt b/scripts/dtc/dt-style-selftest/expected/yaml-cont-align.yaml.txt
index c0801c56d5db..0047276bd3df 100644
--- a/scripts/dtc/dt-style-selftest/expected/yaml-cont-align.yaml.txt
+++ b/scripts/dtc/dt-style-selftest/expected/yaml-cont-align.yaml.txt
@@ -1,2 +1,3 @@
# mode=strict
bad/yaml-cont-align.yaml:29: example 0 [continuation-alignment] continuation should align to column 11 (under < or ")
+bad/yaml-cont-align.yaml:31: example 0 [continuation-alignment] continuation should align to column 12 (under < or ")
diff --git a/scripts/dtc/dt-style-selftest/expected/yaml-value-ws-multiline.yaml.txt b/scripts/dtc/dt-style-selftest/expected/yaml-value-ws-multiline.yaml.txt
index 3df55b1762d0..dbf0c13ba862 100644
--- a/scripts/dtc/dt-style-selftest/expected/yaml-value-ws-multiline.yaml.txt
+++ b/scripts/dtc/dt-style-selftest/expected/yaml-value-ws-multiline.yaml.txt
@@ -1,2 +1,3 @@
# mode=strict
bad/yaml-value-ws-multiline.yaml:25: example 0 [value-whitespace] extra whitespace inside <...>
+bad/yaml-value-ws-multiline.yaml:26: example 0 [continuation-alignment] continuation should align to column 12 (under < or ")
diff --git a/scripts/dtc/dt-style-selftest/good/dts-cont-align.dts b/scripts/dtc/dt-style-selftest/good/dts-cont-align.dts
index 36fb4eefcd83..1a1c07c09a41 100644
--- a/scripts/dtc/dt-style-selftest/good/dts-cont-align.dts
+++ b/scripts/dtc/dt-style-selftest/good/dts-cont-align.dts
@@ -18,9 +18,12 @@ interrupt-controller@10000 {
interrupts = <1 2 3>,
<4 5 6>,
<7 8 9>;
- pinmux = <
- 0x01
- 0x02
- >;
+ pinmux = <0x01
+ 0x02>,
+ <0x03
+ 0x04>;
+ power-domain-names = "foo",
+ "bar",
+ "baz";
};
};
diff --git a/scripts/dtc/dt-style-selftest/good/yaml-cont-align.yaml b/scripts/dtc/dt-style-selftest/good/yaml-cont-align.yaml
new file mode 100644
index 000000000000..2e7b8582bb7c
--- /dev/null
+++ b/scripts/dtc/dt-style-selftest/good/yaml-cont-align.yaml
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/test-good-cont-align.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Test fixture with aligned multi-line property
+
+maintainers:
+ - Test User <test@xxxxxxxxxxx>
+
+properties:
+ compatible:
+ const: example,test-cont-align
+ reg:
+ maxItems: 2
+
+required:
+ - compatible
+ - reg
+
+additionalProperties: false
+
+examples:
+ - |
+ foo@1000 {
+ compatible = "example,test-cont-align";
+ reg = <0x1000 0x100>,
+ <0x2000 0x100>,
+ <0x3000
+ 0x100>;
+ };

--
2.53.0