From: "Rob Herring (Arm)" <robh@kernel.org>
To: Zilin Guan <zilin@seu.edu.cn>
Cc: Jianhao Xu <jianhao.xu@seu.edu.cn>,
saravanak@google.com, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] of: unittest: Fix memory leak in unittest_data_add()
Date: Fri, 2 Jan 2026 15:36:38 -0600 [thread overview]
Message-ID: <176738979758.226449.11539290980243555444.robh@kernel.org> (raw)
In-Reply-To: <20251231114915.234638-1-zilin@seu.edu.cn>
On Wed, 31 Dec 2025 11:49:15 +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 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: 2eb46da2a760 ("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>
> ---
> Changes in v2:
> - using scope-based cleanup helper __free(kfree) for automatic resource cleanup.
>
> drivers/of/unittest.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
Applied, thanks!
prev parent reply other threads:[~2026-01-02 21:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-31 11:49 Zilin Guan
2026-01-02 21:36 ` Rob Herring (Arm) [this message]
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=176738979758.226449.11539290980243555444.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
all inboxes | Powered by JetHome®