summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorKrzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>2026-07-09 19:41:31 +0200
committerRob Herring (Arm) <robh@kernel.org>2026-07-20 15:50:56 -0500
commit46fb56e45526c35b7f9b0e79104a4a5140d00f44 (patch)
tree7f3bf335b6678395a667e4691b338bf18273d3a8 /scripts
parent32541ce0ae38e65c901fdf9814ae00034d77db35 (diff)
downloadlinux-46fb56e45526c35b7f9b0e79104a4a5140d00f44.tar.gz
linux-46fb56e45526c35b7f9b0e79104a4a5140d00f44.zip
dtc: dt-check-style: Rework handling YAML/DTS in rules
Individual rules behave differently depending whether they handle bindings (YAML) or DTS, but the code was focusing on type of indentation (spaces vs tabs). That indentation is actually irrelevant in some rules, so differentiate based on file type. This will be more relevant in the future when more rules act differently on DTS, than on bindings. Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com> Link: https://patch.msgid.link/20260709-dts-style-checker-v5-3-fcc147cb697d@oss.qualcomm.com Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/dtc/dt-check-style23
1 files changed, 12 insertions, 11 deletions
diff --git a/scripts/dtc/dt-check-style b/scripts/dtc/dt-check-style
index e715fb1e741c..f5276b5fdd46 100755
--- a/scripts/dtc/dt-check-style
+++ b/scripts/dtc/dt-check-style
@@ -311,13 +311,16 @@ def collect_labels_and_refs(text):
class Ctx:
"""Context passed to each rule check. Carries the parsed lines,
- raw text, mode, and indent kind."""
+ raw text, mode and kind."""
- def __init__(self, lines, text, mode, indent_kind):
+ def __init__(self, lines, text, mode, kind):
self.lines = lines
self.text = text
self.mode = mode # 'relaxed' or 'strict'
- self.indent_kind = indent_kind # 'spaces' or 'tab'
+ if kind in DTS_FAMILY:
+ self.file_type = 'dts'
+ else:
+ self.file_type = 'yaml'
class Rule:
@@ -347,7 +350,7 @@ def check_tab_in_yaml_example(ctx):
a #define value are tolerated (those are CPP macros, not DTS).
For .dts files, this rule does not apply -- tabs are required.
"""
- if ctx.indent_kind != 'spaces':
+ if ctx.file_type != 'yaml':
return
for dl in ctx.lines:
if dl.linetype == LineType.PREPROCESSOR:
@@ -427,7 +430,7 @@ def check_indent_unit_strict(ctx):
unit = detect_indent_unit(ctx)
if unit is None:
return
- if ctx.indent_kind == 'spaces':
+ if ctx.file_type == 'yaml':
if unit != ' ':
yield (1, 'indent unit must be 4 spaces in strict mode, '
'got %r' % unit)
@@ -438,7 +441,7 @@ def check_indent_consistent(ctx):
unit = detect_indent_unit(ctx)
if unit is None:
return
- if ctx.indent_kind == 'spaces':
+ if ctx.file_type == 'yaml':
if unit not in (' ', ' '):
return # let check_indent_unit_* report this
else:
@@ -1023,11 +1026,11 @@ def select_rules(mode, input_kind):
# Block runner
# ---------------------------------------------------------------------------
-def check_block(text, mode, indent_kind, input_type):
+def check_block(text, mode, input_type):
"""Run all selected rules on a single block of DTS text. Returns a
list of (lineno, rule_name, message) tuples."""
lines = classify_lines(text)
- ctx = Ctx(lines, text, mode, indent_kind)
+ ctx = Ctx(lines, text, mode, input_type)
rules = select_rules(mode, input_type)
findings = []
for r in rules:
@@ -1107,17 +1110,15 @@ def collect_findings(filepath, mode):
formatted output strings; count is the number of findings."""
kind = input_kind(filepath)
if kind == 'yaml':
- indent_kind = 'spaces'
iterator = iter_yaml_examples(filepath)
elif kind in DTS_FAMILY:
- indent_kind = 'tab'
iterator = iter_dts_file(filepath)
else:
return (['%s: unknown file type, skipping' % filepath], 0)
out = []
for text, base, idx in iterator:
- for lineno, rule, msg in check_block(text, mode, indent_kind, kind):
+ for lineno, rule, msg in check_block(text, mode, kind):
abs_line = base + lineno - 1
ex_tag = '' if idx is None else ' example %d' % idx
out.append('%s:%d:%s [%s] %s' %