[PATCH v2 2/6] ASoC: aoa: Use helper function for_each_child_of_node_scoped()
Ai Chao
aichao at kylinos.cn
Mon May 26 18:53:42 AEST 2025
Hi Christophe:
>> The for_each_child_of_node_scoped() helper provides a scope-based
>> clean-up functionality to put the device_node automatically, and
>> as such, there is no need to call of_node_put() directly.
>
> I don't understand this explanation.
>
> You say "no need to call of_node_put()" and the only thing you do in
> addition to changing from for_each_child_of_node() to
> for_each_child_of_node_scoped() is to _add_ a new call to of_node_put().
>
> I would expect to see a _removal_ of some of_node_put() when I read
> your description.
>
>> }
>> + of_node_put(sound);
>> +
The for_each_child_of_node() function is used to iterate over all child
nodes of a device tree node. During each iteration, it retrieves a
pointer to the child node via of_get_next_child() and automatically
increments the node's reference count (of_node_get()). Each call to
of_get_next_child() increases the reference count (refcount) of the
returned child node, ensuring that the node is not freed while in use.
for_each_child_of_node() increments the child node's reference count in
each iteration but does not decrement it automatically.
If of_node_put() is not called manually, the reference count will never
reach zero, resulting in a memory leak of the node.
In function i2sbus_add_dev, it used device_node out of
for_each_child_of_node(){}, it need to add a new call to
of_node_put(sound) to reference count.
In function i2cbus_probe, it used device_node in
for_each_child_of_node(){}, used for_each_child_of_node_scoped() is
better than for_each_child_of_node().
Best regards,
Ai Chao
More information about the Linuxppc-dev
mailing list