[PATCH v2 2/2] dtc: dt-check-style: Allow space-aligning indentation in DTS
From: Krzysztof Kozlowski
Date: Mon Jul 06 2026 - 06:51:33 EST
DTS often have spaces after tabs in indentation for aligning continued
lines of comments or list properties, thus allow such cases to avoid
many false positives. What we can easily detect is a space followed by
tab or too many spaces (more than alignment).
OTOH, DTS example in YAML files does not have tabs at all and there is
already rule for that, thus there is no point to check for mixed
indentation there.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@xxxxxxxxxxxxxxxx>
---
Changes in v2:
1. Rework idea.
2. Adjust function doc/comment.
v1: https://lore.kernel.org/all/20260706071446.87669-2-krzysztof.kozlowski@xxxxxxxxxxxxxxxx/
---
scripts/dtc/dt-check-style | 9 ++++++---
.../expected/yaml-mixed-indent.yaml.txt | 1 -
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/scripts/dtc/dt-check-style b/scripts/dtc/dt-check-style
index 34e0f7e2a57a..e49b7446a2f7 100755
--- a/scripts/dtc/dt-check-style
+++ b/scripts/dtc/dt-check-style
@@ -359,14 +359,17 @@ def check_tab_in_yaml_example(ctx):
def check_mixed_indent_chars(ctx):
- """Indent must be all-spaces or all-tabs, never mixed on one line."""
+ """Indent must be all-tabs, except for aligning indentation (comments
+ or continued lines)."""
for dl in ctx.lines:
if not dl.indent_str:
continue
if dl.linetype == LineType.PREPROCESSOR:
continue
- if ' ' in dl.indent_str and '\t' in dl.indent_str:
+ if re.match(r' \t', dl.indent_str):
yield (dl.lineno, 'mixed tabs and spaces in indent')
+ if dl.indent_str.count(' ') > 7:
+ yield (dl.lineno, 'too many space characters in indent (more than 7)')
def detect_indent_unit(ctx):
@@ -932,7 +935,7 @@ RULES = [
check_tab_in_yaml_example, applies_to=('yaml',)),
Rule('mixed-indent-chars', 'relaxed',
'indent must not mix tabs and spaces',
- check_mixed_indent_chars),
+ check_mixed_indent_chars, applies_to=('dts', 'dtsi', 'dtso')),
Rule('unclosed-block-comment', 'relaxed',
'every /* block comment must close with */',
check_unclosed_block_comment),
diff --git a/scripts/dtc/dt-style-selftest/expected/yaml-mixed-indent.yaml.txt b/scripts/dtc/dt-style-selftest/expected/yaml-mixed-indent.yaml.txt
index c989f8f19853..0089c62963f5 100644
--- a/scripts/dtc/dt-style-selftest/expected/yaml-mixed-indent.yaml.txt
+++ b/scripts/dtc/dt-style-selftest/expected/yaml-mixed-indent.yaml.txt
@@ -1,3 +1,2 @@
# mode=relaxed
-bad/yaml-mixed-indent.yaml:27: example 0 [mixed-indent-chars] mixed tabs and spaces in indent
bad/yaml-mixed-indent.yaml:27: example 0 [tab-in-dts] tab character not allowed in DTS example
--
2.53.0