Thread (12 messages) 12 messages, 5 authors, 2025-05-26

Re: [PATCH v2 2/6] ASoC: aoa: Use helper function for_each_child_of_node_scoped()

From: Ai Chao <hidden>
Date: 2025-05-26 08:53:50
Also in: imx, linux-amlogic, linux-arm-kernel, linux-arm-msm, linux-renesas-soc, linux-sound, lkml

Hi Christophe:
quoted
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.
quoted
      }
+    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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help