dtc: dt-check-style: Allow space-aligning indentation in DTS

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@oss.qualcomm.com>
Link: https://patch.msgid.link/20260709-dts-style-checker-v5-2-fcc147cb697d@oss.qualcomm.com
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
This commit is contained in:
Krzysztof Kozlowski
2026-07-09 19:41:30 +02:00
committed by Rob Herring (Arm)
parent 49b5cf461d
commit 32541ce0ae
4 changed files with 43 additions and 4 deletions

View File

@@ -359,14 +359,24 @@ 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.search(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)')
for cont in dl.continuations:
if not cont.indent_str:
continue
if cont.linetype == LineType.PREPROCESSOR:
continue
if re.search(r' \t', cont.indent_str):
yield (cont.lineno, 'mixed tabs and spaces in indent')
def detect_indent_unit(ctx):
@@ -932,7 +942,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),

View File

@@ -0,0 +1,21 @@
// SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
/* Test fixture: a .dts using wrong indent. */
/dts-v1/;
/ {
compatible = "example,test-board";
#address-cells = <1>;
#size-cells = <1>;
soc@0 {
compatible = "simple-bus";
ranges = <0 0 0 0xc0000000>;
clocks = <1>,
<2>,
<3>,
<4>;
resets = <5>;
};
};

View File

@@ -0,0 +1,9 @@
# mode=strict
bad/dts-mixed-indent.dts:11: [indent-consistent] indent mismatch (expected depth 1 * '\t')
bad/dts-mixed-indent.dts:11: [mixed-indent-chars] too many space characters in indent (more than 7)
bad/dts-mixed-indent.dts:12: [indent-consistent] indent mismatch (expected depth 2 * '\t')
bad/dts-mixed-indent.dts:12: [mixed-indent-chars] mixed tabs and spaces in indent
bad/dts-mixed-indent.dts:13: [indent-consistent] indent mismatch (expected depth 2 * '\t')
bad/dts-mixed-indent.dts:13: [mixed-indent-chars] mixed tabs and spaces in indent
bad/dts-mixed-indent.dts:16: [mixed-indent-chars] mixed tabs and spaces in indent
bad/dts-mixed-indent.dts:19: [indent-consistent] indent mismatch (expected depth 2 * '\t')

View File

@@ -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-yaml] tab character not allowed in DTS example