[PATCH 0/2] cpufreq: sun50i: fix memory leak and remove of_node_put()

Javier Carrasco javier.carrasco.cruz at gmail.com
Fri May 3 10:52:31 PDT 2024


This series fixes a memory leak by means of the _scoped version of the
for_each_child_of_node() loop, which was recently introduced with
34af4554fb0c ("of: Introduce for_each_*_child_of_node_scoped() to
automate of_node_put() handling").

The new approach is still not widely used, but this might be a good
occasion to use it in a driver because it actually fixes a bug, and
the loop is rather simple.

The creator of the new macro was added to the discussion in case the
new approach is still not mature enough, even for such simple case.

Additionally, the existing uses of of_node_put() have been removed to
favour the _free() cleanup handler, which reduces the chances of having
any other memory leak because some of_node_put() is missing as well as
simplifies the current code.

I don't have the real hardware to test the series, so I "faked" the node
in a device tree for an arm64 device (Rockchip) and hacked the driver
to get to run dt_has_supported_hw(). The new implementation works as
expected, but if someone wants to test it with the proper SoC,
additional tests are always welcome. The same applies for the removals
of of_node_put().

Signed-off-by: Javier Carrasco <javier.carrasco.cruz at gmail.com>
---
Javier Carrasco (2):
      cpufreq: sun50i: fix memory leak in dt_has_supported_hw()
      cpufreq: sun50i: replace of_node_put() with automatic cleanup handler

 drivers/cpufreq/sun50i-cpufreq-nvmem.c | 27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)
---
base-commit: 9221b2819b8a4196eecf5476d66201be60fbcf29
change-id: 20240503-sun50i-cpufreq-nvmem-cleanup-40a4cf8fa56d

Best regards,
-- 
Javier Carrasco <javier.carrasco.cruz at gmail.com>




More information about the linux-arm-kernel mailing list