[PATCH v3 4/7] dtc: dt-check-style: Unduplicate checks in check_mixed_indent_chars()
From: Krzysztof Kozlowski
Date: Wed Sep 09 2026 - 10:28:56 EST
Code checking each DtsLine and continuations is the same, so split it to
separate function to avoid duplicated code. This has a positive side
effect - if DtsLine did not have indentation, then check continued to
next one, but now it will still go through the continued lines in the
second loop.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@xxxxxxxxxxxxxxxx>
---
scripts/dtc/dt-check-style | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/scripts/dtc/dt-check-style b/scripts/dtc/dt-check-style
index 3694b0b1ebb6..2ff9fdc50367 100755
--- a/scripts/dtc/dt-check-style
+++ b/scripts/dtc/dt-check-style
@@ -645,27 +645,24 @@ def check_line_length(ctx):
yield from _check_line_length(cont)
+def _check_mixed_indent_chars(dl):
+ if not dl.indent_str:
+ return
+ if dl.linetype == LineType.PREPROCESSOR:
+ return
+ 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)')
+
+
def check_mixed_indent_chars(ctx):
"""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 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)')
+ yield from _check_mixed_indent_chars(dl)
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')
- if cont.indent_str.count(' ') > 7:
- yield (cont.lineno, 'too many space characters in indent (more than 7)')
+ yield from _check_mixed_indent_chars(cont)
def check_node_close_alone(ctx):
--
2.53.0