From: Rob Herring <robh@kernel.org>
To: Zilin Guan <zilin@seu.edu.cn>
Cc: saravanak@google.com, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, Jianhao Xu <jianhao.xu@seu.edu.cn>
Subject: Re: [PATCH] of: unittest: Fix memory leak in unittest_data_add()
Date: Tue, 30 Dec 2025 12:09:45 -0600 [thread overview]
Message-ID: <20251230180945.GA885892-robh@kernel.org> (raw)
In-Reply-To: <20251230065859.1046756-1-zilin@seu.edu.cn>
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
>
next prev parent reply other threads:[~2025-12-30 18:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-30 6:58 [PATCH] of: unittest: Fix memory leak in unittest_data_add() Zilin Guan
2025-12-30 18:09 ` Rob Herring [this message]
2025-12-31 10:35 ` Zilin Guan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251230180945.GA885892-robh@kernel.org \
--to=robh@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jianhao.xu@seu.edu.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=saravanak@google.com \
--cc=zilin@seu.edu.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox