public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: Frank Rowand <frowand.list@gmail.com>
To: Zeng Heng <zengheng4@huawei.com>, robh+dt@kernel.org
Cc: devicetree@vger.kernel.org, liwei391@huawei.com
Subject: Re: [PATCH v2] of: overlay: fix memory leak in add_changeset_node()
Date: Tue, 22 Nov 2022 18:29:28 -0600	[thread overview]
Message-ID: <c89af7df-4e6d-3d0b-d58a-1dbbfe43fcff@gmail.com> (raw)
In-Reply-To: <20221121035335.809316-1-zengheng4@huawei.com>

Hi Zeng,

In the future, please do not send a new version of a patch series as a reply
to a previous thread.  For people who leave threads collapsed in their email
client (like me), there is a good chance that the new patch version email
will not be noticed.

More below...

On 11/20/22 21:53, Zeng Heng wrote:

> When of_changeset_attach_node() returns fail and tchild is
> over of life cycle which is duplicated by __of_node_dup(),
> it needs to call of_node_put() to release tchild in
> error handle route.

This does not seem correct.  I will explain this in the patch v1
thread.

> 
> Otherwise, there are some memory leak reported about the node:
> 
> unreferenced object 0xffff88810cd1e800 (size 256):
>   backtrace:
>     kmalloc_trace
>     __of_node_dup
>     add_changeset_node (inlined)
>     build_changeset_next_level
> 
> unreferenced object 0xffff888113721240 (size 16):
>   backtrace:
>     __kmalloc_node_track_caller
>     kstrdup
>     __of_node_dup
>     add_changeset_node (inlined)
>     build_changeset_next_level
> 
> unreferenced object 0xffff88810a38d400 (size 128):
>   backtrace:
>     kmalloc_trace
>     __of_prop_dup
>     add_changeset_property
>     build_changeset_next_level
> 

> Fixes: 0290c4ca2536 ("of: overlay: rename identifiers to more reflect what they do")

You have to dig deeper.  The code that introduced the issue is even older:

7518b5890d8a of/overlay: Introduce DT overlay support

-Frank


> Signed-off-by: Zeng Heng <zengheng4@huawei.com>
> ---
>  drivers/of/overlay.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
> index bd8ff4df723d..a5189a0ec0a3 100644
> --- a/drivers/of/overlay.c
> +++ b/drivers/of/overlay.c
> @@ -436,8 +436,10 @@ static int add_changeset_node(struct overlay_changeset *ovcs,
>  		of_node_set_flag(tchild, OF_OVERLAY);
>  
>  		ret = of_changeset_attach_node(&ovcs->cset, tchild);
> -		if (ret)
> +		if (ret) {
> +			of_node_put(tchild);
>  			return ret;
> +		}
>  
>  		target_child.np = tchild;
>  		target_child.in_livetree = false;


  parent reply	other threads:[~2022-11-23  0:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-18 10:53 [PATCH] of: overlay: fix memory leak in add_changeset_node() Zeng Heng
2022-11-21  2:00 ` Frank Rowand
2022-11-21  3:37   ` Zeng Heng
2022-11-21  3:53     ` [PATCH v2] " Zeng Heng
2022-11-21  6:07       ` Zeng Heng
2022-11-23  0:29       ` Frank Rowand [this message]
2022-11-23  1:16         ` Frank Rowand
2022-11-23  1:52           ` Zeng Heng
2022-11-23  1:41         ` Zeng Heng
2022-12-01 22:54 ` [PATCH] " Frank Rowand

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=c89af7df-4e6d-3d0b-d58a-1dbbfe43fcff@gmail.com \
    --to=frowand.list@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=liwei391@huawei.com \
    --cc=robh+dt@kernel.org \
    --cc=zengheng4@huawei.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