Skip to content

Conversation

mathieuchopstm
Copy link
Contributor

dt_nodelabel_int_prop did not check if the property existed on the node before accessing it, which would result in a build-time crash (KeyError exception) and thus build error if used on a node which lacked the requested property.

Fix by using the common _node_int_prop() helper which handles all edge cases properly.

NOTE: there is a tiny functional difference compared to my original idea which was

-    if not node or node.props[prop].type != "int":
+    if not node:
       return "0"

+    if not prop in node.props:     # <=== this is the missing check
+      return "0"
+
+    if node.props[prop].type != "int":
+      return "0"

   if not node.props[prop].val:
       return "0"

   return str(node.props[prop].val)

➡️ _node_int_prop() does not check for node.props[prop].val is not None

However, the check for type should be sufficient since according to edtlib documentation:

val:
The value of the property, with the format determined by spec.type,
which comes from the 'type:' string in the binding.
- For 'type: int/array/string/string-array', 'val' is what you'd expect
(a Python integer or string, or a list of them)

dt_nodelabel_int_prop did not check if the property existed on the node
before accessing it, which would result in a build-time crash (and thus
build error) if used on a node which lacked the requested property.

Fix by using the common _node_int_prop() helper which handles all edge
cases properly.

Signed-off-by: Mathieu Choplain <[email protected]>
Copy link

sonarqubecloud bot commented Oct 8, 2025

@cfriedt cfriedt merged commit 7bbecd8 into zephyrproject-rtos:main Oct 11, 2025
36 checks passed
@mathieuchopstm mathieuchopstm deleted the kconfigfuncs_ensure_dt_prop_exists branch October 13, 2025 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants