[PATCH v6 03/10] dtc: dt-check-style: Fix alignment of values in continued property lines
From: Krzysztof Kozlowski <hidden>
Date: 2026-08-26 11:16:18
Also in:
lkml
Subsystem:
open firmware and flattened device tree, the rest · Maintainers:
Rob Herring, Saravana Kannan, Linus Torvalds
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 <redacted>
---
scripts/dtc/dt-check-style | 32 ++++++++++++++--------
.../dtc/dt-style-selftest/bad/dts-cont-align.dts | 26 ++++++++++++++++++
.../dtc/dt-style-selftest/bad/yaml-cont-align.yaml | 6 ++--
.../expected/dts-cont-align.dts.txt | 10 +++++++
.../expected/yaml-cont-align.yaml.txt | 3 +-
.../expected/yaml-value-ws-multiline.yaml.txt | 1 +
.../dtc/dt-style-selftest/good/dts-cont-align.dts | 13 +++++----
.../dt-style-selftest/good/yaml-cont-align.yaml | 32 ++++++++++++++++++++++
8 files changed, 104 insertions(+), 19 deletions(-)
diff --git a/scripts/dtc/dt-check-style b/scripts/dtc/dt-check-style
index 22e1ceac7f8b..eb5045f0ad9e 100755
--- a/scripts/dtc/dt-check-style
+++ b/scripts/dtc/dt-check-style@@ -926,10 +926,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
@@ -938,17 +939,26 @@ def check_continuation_alignment(ctx): eq = dl.raw.find('=') if eq < 0: continue - # First '<' or '"' after '=' - rest = dl.raw[eq + 1:] - m = re.search(r'[<"]', rest) + # First '<' or '"' after '=', but ignore comments and strip trailing + # whitespace (e.g. remaining after removing the comment) + rest = _strip_strings_and_comments(dl.raw[eq + 1:]).rstrip() + m = re.search(r'\s*([<"])', rest) if not m: continue - target_col = _display_col(dl.raw[:eq + 1 + m.start()]) + dl_value_complete = rest.endswith('",') or rest.endswith('>,') + target_col = _display_col(_strip_strings_and_comments(dl.raw[:eq + 1 + m.start(1)])) for cont in dl.continuations: - if _display_col(cont.indent_str) != target_col: + target_offset = 0 + err_msg_explanation = 'to < or "' + if not dl_value_complete: + target_offset = 1 + err_msg_explanation = 'to the value under <' + if _display_col(cont.indent_str) != target_col + target_offset: yield (cont.lineno, 'continuation should align to column %d ' - '(under < or ")' % (target_col + 1)) + '(%s)' % (target_col + target_offset + 1, err_msg_explanation)) + # Align to the value within <> or "" of continuation (so the previous line) + dl_value_complete = cont.stripped.endswith('",') or cont.stripped.endswith('>,') def check_unclosed_block_comment(ctx):
@@ -1052,7 +1062,7 @@ RULES = [ 'lines must not exceed 80 columns', check_line_length), Rule('continuation-alignment', 'strict', - 'multi-line property continuations align under < or "', + 'multi-line property continuations align under <, " or the value under <', check_continuation_alignment), Rule('unused-labels', 'strict', 'every label must be &-referenced in the same example/file '
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..5390ebbf4059
--- /dev/null
+++ b/scripts/dtc/dt-style-selftest/bad/dts-cont-align.dts@@ -0,0 +1,26 @@ +// 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>; + clocks = <1 2 3>, /* comments with " < , should not matter */ + <4 5 6>, + <7 8 9>; + interrupts = <1 2 3>, /* comments with " < , should not ... */ + <4 5 6>, + <7 8 9>; + pinmux = <0x01 + 0x02>, + <0x03 + 0x04>; + power-domain-names = "foo", + "bar", /* comments with " < , should not */ + "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..ccf443173dca 100644
--- a/scripts/dtc/dt-style-selftest/bad/yaml-cont-align.yaml
+++ b/scripts/dtc/dt-style-selftest/bad/yaml-cont-align.yaml@@ -25,6 +25,8 @@ examples: - | foo@1000 { compatible = "example,test-cont-align"; - reg = <0x1000 0x100>, - <0x2000 0x100>; + reg = <0x1000 0x100>, /* comments with " < , should not matter */ + <0x2000 0x100>, /* comments with " < , should not matter */ + <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..a7ed62677a2b
--- /dev/null
+++ b/scripts/dtc/dt-style-selftest/expected/dts-cont-align.dts.txt@@ -0,0 +1,10 @@ +# mode=strict +bad/dts-cont-align.dts:13: [continuation-alignment] continuation should align to column 26 (to < or ") +bad/dts-cont-align.dts:14: [continuation-alignment] continuation should align to column 26 (to < or ") +bad/dts-cont-align.dts:16: [continuation-alignment] continuation should align to column 30 (to < or ") +bad/dts-cont-align.dts:17: [continuation-alignment] continuation should align to column 30 (to < or ") +bad/dts-cont-align.dts:19: [continuation-alignment] continuation should align to column 27 (to the value under <) +bad/dts-cont-align.dts:20: [continuation-alignment] continuation should align to column 26 (to < or ") +bad/dts-cont-align.dts:21: [continuation-alignment] continuation should align to column 27 (to the value under <) +bad/dts-cont-align.dts:23: [continuation-alignment] continuation should align to column 38 (to < or ") +bad/dts-cont-align.dts:24: [continuation-alignment] continuation should align to column 38 (to < 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..eb9a84d5c222 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:29: example 0 [continuation-alignment] continuation should align to column 11 (to < or ") +bad/yaml-cont-align.yaml:31: example 0 [continuation-alignment] continuation should align to column 12 (to the value under <)
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..d25b5b425e3f 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 (to the value under <)
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..b52ee6cccd8c 100644
--- a/scripts/dtc/dt-style-selftest/good/dts-cont-align.dts
+++ b/scripts/dtc/dt-style-selftest/good/dts-cont-align.dts@@ -15,12 +15,15 @@ / { interrupt-controller@10000 { compatible = "example,intc"; reg = <0x10000 0x1000>; - interrupts = <1 2 3>, + interrupts = <1 2 3>, /* comments with " < , should not ... */ <4 5 6>, <7 8 9>; - pinmux = < - 0x01 - 0x02 - >; + pinmux = <0x01 + 0x02>, + <0x03 /* comments with " < , should not matter */ + 0x04>; + power-domain-names = "foo", /* comments with " < , should not */ + "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@example.com> + +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