[PATCH v6 07/10] dtc: dt-check-style: Call _strip_strings_and_comments() only once
From: Krzysztof Kozlowski <hidden>
Date: 2026-08-26 11:16:23
Also in:
lkml
Subsystem:
open firmware and flattened device tree, the rest · Maintainers:
Rob Herring, Saravana Kannan, Linus Torvalds
More than one rule evaluates pure code - stripped from comments and indentation - thus store this pure code in DtsLine class for better performance. Signed-off-by: Krzysztof Kozlowski <redacted> --- scripts/dtc/dt-check-style | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/scripts/dtc/dt-check-style b/scripts/dtc/dt-check-style
index b71e6bf815a7..43069fc1fac9 100755
--- a/scripts/dtc/dt-check-style
+++ b/scripts/dtc/dt-check-style@@ -79,18 +79,19 @@ def is_preprocessor(stripped): class DtsLine: - __slots__ = ('lineno', 'raw', 'linetype', 'indent_str', 'stripped', 'is_root', + __slots__ = ('lineno', 'raw', 'code', 'linetype', 'indent_str', 'stripped', 'is_root', 'prop_name', 'continuations', 'node_name', 'node_addr', 'label', 'ref_name', 'parent', 'depth', 'closures') def __init__(self, lineno, raw, linetype, depth, indent_str, stripped, is_root = False): self.lineno = lineno # 1-based within the block - self.raw = raw + self.raw = raw # Entire raw line self.linetype = linetype self.indent_str = indent_str # leading whitespace as-is self.depth = depth - self.stripped = stripped + self.stripped = stripped # Code without indentation + self.code = _strip_strings_and_comments(stripped) # Only the code, skipping trailing comments self.is_root = is_root self.prop_name = None self.continuations = []
@@ -811,8 +812,7 @@ def check_hex_case(ctx): LineType.COMMENT_START, LineType.COMMENT_BODY, LineType.COMMENT_END, LineType.PREPROCESSOR): continue - text = _strip_strings_and_comments(dl.raw) - for m in re.finditer(r'\b0[xX][0-9a-fA-F]+\b', text): + for m in re.finditer(r'\b0[xX][0-9a-fA-F]+\b', dl.code): lit = m.group(0) if any(c.isupper() for c in lit[2:]) or lit[1] == 'X': yield (dl.lineno,
@@ -860,9 +860,9 @@ def check_value_whitespace(ctx): for dl in ctx.lines: if dl.linetype != LineType.PROPERTY: continue - segs = [_strip_strings_and_comments(dl.raw).strip()] + segs = [dl.code.strip()] for cont in dl.continuations: - segs.append(_strip_strings_and_comments(cont.stripped).strip()) + segs.append(cont.code.strip()) text = '' for s in segs: if not s:
@@ -895,8 +895,7 @@ def check_node_close_alone(ctx): LineType.COMMENT_START, LineType.COMMENT_BODY, LineType.COMMENT_END, LineType.PREPROCESSOR): continue - text = _strip_strings_and_comments(dl.raw) - if '};' in text: + if '};' in dl.code: yield (dl.lineno, 'closing brace must be on its own line')
--
2.53.0