* [PATCH] of: unittest: Fix memory leak in unittest_data_add()
@ 2025-12-30 6:58 Zilin Guan
2025-12-30 18:09 ` Rob Herring
0 siblings, 1 reply; 3+ messages in thread
From: Zilin Guan @ 2025-12-30 6:58 UTC (permalink / raw)
To: robh; +Cc: saravanak, devicetree, linux-kernel, Zilin Guan, Jianhao Xu
In unittest_data_add(), if of_resolve_phandles() fails, the allocated
unittest_data is not freed, leading to a memory leak.
Fix this by freeing unittest_data in the error handling path before
returning.
Fixes: 2eb46da2a760 ("of/selftest: Use the resolver to fixup phandles")
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>
---
drivers/of/unittest.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 388e9ec2cccf..8622a8ac1814 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -2031,6 +2031,7 @@ static int __init unittest_data_add(void)
rc = of_resolve_phandles(unittest_data_node);
if (rc) {
pr_err("%s: Failed to resolve phandles (rc=%i)\n", __func__, rc);
+ kfree(unittest_data);
rc = -EINVAL;
goto unlock;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] of: unittest: Fix memory leak in unittest_data_add()
2025-12-30 6:58 [PATCH] of: unittest: Fix memory leak in unittest_data_add() Zilin Guan
@ 2025-12-30 18:09 ` Rob Herring
2025-12-31 10:35 ` Zilin Guan
0 siblings, 1 reply; 3+ messages in thread
From: Rob Herring @ 2025-12-30 18:09 UTC (permalink / raw)
To: Zilin Guan; +Cc: saravanak, devicetree, linux-kernel, Jianhao Xu
On Tue, Dec 30, 2025 at 06:58:59AM +0000, Zilin Guan wrote:
> In unittest_data_add(), if of_resolve_phandles() fails, the allocated
> unittest_data is not freed, leading to a memory leak.
>
> Fix this by freeing unittest_data in the error handling path before
> returning.
Please change the function to use cleanup.h instead so this bug can't
happen again.
>
> Fixes: 2eb46da2a760 ("of/selftest: Use the resolver to fixup phandles")
> 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>
> ---
> drivers/of/unittest.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
> index 388e9ec2cccf..8622a8ac1814 100644
> --- a/drivers/of/unittest.c
> +++ b/drivers/of/unittest.c
> @@ -2031,6 +2031,7 @@ static int __init unittest_data_add(void)
> rc = of_resolve_phandles(unittest_data_node);
> if (rc) {
> pr_err("%s: Failed to resolve phandles (rc=%i)\n", __func__, rc);
> + kfree(unittest_data);
> rc = -EINVAL;
> goto unlock;
> }
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] of: unittest: Fix memory leak in unittest_data_add()
2025-12-30 18:09 ` Rob Herring
@ 2025-12-31 10:35 ` Zilin Guan
0 siblings, 0 replies; 3+ messages in thread
From: Zilin Guan @ 2025-12-31 10:35 UTC (permalink / raw)
To: robh; +Cc: devicetree, jianhao.xu, linux-kernel, saravanak, zilin
On Tue, Dec 30, 2025 at 12:09:45PM -0600, Rob Herring wrote:
> Please change the function to use cleanup.h instead so this bug can't
> happen again.
Hi Rob,
Thanks for your review and suggestion.
I will update the code to use cleanup.h as suggested and send a v2 patch
soon.
Best regards,
Zilin Guan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-12-31 10:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-30 6:58 [PATCH] of: unittest: Fix memory leak in unittest_data_add() Zilin Guan
2025-12-30 18:09 ` Rob Herring
2025-12-31 10:35 ` Zilin Guan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).