summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorKrzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>2026-08-03 11:03:05 +0200
committerRob Herring (Arm) <robh@kernel.org>2026-08-14 15:43:24 -0500
commitd863ae623af406dd525ecbcd43780e577e09efad (patch)
tree058a50e0812e9394d4f25672dd35f6d25efe4d11 /scripts
parent2d51fa600462a2126d3cc50911a11428d8b8038e (diff)
downloadlinux-next-d863ae623af406dd525ecbcd43780e577e09efad.tar.gz
linux-next-d863ae623af406dd525ecbcd43780e577e09efad.zip
dtc: dt-check-style: Simplify setting depth of DtsLine
When creating new DtsLine object, pass expected indentation depth as constructor, instead of assigning it immediately after, so the code will be easier to read and explicit (depth is not supposed to change during DtsLine lifetime). Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com> Link: https://patch.msgid.link/20260803-n-dts-style-checker-continued-v3-2-6c9776928cea@oss.qualcomm.com Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/dtc/dt-check-style31
1 files changed, 11 insertions, 20 deletions
diff --git a/scripts/dtc/dt-check-style b/scripts/dtc/dt-check-style
index 3985923622e8..96deffc0d8a7 100755
--- a/scripts/dtc/dt-check-style
+++ b/scripts/dtc/dt-check-style
@@ -82,11 +82,12 @@ class DtsLine:
'node_name', 'node_addr', 'label', 'ref_name', 'depth',
'closures')
- def __init__(self, lineno, raw, linetype, indent_str, stripped):
+ def __init__(self, lineno, raw, linetype, depth, indent_str, stripped):
self.lineno = lineno # 1-based within the block
self.raw = raw
self.linetype = linetype
self.indent_str = indent_str # leading whitespace as-is
+ self.depth = depth
self.stripped = stripped
self.prop_name = None
self.continuations = []
@@ -94,7 +95,6 @@ class DtsLine:
self.node_addr = None
self.label = None
self.ref_name = None
- self.depth = 0 # filled in by classify_lines
self.closures = 1 # count of '}' on a NODE_CLOSE line
@@ -162,16 +162,14 @@ def classify_lines(text):
# or a blank line).
if in_cpp_macro:
dl = DtsLine(i, raw, LineType.PREPROCESSOR,
- indent_str, stripped)
- dl.depth = depth
+ depth, indent_str, stripped)
out.append(dl)
in_cpp_macro = (bool(stripped) and
stripped.rstrip().endswith('\\'))
continue
if not stripped:
- dl = DtsLine(i, raw, LineType.BLANK, '', '')
- dl.depth = depth
+ dl = DtsLine(i, raw, LineType.BLANK, depth, '', '')
out.append(dl)
continue
@@ -180,15 +178,13 @@ def classify_lines(text):
else LineType.COMMENT_BODY)
if ltype == LineType.COMMENT_END:
in_block_comment = False
- dl = DtsLine(i, raw, ltype, indent_str, stripped)
- dl.depth = depth
+ dl = DtsLine(i, raw, ltype, depth, indent_str, stripped)
out.append(dl)
continue
if (stripped.startswith('#') or stripped.startswith('/')) and is_preprocessor(stripped):
- dl = DtsLine(i, raw, LineType.PREPROCESSOR,
+ dl = DtsLine(i, raw, LineType.PREPROCESSOR, depth,
indent_str, stripped)
- dl.depth = depth
out.append(dl)
prev_complete = True
in_cpp_macro = stripped.rstrip().endswith('\\')
@@ -205,14 +201,12 @@ def classify_lines(text):
# structural classification entirely.
if not code:
ltype = LineType.COMMENT_START if opens_block else LineType.COMMENT
- dl = DtsLine(i, raw, ltype, indent_str, stripped)
- dl.depth = depth
+ dl = DtsLine(i, raw, ltype, depth, indent_str, stripped)
out.append(dl)
continue
if not prev_complete:
- dl = DtsLine(i, raw, LineType.CONTINUATION, indent_str, code)
- dl.depth = depth
+ dl = DtsLine(i, raw, LineType.CONTINUATION, depth, indent_str, code)
out.append(dl)
prev_complete = (code.endswith(';') or
code.endswith('{') or
@@ -227,26 +221,23 @@ def classify_lines(text):
if re_only_closures.match(code):
closures = code.count('}')
depth = max(depth - closures, 0)
- dl = DtsLine(i, raw, LineType.NODE_CLOSE, indent_str, code)
- dl.depth = depth
+ dl = DtsLine(i, raw, LineType.NODE_CLOSE, depth, indent_str, code)
dl.closures = closures
out.append(dl)
prev_complete = True
continue
if code.endswith('{'):
- dl = DtsLine(i, raw, LineType.NODE_OPEN, indent_str, code)
+ dl = DtsLine(i, raw, LineType.NODE_OPEN, depth, indent_str, code)
parse_node_header(dl)
- dl.depth = depth
out.append(dl)
depth += 1
prev_complete = True
continue
# Property (or first line of a multi-line property).
- dl = DtsLine(i, raw, LineType.PROPERTY, indent_str, code)
+ dl = DtsLine(i, raw, LineType.PROPERTY, depth, indent_str, code)
parse_property_name(dl)
- dl.depth = depth
out.append(dl)
prev_complete = code.endswith(';')