Thread (15 messages) 15 messages, 2 authors, 2d ago
WARM2d
Revisions (3)
  1. v3 current
  2. v4 [diff vs current]
  3. v5 [diff vs current]

[PATCH v3 4/6] dtc: dt-check-style: Expect first device_type

From: Krzysztof Kozlowski <hidden>
Date: 2026-07-06 15:54:01
Also in: lkml
Subsystem: open firmware and flattened device tree, open firmware and flattened device tree bindings, the rest · Maintainers: Rob Herring, Saravana Kannan, Krzysztof Kozlowski, Conor Dooley, Linus Torvalds

A few nodes do have "device_type" property which is mostly, but not always,
the first property in a device node, when applicable.  Adjust the DTS
coding style rules to actually expect the device_type first and improve
the dt-check-style to handle this correctly.

Signed-off-by: Krzysztof Kozlowski <redacted>

---

Changes in v3:
New patch
---
 .../devicetree/bindings/dts-coding-style.rst       | 15 ++++-----
 scripts/dtc/dt-check-style                         | 29 +++++++++--------
 .../dt-style-selftest/bad/dts-property-order.dts   | 36 ++++++++++++++++++++++
 .../bad/yaml-prop-order-device-type.yaml           | 31 +++++++++++++++++++
 .../expected/dts-property-order.dts.txt            |  5 +++
 .../expected/yaml-prop-order-device-type.yaml.txt  |  2 ++
 6 files changed, 98 insertions(+), 20 deletions(-)
diff --git a/Documentation/devicetree/bindings/dts-coding-style.rst b/Documentation/devicetree/bindings/dts-coding-style.rst
index 4a02ea60cbbe..63648db377e1 100644
--- a/Documentation/devicetree/bindings/dts-coding-style.rst
+++ b/Documentation/devicetree/bindings/dts-coding-style.rst
@@ -114,15 +114,16 @@ Order of Properties in Device Node
 
 The following order of properties in device nodes is preferred:
 
-1. "compatible"
-2. "reg"
-3. "ranges"
-4. Standard/common properties (defined by common bindings, e.g. without
+1. "device_type" (if applicable)
+2. "compatible"
+3. "reg"
+4. "ranges"
+5. Standard/common properties (defined by common bindings, e.g. without
    vendor-prefixes)
-5. Vendor-specific properties
-6. "status" (if applicable), preceded by a blank line if there is content
+6. Vendor-specific properties
+7. "status" (if applicable), preceded by a blank line if there is content
    before the property
-7. Child nodes, where each node is preceded with a blank line
+8. Child nodes, where each node is preceded with a blank line
 
 The "status" property is by default "okay", thus it can be omitted.
 
diff --git a/scripts/dtc/dt-check-style b/scripts/dtc/dt-check-style
index cf61e92d0568..d9080297bd4d 100755
--- a/scripts/dtc/dt-check-style
+++ b/scripts/dtc/dt-check-style
@@ -558,28 +558,31 @@ def check_child_name_order(ctx):
 
 def _property_bucket(name):
     """Return the canonical bucket index for a property:
-       0 compatible
-       1 reg / reg-names
-       2 ranges
-       3 standard properties (no vendor comma in #-stripped name)
-       4 vendor-specific properties
-       5 status
+       0 device_type
+       1 compatible
+       2 reg / reg-names
+       3 ranges
+       4 standard properties (no vendor comma in #-stripped name)
+       5 vendor-specific properties
+       6 status
     Plus a sub-key inside the bucket for fixed slots (compatible, reg,
     reg-names, ranges, status). 'standard' and 'vendor' return None for
     the sub-key, signalling that the within-bucket key is computed by
     the pairing rules."""
     stripped = name.lstrip('#')
-    if name == 'compatible':
+    if name == 'device_type':
         return (0, 0)
-    if name == 'reg':
+    if name == 'compatible':
         return (1, 0)
-    if name == 'reg-names':
-        return (1, 1)
-    if name == 'ranges':
+    if name == 'reg':
         return (2, 0)
+    if name == 'reg-names':
+        return (2, 1)
+    if name == 'ranges':
+        return (3, 0)
     if name == 'status':
-        return (5, 0)
-    return (4 if ',' in stripped else 3, None)
+        return (6, 0)
+    return (5 if ',' in stripped else 4, None)
 
 
 # Declarative pairing rules: each is a callable
diff --git a/scripts/dtc/dt-style-selftest/bad/dts-property-order.dts b/scripts/dtc/dt-style-selftest/bad/dts-property-order.dts
new file mode 100644
index 000000000000..9e55d683a071
--- /dev/null
+++ b/scripts/dtc/dt-style-selftest/bad/dts-property-order.dts
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+/*
+ * Test fixture: Incorrect property order
+ */
+
+/dts-v1/;
+
+/ {
+	memory@a0000000 {
+		reg = <0x0 0xa0000000 0x0 0x0>;
+		device_type = "memory";
+	};
+
+	pmu {
+		compatible = "example,pmu";
+
+		status = "disabled";
+		dma-coherent;
+	};
+
+	soc@0 {
+		ranges = <0 0 0 0xc0000000>;
+		compatible = "simple-bus";
+
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		interrupt-controller@10000 {
+			reg = <0x10000 0x1000>;
+			interrupts = <1 2 3>,
+				     <4 5 6>,
+				     <7 8 9>;
+			compatible = "example,intc";
+		};
+	};
+};
diff --git a/scripts/dtc/dt-style-selftest/bad/yaml-prop-order-device-type.yaml b/scripts/dtc/dt-style-selftest/bad/yaml-prop-order-device-type.yaml
new file mode 100644
index 000000000000..433afb731dde
--- /dev/null
+++ b/scripts/dtc/dt-style-selftest/bad/yaml-prop-order-device-type.yaml
@@ -0,0 +1,31 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/test-bad-prop-order.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Test fixture with device_type
+
+maintainers:
+  - Test User <test@example.com>
+
+properties:
+  compatible:
+    const: example,test-prop-order-device-type
+  reg:
+    maxItems: 1
+  device_type: true
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    device@1000 {
+        compatible = "example,test-prop-order";
+        device_type = "cpu";
+        reg = <0x1000 0x100>;
+    };
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
new file mode 100644
index 000000000000..7b1a6bae3741
--- /dev/null
+++ b/scripts/dtc/dt-style-selftest/expected/dts-property-order.dts.txt
@@ -0,0 +1,5 @@
+# mode=strict
+bad/dts-property-order.dts:11: [property-order] property 'device_type' out of canonical order (should sort before 'reg')
+bad/dts-property-order.dts:18: [property-order] property 'dma-coherent' out of canonical order (should sort before 'status')
+bad/dts-property-order.dts:23: [property-order] property 'compatible' out of canonical order (should sort before 'ranges')
+bad/dts-property-order.dts:33: [property-order] property 'compatible' out of canonical order (should sort before 'interrupts')
diff --git a/scripts/dtc/dt-style-selftest/expected/yaml-prop-order-device-type.yaml.txt b/scripts/dtc/dt-style-selftest/expected/yaml-prop-order-device-type.yaml.txt
new file mode 100644
index 000000000000..9350e2b80f75
--- /dev/null
+++ b/scripts/dtc/dt-style-selftest/expected/yaml-prop-order-device-type.yaml.txt
@@ -0,0 +1,2 @@
+# mode=strict
+bad/yaml-prop-order-device-type.yaml:29: example 0 [property-order] property 'device_type' out of canonical order (should sort before 'compatible')
-- 
2.53.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help