[PATCH v2 10/11] dtc: dt-check-style: Add warning for redundant white-spaces
From: Krzysztof Kozlowski
Date: Sun Aug 02 2026 - 04:51:03 EST
Show warnings of too many spaces around '=', 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@xxxxxxxxxxxxxxxx>
---
scripts/dtc/dt-check-style | 38 ++++++++++++++++++++++
.../bad/dts-redundant-ws-strict.dts | 27 +++++++++++++++
.../dtc/dt-style-selftest/bad/dts-redundant-ws.dts | 27 +++++++++++++++
.../bad/yaml-redundant-ws-strict.yaml | 29 +++++++++++++++++
.../dt-style-selftest/bad/yaml-redundant-ws.yaml | 29 +++++++++++++++++
.../expected/dts-redundant-ws-strict.dts.txt | 13 ++++++++
.../expected/dts-redundant-ws.dts.txt | 9 +++++
.../expected/yaml-redundant-ws-strict.yaml.txt | 5 +++
.../expected/yaml-redundant-ws.yaml.txt | 3 ++
9 files changed, 180 insertions(+)
diff --git a/scripts/dtc/dt-check-style b/scripts/dtc/dt-check-style
index 56d8d0c217f2..6512cf5cfdde 100755
--- a/scripts/dtc/dt-check-style
+++ b/scripts/dtc/dt-check-style
@@ -348,6 +348,36 @@ def check_trailing_whitespace(ctx):
yield (dl.lineno, 'trailing whitespace')
+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:
+ 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.raw):
+ yield (dl.lineno, 'extra whitespace before {')
+ if re.search(r':(\s\s+|\t)', dl.raw):
+ yield (dl.lineno, 'extra whitespace after :')
+ if re.search(r'\s+;', dl.raw):
+ yield (dl.lineno, 'extra whitespace before ;')
+
+
+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.raw):
+ yield (dl.lineno, 'extra whitespace before =')
+ if re.search(r'=(\s\s+|\t)', dl.raw):
+ yield (dl.lineno, 'extra whitespace after =')
+
+
def check_tab_in_yaml_example(ctx):
"""Reject literal tabs in DTS lines when input is YAML.
@@ -1002,6 +1032,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',)),
@@ -1052,6 +1086,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..d73908b2ab0f
--- /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 {
+ compatible = "simple-bus";
+ ranges = <0 0 0 0xc0000000>;
+
+ #address-cells = <1>;
+ #size-cells = <1>;
+ } ;
+};
+
+&soc {
+ serial: serial@20000 {
+ 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..2fedf462ca56
--- /dev/null
+++ b/scripts/dtc/dt-style-selftest/bad/dts-redundant-ws.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 {
+ compatible = "simple-bus";
+ ranges = <0 0 0 0xc0000000>;
+
+ #address-cells = <1>;
+ #size-cells = <1>;
+ } ;
+};
+
+&soc {
+ serial: serial@20000 {
+ compatible = "example,serial";
+ reg = <0x20000 0x1000>;
+ } ;
+};
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..14c2346d7658
--- /dev/null
+++ b/scripts/dtc/dt-style-selftest/bad/yaml-redundant-ws-strict.yaml
@@ -0,0 +1,29 @@
+# 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:
+ - Test User <test@xxxxxxxxxxx>
+
+properties:
+ compatible:
+ const: example,test-redundant
+ reg:
+ maxItems: 1
+
+required:
+ - compatible
+ - reg
+
+additionalProperties: false
+
+examples:
+ - |
+ device@1000 {
+ compatible = "example,test-trailing";
+ reg = <0x1000 0x100>;
+ } ;
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..db265402d0e8
--- /dev/null
+++ b/scripts/dtc/dt-style-selftest/bad/yaml-redundant-ws.yaml
@@ -0,0 +1,29 @@
+# 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:
+ - Test User <test@xxxxxxxxxxx>
+
+properties:
+ compatible:
+ const: example,test-redundant
+ reg:
+ maxItems: 1
+
+required:
+ - compatible
+ - reg
+
+additionalProperties: false
+
+examples:
+ - |
+ device@1000 {
+ compatible = "example,test-trailing";
+ reg = <0x1000 0x100>;
+ } ;
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..c18c1972bb47
--- /dev/null
+++ b/scripts/dtc/dt-style-selftest/expected/dts-redundant-ws.dts.txt
@@ -0,0 +1,9 @@
+# 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 ;
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..a70b365b6cf5
--- /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:29: 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..c85e80ed272a
--- /dev/null
+++ b/scripts/dtc/dt-style-selftest/expected/yaml-redundant-ws.yaml.txt
@@ -0,0 +1,3 @@
+# 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 ;
--
2.53.0