mirror-linux/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 samples: rust: platform: Add property child and reference args examples 2025-06-25 17:48:41 +02:00
.kunitconfig of: Allow overlay kunit tests to run CONFIG_OF_OVERLAY=n 2024-11-15 14:03:28 -06:00
Kconfig Kbuild updates for v6.13 2024-11-30 13:41:50 -08:00
Makefile of: Add a KUnit test for overlays and test managed APIs 2024-07-29 15:33:12 -07:00
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 of: Constify struct device_node function arguments 2024-10-15 08:58:36 -05:00
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 of: Add #address-cells/#size-cells in the device-tree root empty node 2024-12-02 09:26:33 -06:00
fdt.c arm64: kdump: Fix elfcorehdr overlap caused by reserved memory processing reorder 2025-12-16 07:59:30 -06:00
fdt_address.c of: Remove a duplicated code block 2025-01-13 08:39:28 -06:00
irq.c Devicetree updates for v6.19: 2025-12-04 15:50:37 -08:00
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 of: Add a KUnit test for overlays and test managed APIs 2024-07-29 15:33:12 -07:00
module.c of: module: remove strlen() call in of_modalias() 2024-10-16 12:00:10 -05:00
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_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 of/reserved_mem: Simplify the logic of __reserved_mem_alloc_size() 2025-11-20 08:32:49 -06:00
of_test.c of: address: Add kunit test for __of_address_resource_bounds() 2025-02-02 20:59:04 -06:00
overlay.c of: overlay: Avoid spurious error messages in of_overlay_remove() 2025-11-17 11:24:51 -06:00
overlay_test.c of: Allow overlay kunit tests to run CONFIG_OF_OVERLAY=n 2024-11-15 14:03:28 -06:00
pdt.c of: Do not expose of_alias_scan() and correct its comments 2025-01-17 08:52:57 -06:00
platform.c of/platform: Use typed accessors rather than of_get_property() 2025-03-14 18:01:42 -05:00
property.c of: base: Add of_property_read_u8_index 2025-12-08 12:37:26 +05:30
resolver.c of: Introduce and apply private is_pseudo_property() 2025-02-25 08:43:00 -06:00
unittest.c of: unittest: Fix memory leak in unittest_data_add() 2026-01-02 15:36:37 -06:00