From 957869414077efa66ca866e9fcced34ec9678a38 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 10 Jan 2025 17:00:11 -0700 Subject: ofnode: Update of_add_subnode() to indicate name is alloced This function allocates memory for the node name, so mention this in the function comment. Signed-off-by: Simon Glass --- include/dm/ofnode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/dm/ofnode.h') diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 890f0e6cf40..c5f0a6d6788 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -1809,7 +1809,7 @@ static inline int ofnode_read_bootscript_flash(u64 *bootscr_flash_offset, * of_add_subnode() - add a new subnode to a node * * @parent: parent node to add to - * @name: name of subnode + * @name: name of subnode (allocated by this function) * @nodep: returns pointer to new subnode (valid if the function returns 0 * or -EEXIST) * Returns 0 if OK, -EEXIST if already exists, -ENOMEM if out of memory, other -- cgit v1.2.3 From ff698f2ddbcce5601a19fd61bef45aedd3d59cc6 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 10 Jan 2025 17:00:27 -0700 Subject: dm: core: Clarify behaviour of ofnode_name_eq() This function is somewhat ambiguous, so expand the comments and add a test for the undefined behaviour. Signed-off-by: Simon Glass --- include/dm/ofnode.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'include/dm/ofnode.h') diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index c5f0a6d6788..2f3da384eba 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -386,11 +386,10 @@ static inline oftree oftree_from_np(struct device_node *root) void oftree_dispose(oftree tree); /** - * ofnode_name_eq() - Check if the node name is equivalent to a given name - * ignoring the unit address + * ofnode_name_eq() - Check a node name ignoring its unit address * - * @node: valid node reference that has to be compared - * @name: name that has to be compared with the node name + * @node: valid node to compared, which may have a unit address + * @name: name (without unit address) to compare with the node name * Return: true if matches, false if it doesn't match */ bool ofnode_name_eq(ofnode node, const char *name); -- cgit v1.2.3 From aacc05b07d28e01bbbaf9037b3e8e1275e48701f Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 10 Jan 2025 17:00:28 -0700 Subject: dm: core: Provide ofnode_name_eq_unit() to accept a unit address When a unit-address is provided, use it to match against the node name. Since this increases code size, put it into a separate function. Signed-off-by: Simon Glass --- include/dm/ofnode.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'include/dm/ofnode.h') diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 2f3da384eba..8e4c3574df8 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -394,6 +394,20 @@ void oftree_dispose(oftree tree); */ bool ofnode_name_eq(ofnode node, const char *name); +/** + * ofnode_name_eq_unit() - Check a node name ignoring its unit address + * + * This is separate from ofnode_name_eq() to avoid code-size increase for + * boards which don't need this function + * + * @node: valid node to compared, which may have a unit address + * @name: name to compare with the node name. If this contains a unit + * address, it is matched, otherwise the unit address is ignored + * when searching for matches + * Return: true if matches, false if it doesn't match + */ +bool ofnode_name_eq_unit(ofnode node, const char *name); + /** * ofnode_read_u8() - Read a 8-bit integer from a property * -- cgit v1.2.3 From 8985ff56b16dc6c04da2c96d48e7f6f54d04e3ff Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 10 Jan 2025 17:00:29 -0700 Subject: dm: core: Provide ofnode_find_subnode_unit() The ofnode_find_subnode() function currently processes things two different ways, so the treatment of unit addresses differs depending on whether OF_LIVE is enabled or not. Add a new version which uses the ofnode API and add a test to check that unit addresses can be matched correctly. Leave the old function in place for the !OF_LIVE case, to avoid a code-size increase, e.g. on firefly-rk3288 Signed-off-by: Simon Glass --- include/dm/ofnode.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'include/dm/ofnode.h') diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 8e4c3574df8..120393426db 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -607,6 +607,18 @@ bool ofnode_read_bool(ofnode node, const char *propname); */ ofnode ofnode_find_subnode(ofnode node, const char *subnode_name); +/** + * ofnode_find_subnode_unit() - find a named subnode of a parent node + * + * @node: valid reference to parent node + * @subnode_name: name of subnode to find, including any unit address. If the + * unit address is omitted, any subnode which matches the name (excluding + * any unit address) is returned + * Return: reference to subnode (which can be invalid if there is no such + * subnode) + */ +ofnode ofnode_find_subnode_unit(ofnode node, const char *subnode_name); + #if CONFIG_IS_ENABLED(DM_INLINE_OFNODE) #include -- cgit v1.2.3