From: Muchun Song <muchun.song@linux.dev>
To: Liu Ye <liuye@kylinos.cn>
Cc: akpm@linux-foundation.org, david@fromorbit.com,
zhengqi.arch@bytedance.com, roman.gushchin@linux.dev,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/shrinker_debug: Fix possible memory leak in shrinker_debugfs_rename function.
Date: Wed, 5 Mar 2025 11:17:48 +0800 [thread overview]
Message-ID: <99A7645C-B8FB-4F28-B4B8-D5372F4C001E@linux.dev> (raw)
In-Reply-To: <20250305020123.605496-1-liuye@kylinos.cn>
> On Mar 5, 2025, at 10:01, Liu Ye <liuye@kylinos.cn> wrote:
>
> After calling debugfs_change_name function, the return value should be
> checked and the old name restored. If debugfs_change_name fails, the new
> name memory should be freed.
Seems it is not a big problem, no memory leak at least. The effect is that
the shrinker->name is not consistent with the name displayed in debugfs.
Right? But the improvement LGTM. So:
Reviewed-by: Muchun Song <muchun.song@linux.dev>
Thanks.
>
> Signed-off-by: Liu Ye <liuye@kylinos.cn>
> ---
> mm/shrinker_debug.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/mm/shrinker_debug.c b/mm/shrinker_debug.c
> index 794bd433cce0..20eaee3e97f7 100644
> --- a/mm/shrinker_debug.c
> +++ b/mm/shrinker_debug.c
> @@ -214,10 +214,14 @@ int shrinker_debugfs_rename(struct shrinker *shrinker, const char *fmt, ...)
> ret = debugfs_change_name(shrinker->debugfs_entry, "%s-%d",
> shrinker->name, shrinker->debugfs_id);
>
> + if (ret) {
> + shrinker->name = old;
> + kfree_const(new);
> + } else {
> + kfree_const(old);
> + }
> mutex_unlock(&shrinker_mutex);
>
> - kfree_const(old);
> -
> return ret;
> }
> EXPORT_SYMBOL(shrinker_debugfs_rename);
> --
> 2.25.1
>
next prev parent reply other threads:[~2025-03-05 3:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-05 2:01 Liu Ye
2025-03-05 3:17 ` Muchun Song [this message]
2025-03-05 3:26 ` Qi Zheng
[not found] ` <875d80ee-d99a-4580-8648-36adb1e8591c@kylinos.cn>
2025-03-05 6:46 ` Muchun Song
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=99A7645C-B8FB-4F28-B4B8-D5372F4C001E@linux.dev \
--to=muchun.song@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=david@fromorbit.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=liuye@kylinos.cn \
--cc=roman.gushchin@linux.dev \
--cc=zhengqi.arch@bytedance.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