From: Frank Rowand <frowand.list@gmail.com>
To: Vincent Whitchurch <vincent.whitchurch@axis.com>,
pantelis.antoniou@konsulko.com, robh+dt@kernel.org
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
Vincent Whitchurch <rabinv@axis.com>
Subject: Re: [PATCH 1/2] of: overlay: fix properties memory leak
Date: Thu, 21 Nov 2019 10:55:26 -0600 [thread overview]
Message-ID: <53898749-ab88-19c3-77e7-6c81a8b0e8ee@gmail.com> (raw)
In-Reply-To: <20191118132809.30127-1-vincent.whitchurch@axis.com>
Hi Vincent,
On 11/18/19 7:28 AM, Vincent Whitchurch wrote:
> No changeset entries are created for #address-cells and #size-cells
> properties, but the duplicated properies are never freed. This results
> in a memory leak which is detected by kmemleak:
>
> unreferenced object 0x85887180 (size 64):
> backtrace:
> kmem_cache_alloc_trace+0x1fb/0x1fc
> __of_prop_dup+0x25/0x7c
> add_changeset_property+0x17f/0x370
> build_changeset_next_level+0x29/0x20c
> of_overlay_fdt_apply+0x32b/0x6b4
> ...
>
> Fixes: 6f75118800acf77f8 ("of: overlay: validate overlay properties #address-cells and #size-cells")
> Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
> ---
> drivers/of/overlay.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
> index c423e94baf0f..5f8869e2a8b3 100644
> --- a/drivers/of/overlay.c
> +++ b/drivers/of/overlay.c
> @@ -360,7 +360,7 @@ static int add_changeset_property(struct overlay_changeset *ovcs,
> pr_err("WARNING: memory leak will occur if overlay removed, property: %pOF/%s\n",
> target->np, new_prop->name);
>
> - if (ret) {
> + if (ret || !check_for_non_overlay_node) {
> kfree(new_prop->name);
> kfree(new_prop->value);
> kfree(new_prop);
>
Thanks for finding and proposing a fix for the memory leak.
The proposed patch conveniently uses check_for_non_overlay_node
which leads to a nice small patch. But ends up adding an
additional hidden meaning to the variable, resulting in more
fragile code.
I will propose a different solution and ask you to test it
to make sure it also solves the memory leak.
-Frank
prev parent reply other threads:[~2019-11-21 16:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-18 13:28 [PATCH 1/2] of: overlay: fix properties memory leak Vincent Whitchurch
2019-11-18 13:28 ` [PATCH 2/2] of: overlay: fix target_path " Vincent Whitchurch
2019-11-21 17:37 ` Frank Rowand
2019-11-21 16:55 ` Frank Rowand [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=53898749-ab88-19c3-77e7-6c81a8b0e8ee@gmail.com \
--to=frowand.list@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pantelis.antoniou@konsulko.com \
--cc=rabinv@axis.com \
--cc=robh+dt@kernel.org \
--cc=vincent.whitchurch@axis.com \
/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;
as well as URLs for NNTP newsgroup(s).