diff options
| author | Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com> | 2026-08-26 13:16:01 +0200 |
|---|---|---|
| committer | Rob Herring (Arm) <robh@kernel.org> | 2026-08-31 08:23:18 -0500 |
| commit | ed47943d94f18bb2ca2995936ae8c06f65fa720e (patch) | |
| tree | e01a909b3f499fab096576ea1fbfddbeb16bb245 /scripts | |
| parent | f976e82f64d99c028bb503c4993754d14ea96996 (diff) | |
| download | linux-next-ed47943d94f18bb2ca2995936ae8c06f65fa720e.tar.gz linux-next-ed47943d94f18bb2ca2995936ae8c06f65fa720e.zip | |
dtc: dt-check-style: Add warning for redundant white-spaces
Show warnings of too many spaces around '=', after ':', before '{' and
';' characters, or using tabs for these. Both in-tree DTS and DT
bindings have many warnings for the first case (too mant spaces around
'='), thus keep this one only for 'strict' mode.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Link: https://patch.msgid.link/20260826-n-dts-style-checker-continued-v6-9-f270b1e81f8e@oss.qualcomm.com
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
Diffstat (limited to 'scripts')
13 files changed, 210 insertions, 0 deletions
diff --git a/scripts/dtc/dt-check-style b/scripts/dtc/dt-check-style index 43069fc1fac9..487e76b85105 100755 --- a/scripts/dtc/dt-check-style +++ b/scripts/dtc/dt-check-style @@ -349,6 +349,42 @@ def check_trailing_whitespace(ctx): yield (dl.lineno, 'trailing whitespace') +def _check_redundant_whitespace(dl): + if dl.linetype in (LineType.COMMENT, LineType.COMMENT_BODY, + LineType.COMMENT_END, LineType.COMMENT_START, + LineType.PREPROCESSOR): + return + if re.search(r'(\s\s+|\t)\{', dl.code): + yield (dl.lineno, 'extra whitespace before {') + if re.search(r':(\s\s+|\t)', dl.code): + yield (dl.lineno, 'extra whitespace after :') + if re.search(r'\s+;', dl.code): + yield (dl.lineno, 'extra whitespace before ;') + + +def check_redundant_whitespace(ctx): + """No whitespace between brackets or other code elements. + See also check_value_whitespace() for more checks.""" + for dl in ctx.lines: + yield from _check_redundant_whitespace(dl) + for cont in dl.continuations: + yield from _check_redundant_whitespace(cont) + + +def check_redundant_whitespace_strict(ctx): + """No whitespace between brackets or other code elements. + See also check_value_whitespace() for more checks.""" + for dl in ctx.lines: + if dl.linetype in (LineType.COMMENT, LineType.COMMENT_BODY, + LineType.COMMENT_END, LineType.COMMENT_START, + LineType.PREPROCESSOR): + continue + if re.search(r'(\s\s+|\t)=', dl.code): + yield (dl.lineno, 'extra whitespace before =') + if re.search(r'=(\s\s+|\t)', dl.code): + yield (dl.lineno, 'extra whitespace after =') + + def check_tab_in_yaml_example(ctx): """Reject literal tabs in DTS lines when input is YAML. @@ -1003,6 +1039,10 @@ RULES = [ Rule('trailing-whitespace', 'relaxed', 'no trailing whitespace on any line', check_trailing_whitespace), + # See also check_redundant_whitespace_strict() and check_value_whitespace() + Rule('redundant-whitespace', 'relaxed', + 'no redundant whitespace within code', + check_redundant_whitespace), Rule('tab-in-yaml', 'relaxed', 'YAML (also DTS examples) may not contain tab characters', check_tab_in_yaml_example, applies_to=('yaml',)), @@ -1053,6 +1093,10 @@ RULES = [ Rule('unit-address-format', 'strict', 'unit addresses must be lowercase hex without leading zeros', check_unit_address_format), + # See also check_redundant_whitespace() and check_value_whitespace() + Rule('redundant-whitespace-strict', 'strict', + 'no redundant whitespace within code', + check_redundant_whitespace_strict), Rule('value-whitespace', 'strict', 'no whitespace directly inside <...> brackets', check_value_whitespace), diff --git a/scripts/dtc/dt-style-selftest/bad/dts-redundant-ws-strict.dts b/scripts/dtc/dt-style-selftest/bad/dts-redundant-ws-strict.dts new file mode 100644 index 000000000000..201e3940ba1c --- /dev/null +++ b/scripts/dtc/dt-style-selftest/bad/dts-redundant-ws-strict.dts @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +/dts-v1/; + +#define SOME_MACRO(foo) \ + (foo) ? <1> : <2> ; + +/ { + compatible = "example,test-board"; + #address-cells = <1>; + #size-cells = <1>; + + /* comments { are okay = though ; */ + soc: soc@0 { /* comments { are okay = though ; */ + compatible = "simple-bus"; /* comments { are okay = though ; */ + ranges = <0 0 0 0xc0000000>; + + #address-cells = <1>; + #size-cells = <1>; + } ; +}; /* comments { are okay = though ; */ + +&soc { + serial: serial@20000 { /* comments { are okay = though ; */ + compatible = "example,serial"; + reg = <0x20000 0x1000>; + } ; +}; diff --git a/scripts/dtc/dt-style-selftest/bad/dts-redundant-ws.dts b/scripts/dtc/dt-style-selftest/bad/dts-redundant-ws.dts new file mode 100644 index 000000000000..f6480ddc508a --- /dev/null +++ b/scripts/dtc/dt-style-selftest/bad/dts-redundant-ws.dts @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +/dts-v1/; + +#define SOME_MACRO(foo) \ + (foo) ? <1> : <2> ; + +/ { + compatible = "example,test-board"; + #address-cells = <1>; + #size-cells = <1>; + + /* comments { are okay = though ; */ + soc: soc@0 { /* comments { are okay = though ; */ + compatible = "simple-bus"; /* comments { are okay = though ; */ + ranges = <0 0 0 0xc0000000>; + + #address-cells = <1>; + #size-cells = <1>; + } ; +}; /* comments { are okay = though ; */ + +&soc { + serial: serial@20000 { /* comments { are okay = though ; */ + compatible = "example,serial"; + reg = <0x20000 0x1000>, + <0x30000 0x1000> ; + } ; /* comments { are okay = though ; */ +}; diff --git a/scripts/dtc/dt-style-selftest/bad/dts-redundant-ws.dtso b/scripts/dtc/dt-style-selftest/bad/dts-redundant-ws.dtso new file mode 100644 index 000000000000..01d94e14071a --- /dev/null +++ b/scripts/dtc/dt-style-selftest/bad/dts-redundant-ws.dtso @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +/dts-v1/; +/plugin/; + +&{/} { + compatible = "example,test-board"; + #address-cells = <1>; + #size-cells = <1>; +}; diff --git a/scripts/dtc/dt-style-selftest/bad/yaml-redundant-ws-strict.yaml b/scripts/dtc/dt-style-selftest/bad/yaml-redundant-ws-strict.yaml new file mode 100644 index 000000000000..739c44fd7217 --- /dev/null +++ b/scripts/dtc/dt-style-selftest/bad/yaml-redundant-ws-strict.yaml @@ -0,0 +1,31 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/yaml-redundant-ws-strict.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Test fixture with redundant whitespace + +maintainers: + - Rob Herring <robh@kernel.org> + +properties: + compatible: + const: example,test-redundant + reg: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + device@1000 { + compatible = "example,test-trailing"; + reg = <0x1000 0x100>; + clocks = <&clk 0>; /* comments { are okay = though ; */ + clock-names = "bus"; /* comments { are okay = though ; */ + } ; diff --git a/scripts/dtc/dt-style-selftest/bad/yaml-redundant-ws.yaml b/scripts/dtc/dt-style-selftest/bad/yaml-redundant-ws.yaml new file mode 100644 index 000000000000..b2f51969b0ff --- /dev/null +++ b/scripts/dtc/dt-style-selftest/bad/yaml-redundant-ws.yaml @@ -0,0 +1,35 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/yaml-redundant-ws.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Test fixture with redundant whitespace + +maintainers: + - Rob Herring <robh@kernel.org> + +properties: + compatible: + const: example,test-redundant + reg: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + device@1000 { /* comments { are okay = though ; */ + compatible = "example,test-trailing"; + reg = <0x1000 0x100>, + <0x3000 0x100> ; + } ; + + device@2000 { /* comments { are okay = though ; */ + compatible = "example,test-trailing"; + reg = <0x2000 0x100>; + }; /* comments { are okay = though ; */ diff --git a/scripts/dtc/dt-style-selftest/expected/dts-property-order.dts.txt b/scripts/dtc/dt-style-selftest/expected/dts-property-order.dts.txt index aab048a0ba3b..0ab832ccf07a 100644 --- a/scripts/dtc/dt-style-selftest/expected/dts-property-order.dts.txt +++ b/scripts/dtc/dt-style-selftest/expected/dts-property-order.dts.txt @@ -6,5 +6,6 @@ bad/dts-property-order.dts:21: [property-order] property 'device_type' out of ca bad/dts-property-order.dts:30: [property-order] property 'dma-coherent' out of canonical order (should sort before 'status') bad/dts-property-order.dts:35: [property-order] property 'compatible' out of canonical order (should sort before 'ranges') bad/dts-property-order.dts:45: [property-order] property 'compatible' out of canonical order (should sort before 'interrupts') +bad/dts-property-order.dts:50: [redundant-whitespace] extra whitespace before { bad/dts-property-order.dts:52: [property-order] property 'model' out of canonical order (should sort before 'compatible') bad/dts-property-order.dts:57: [property-order] property 'model' out of canonical order (should sort before 'compatible') diff --git a/scripts/dtc/dt-style-selftest/expected/dts-property-order.dtso.txt b/scripts/dtc/dt-style-selftest/expected/dts-property-order.dtso.txt index e9b3ac985718..9f2a00916329 100644 --- a/scripts/dtc/dt-style-selftest/expected/dts-property-order.dtso.txt +++ b/scripts/dtc/dt-style-selftest/expected/dts-property-order.dtso.txt @@ -6,5 +6,6 @@ bad/dts-property-order.dtso:22: [property-order] property 'device_type' out of c bad/dts-property-order.dtso:31: [property-order] property 'dma-coherent' out of canonical order (should sort before 'status') bad/dts-property-order.dtso:36: [property-order] property 'compatible' out of canonical order (should sort before 'ranges') bad/dts-property-order.dtso:46: [property-order] property 'compatible' out of canonical order (should sort before 'interrupts') +bad/dts-property-order.dtso:51: [redundant-whitespace] extra whitespace before { bad/dts-property-order.dtso:53: [property-order] property 'model' out of canonical order (should sort before 'compatible') bad/dts-property-order.dtso:58: [property-order] property 'model' out of canonical order (should sort before 'compatible') diff --git a/scripts/dtc/dt-style-selftest/expected/dts-redundant-ws-strict.dts.txt b/scripts/dtc/dt-style-selftest/expected/dts-redundant-ws-strict.dts.txt new file mode 100644 index 000000000000..ac0d57bdecdf --- /dev/null +++ b/scripts/dtc/dt-style-selftest/expected/dts-redundant-ws-strict.dts.txt @@ -0,0 +1,13 @@ +# mode=strict +bad/dts-redundant-ws-strict.dts:7: [redundant-whitespace] extra whitespace before { +bad/dts-redundant-ws-strict.dts:13: [redundant-whitespace] extra whitespace before { +bad/dts-redundant-ws-strict.dts:13: [redundant-whitespace] extra whitespace after : +bad/dts-redundant-ws-strict.dts:17: [redundant-whitespace-strict] extra whitespace before = +bad/dts-redundant-ws-strict.dts:18: [redundant-whitespace-strict] extra whitespace after = +bad/dts-redundant-ws-strict.dts:19: [redundant-whitespace] extra whitespace before ; +bad/dts-redundant-ws-strict.dts:22: [redundant-whitespace] extra whitespace before { +bad/dts-redundant-ws-strict.dts:23: [redundant-whitespace] extra whitespace before { +bad/dts-redundant-ws-strict.dts:23: [redundant-whitespace] extra whitespace after : +bad/dts-redundant-ws-strict.dts:24: [redundant-whitespace-strict] extra whitespace before = +bad/dts-redundant-ws-strict.dts:25: [redundant-whitespace-strict] extra whitespace after = +bad/dts-redundant-ws-strict.dts:26: [redundant-whitespace] extra whitespace before ; diff --git a/scripts/dtc/dt-style-selftest/expected/dts-redundant-ws.dts.txt b/scripts/dtc/dt-style-selftest/expected/dts-redundant-ws.dts.txt new file mode 100644 index 000000000000..3b2a989045ed --- /dev/null +++ b/scripts/dtc/dt-style-selftest/expected/dts-redundant-ws.dts.txt @@ -0,0 +1,10 @@ +# mode=relaxed +bad/dts-redundant-ws.dts:7: [redundant-whitespace] extra whitespace before { +bad/dts-redundant-ws.dts:13: [redundant-whitespace] extra whitespace before { +bad/dts-redundant-ws.dts:13: [redundant-whitespace] extra whitespace after : +bad/dts-redundant-ws.dts:19: [redundant-whitespace] extra whitespace before ; +bad/dts-redundant-ws.dts:22: [redundant-whitespace] extra whitespace before { +bad/dts-redundant-ws.dts:23: [redundant-whitespace] extra whitespace before { +bad/dts-redundant-ws.dts:23: [redundant-whitespace] extra whitespace after : +bad/dts-redundant-ws.dts:26: [redundant-whitespace] extra whitespace before ; +bad/dts-redundant-ws.dts:27: [redundant-whitespace] extra whitespace before ; diff --git a/scripts/dtc/dt-style-selftest/expected/dts-redundant-ws.dtso.txt b/scripts/dtc/dt-style-selftest/expected/dts-redundant-ws.dtso.txt new file mode 100644 index 000000000000..5f9a63061709 --- /dev/null +++ b/scripts/dtc/dt-style-selftest/expected/dts-redundant-ws.dtso.txt @@ -0,0 +1,2 @@ +# mode=strict +bad/dts-redundant-ws.dtso:5: [redundant-whitespace] extra whitespace before { diff --git a/scripts/dtc/dt-style-selftest/expected/yaml-redundant-ws-strict.yaml.txt b/scripts/dtc/dt-style-selftest/expected/yaml-redundant-ws-strict.yaml.txt new file mode 100644 index 000000000000..fbf323832c91 --- /dev/null +++ b/scripts/dtc/dt-style-selftest/expected/yaml-redundant-ws-strict.yaml.txt @@ -0,0 +1,5 @@ +# mode=strict +bad/yaml-redundant-ws-strict.yaml:26: example 0 [redundant-whitespace] extra whitespace before { +bad/yaml-redundant-ws-strict.yaml:27: example 0 [redundant-whitespace-strict] extra whitespace before = +bad/yaml-redundant-ws-strict.yaml:28: example 0 [redundant-whitespace-strict] extra whitespace after = +bad/yaml-redundant-ws-strict.yaml:31: example 0 [redundant-whitespace] extra whitespace before ; diff --git a/scripts/dtc/dt-style-selftest/expected/yaml-redundant-ws.yaml.txt b/scripts/dtc/dt-style-selftest/expected/yaml-redundant-ws.yaml.txt new file mode 100644 index 000000000000..a162967e4336 --- /dev/null +++ b/scripts/dtc/dt-style-selftest/expected/yaml-redundant-ws.yaml.txt @@ -0,0 +1,4 @@ +# mode=relaxed +bad/yaml-redundant-ws.yaml:26: example 0 [redundant-whitespace] extra whitespace before { +bad/yaml-redundant-ws.yaml:29: example 0 [redundant-whitespace] extra whitespace before ; +bad/yaml-redundant-ws.yaml:30: example 0 [redundant-whitespace] extra whitespace before ; |
