linux-yocto/drivers/of
Zilin Guan f09b0f705b of: unittest: Fix memory leak in unittest_data_add()
[ Upstream commit 235a1eb8d2dcc49a6cf0a5ee1aa85544a5d0054b ]

In unittest_data_add(), if of_resolve_phandles() fails, the allocated
unittest_data is not freed, leading to a memory leak.

Fix this by using scope-based cleanup helper __free(kfree) for automatic
resource cleanup. This ensures unittest_data is automatically freed when
it goes out of scope in error paths.

For the success path, use retain_and_null_ptr() to transfer ownership
of the memory to the device tree and prevent double freeing.

Fixes: 2eb46da2a7 ("of/selftest: Use the resolver to fixup phandles")
Suggested-by: Rob Herring <robh@kernel.org>
Co-developed-by: Jianhao Xu <jianhao.xu@seu.edu.cn>
Signed-off-by: Jianhao Xu <jianhao.xu@seu.edu.cn>
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
Link: https://patch.msgid.link/20251231114915.234638-1-zilin@seu.edu.cn
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2026-01-17 16:35:18 +01:00
..
unittest-data samples: rust: platform: Add property child and reference args examples 2025-06-25 17:48:41 +02:00
.kunitconfig
address.c Devicetree for v6.15: 2025-03-29 11:23:16 -07:00
base.c Devicetree for v6.15: 2025-03-29 11:23:16 -07:00
cpu.c
device.c of: Clarify OF device context in of_match_device() comment 2025-07-30 17:49:06 -05:00
dynamic.c of: dynamic: Fix use after free in of_changeset_add_prop_helper() 2025-08-22 16:21:35 -05:00
empty_root.dts
fdt_address.c
fdt.c arm64: kdump: Fix elfcorehdr overlap caused by reserved memory processing reorder 2026-01-02 12:56:53 +01:00
irq.c of/irq: Export of_msi_xlate() for module usage 2025-10-24 07:44:09 -05:00
Kconfig
kexec.c arm64: add KHO support 2025-05-12 23:50:41 -07:00
kobj.c sysfs: treewide: switch back to bin_attribute::read()/write() 2025-06-17 10:44:13 +02:00
kunit_overlay_test.dtso
Makefile
module.c
of_kunit_helpers.c of: Skip devicetree kunit tests when RISCV+ACPI doesn't populate root node 2025-12-18 14:03:22 +01:00
of_numa.c of_numa: fix uninitialized memory nodes causing kernel panic 2025-08-27 22:45:41 -07:00
of_private.h Devicetree for v6.15: 2025-03-29 11:23:16 -07:00
of_reserved_mem.c dma-mapping fixes for Linux 6.17 2025-08-28 16:04:14 -07:00
of_test.c
overlay_test.c
overlay.c of: doc: Fix typo in doc comments. 2025-10-01 07:55:42 -05:00
pdt.c
platform.c
property.c of: Add of_property_read_u16_index 2025-03-20 12:42:27 +00:00
resolver.c
unittest.c of: unittest: Fix memory leak in unittest_data_add() 2026-01-17 16:35:18 +01:00