[PATCH v3 1/7] dtc: dt-check-style: Handle continued lines in check_hex_case()
From: Krzysztof Kozlowski <hidden>
Date: 2026-09-09 13:10:53
Also in:
lkml
Subsystem:
open firmware and flattened device tree, the rest · Maintainers:
Rob Herring, Saravana Kannan, Linus Torvalds
Continued lines are not separate DtsLine items in ctx.lines, so they need own iteration. Rule for hex case is applicable to continued values as well. Signed-off-by: Krzysztof Kozlowski <redacted> --- scripts/dtc/dt-check-style | 24 ++++++++++++++-------- .../dtc/dt-style-selftest/bad/yaml-hex-case.yaml | 5 ++++- .../expected/yaml-hex-case.yaml.txt | 2 ++ 3 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/scripts/dtc/dt-check-style b/scripts/dtc/dt-check-style
index 15a3ba82fd5f..6d978c4d9832 100755
--- a/scripts/dtc/dt-check-style
+++ b/scripts/dtc/dt-check-style@@ -547,18 +547,24 @@ def check_continuation_alignment(ctx): dl_value_complete = cont.stripped.endswith('",') or cont.stripped.endswith('>,') +def _check_hex_case(dl): + if dl.linetype in (LineType.BLANK, LineType.COMMENT, + LineType.COMMENT_START, LineType.COMMENT_BODY, + LineType.COMMENT_END, LineType.PREPROCESSOR): + return + 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, + 'hex literal %r must be lowercase' % lit) + + def check_hex_case(ctx): """Hex literals (0xN) must use lowercase digits and prefix.""" for dl in ctx.lines: - if dl.linetype in (LineType.BLANK, LineType.COMMENT, - LineType.COMMENT_START, LineType.COMMENT_BODY, - LineType.COMMENT_END, LineType.PREPROCESSOR): - continue - 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, - 'hex literal %r must be lowercase' % lit) + yield from _check_hex_case(dl) + for cont in dl.continuations: + yield from _check_hex_case(cont) def check_indent_consistent(ctx):
diff --git a/scripts/dtc/dt-style-selftest/bad/yaml-hex-case.yaml b/scripts/dtc/dt-style-selftest/bad/yaml-hex-case.yaml
index c55359a4ca68..b0b8683b883a 100644
--- a/scripts/dtc/dt-style-selftest/bad/yaml-hex-case.yaml
+++ b/scripts/dtc/dt-style-selftest/bad/yaml-hex-case.yaml@@ -25,5 +25,8 @@ examples: - | foo@1000 { compatible = "example,test-hex-case"; - reg = <0xABCD 0x100>; + reg = <0xABCD 0x100>, + <0x2BCD 0x100>, + <0x3BCD + 0x100>; };
diff --git a/scripts/dtc/dt-style-selftest/expected/yaml-hex-case.yaml.txt b/scripts/dtc/dt-style-selftest/expected/yaml-hex-case.yaml.txt
index 6600f7cd1ba5..f42490256939 100644
--- a/scripts/dtc/dt-style-selftest/expected/yaml-hex-case.yaml.txt
+++ b/scripts/dtc/dt-style-selftest/expected/yaml-hex-case.yaml.txt@@ -1,2 +1,4 @@ # mode=strict bad/yaml-hex-case.yaml:28: example 0 [hex-case] hex literal '0xABCD' must be lowercase +bad/yaml-hex-case.yaml:29: example 0 [hex-case] hex literal '0x2BCD' must be lowercase +bad/yaml-hex-case.yaml:30: example 0 [hex-case] hex literal '0x3BCD' must be lowercase
--
2.53.0