linux-kernelorg-stable/drivers/of
Zilin Guan 235a1eb8d2 of: unittest: Fix memory leak in unittest_data_add()
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>
2026-01-02 15:36:37 -06:00
..
unittest-data
.kunitconfig
Kconfig
Makefile
address.c of/address: Remove the incorrect and misleading comment 2025-11-17 11:24:51 -06:00
base.c of: Add wrappers to match root node with OF device ID tables 2025-11-26 19:38:24 -06:00
cpu.c
device.c
dynamic.c
empty_root.dts
fdt.c arm64: kdump: Fix elfcorehdr overlap caused by reserved memory processing reorder 2025-12-16 07:59:30 -06:00
fdt_address.c
irq.c Devicetree updates for v6.19: 2025-12-04 15:50:37 -08:00
kexec.c
kobj.c
kunit_overlay_test.dtso
module.c
of_kunit_helpers.c of: Skip devicetree kunit tests when RISCV+ACPI doesn't populate root node 2025-11-26 19:46:23 -06:00
of_numa.c
of_private.h
of_reserved_mem.c of/reserved_mem: Simplify the logic of __reserved_mem_alloc_size() 2025-11-20 08:32:49 -06:00
of_test.c
overlay.c of: overlay: Avoid spurious error messages in of_overlay_remove() 2025-11-17 11:24:51 -06:00
overlay_test.c
pdt.c
platform.c
property.c of: base: Add of_property_read_u8_index 2025-12-08 12:37:26 +05:30
resolver.c
unittest.c of: unittest: Fix memory leak in unittest_data_add() 2026-01-02 15:36:37 -06:00