Skip to content

Commit 2ced0c3

Browse files
check_compliance: check for underscores in property names
Issue failures when a devicetree property defined in a binding contains an underscore. The standard word separator in a property is a dash. (This won't affect the standard -- albeit deprecated -- device_type property, because that is not defined in any bindings.) Add an 'allowlist' type file, check_compliance_ok_properties.yaml, for existing cases that are OK. Fixes: #53506 Signed-off-by: Marti Bolivar <[email protected]>
1 parent b6ab838 commit 2ced0c3

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

scripts/ci/check_compliance.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import shlex
2020

2121
from yamllint import config, linter
22+
import yaml
2223

2324
from junitparser import TestCase, TestSuite, JUnitXml, Skipped, Error, Failure
2425
import magic
@@ -247,6 +248,8 @@ def run(self):
247248
if len(matches) == 0:
248249
self.failure(output)
249250

251+
with open(Path(__file__).parent / 'check_compliance_ok_properties.yaml', 'r') as f:
252+
DT_OK_PROPERTIES = set(yaml.safe_load(f.read()))
250253

251254
class DevicetreeBindingsCheck(ComplianceTest):
252255
"""
@@ -285,6 +288,7 @@ def run(self, full=True):
285288
# This does a bit more work than necessary, but that should
286289
# be OK.
287290
for binding in edtlib.bindings_from_dirs(bindings_dirs):
291+
self.check_recursively(binding, self.property_name_check)
288292
self.check_recursively(binding, self.required_false_check)
289293

290294
@staticmethod
@@ -293,6 +297,20 @@ def check_recursively(binding, check_function):
293297
check_function(binding)
294298
binding = binding.child_binding
295299

300+
def property_name_check(self, binding):
301+
for prop_name in binding.prop2specs:
302+
if '_' in prop_name and prop_name not in DT_OK_PROPERTIES:
303+
better_prop = prop_name.replace('_', '-')
304+
self.failure(
305+
f'{binding.path}: property "{prop_name}" contains '
306+
'underscores.\n'
307+
f'\tUse "{better_prop}" instead unless '
308+
'this property name is from Linux or another authoritative '
309+
f'upstream source of bindings for compatible "{binding.compatible}".\n'
310+
'\tHint: update check_compliance_ok_properties.yaml if you need to '
311+
'override this check for this property.'
312+
)
313+
296314
def required_false_check(self, binding):
297315
raw_props = binding.raw.get('properties', {})
298316
for prop_name, raw_prop in raw_props.items():
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This file is a YAML list of property names that are OK to contain
2+
# underscores because they are from upstream Linux or some other
3+
# authoritative source.
4+
#
5+
# Otherwise, the preferred word separator in DT property names is '-',
6+
# not '_'.
7+
8+
- mmc-hs200-1_8v
9+
- mmc-hs400-1_8v

0 commit comments

Comments
 (0)