* [PATCH] mm/shrinker_debug: Fix possible memory leak in shrinker_debugfs_rename function.
@ 2025-03-05 2:01 Liu Ye
2025-03-05 3:17 ` Muchun Song
0 siblings, 1 reply; 4+ messages in thread
From: Liu Ye @ 2025-03-05 2:01 UTC (permalink / raw)
To: akpm, david
Cc: zhengqi.arch, roman.gushchin, muchun.song, linux-mm,
linux-kernel, Liu Ye
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.
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/shrinker_debug: Fix possible memory leak in shrinker_debugfs_rename function.
2025-03-05 2:01 [PATCH] mm/shrinker_debug: Fix possible memory leak in shrinker_debugfs_rename function Liu Ye
@ 2025-03-05 3:17 ` Muchun Song
2025-03-05 3:26 ` Qi Zheng
0 siblings, 1 reply; 4+ messages in thread
From: Muchun Song @ 2025-03-05 3:17 UTC (permalink / raw)
To: Liu Ye; +Cc: akpm, david, zhengqi.arch, roman.gushchin, linux-mm, linux-kernel
> 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
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/shrinker_debug: Fix possible memory leak in shrinker_debugfs_rename function.
2025-03-05 3:17 ` Muchun Song
@ 2025-03-05 3:26 ` Qi Zheng
[not found] ` <875d80ee-d99a-4580-8648-36adb1e8591c@kylinos.cn>
0 siblings, 1 reply; 4+ messages in thread
From: Qi Zheng @ 2025-03-05 3:26 UTC (permalink / raw)
To: Muchun Song, Liu Ye; +Cc: akpm, david, roman.gushchin, linux-mm, linux-kernel
On 3/5/25 11:17 AM, Muchun Song wrote:
>
>
>> 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:
Right, so the subject needs to be changed.
Maybe:
mm: shrinker: fix name consistency issue in shrinker_debugfs_rename()
?
BTW, it seems that the callers of shrinker_debugfs_rename() did not
process the return value of the function?
>
> 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
>>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/shrinker_debug: Fix possible memory leak in shrinker_debugfs_rename function.
[not found] ` <875d80ee-d99a-4580-8648-36adb1e8591c@kylinos.cn>
@ 2025-03-05 6:46 ` Muchun Song
0 siblings, 0 replies; 4+ messages in thread
From: Muchun Song @ 2025-03-05 6:46 UTC (permalink / raw)
To: liuye; +Cc: Qi Zheng, akpm, david, roman.gushchin, linux-mm, linux-kernel
> On Mar 5, 2025, at 14:10, liuye <liuye@kylinos.cn> wrote:
>
>
> 在 2025/3/5 11:26, Qi Zheng 写道:
>>
>>
>> On 3/5/25 11:17 AM, Muchun Song wrote:
>>>
>>>
>>>> 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:
>>
>> Right, so the subject needs to be changed.
>>
>> Maybe:
>>
>> mm: shrinker: fix name consistency issue in shrinker_debugfs_rename()
>>
>> ?
> I will send a new patch using this subject later.
Please update the commit message as well to include the effect.
> And add Reviewed-by:Qi Zheng <zhengqi.arch@bytedance.com> ?
>
>>
>> BTW, it seems that the callers of shrinker_debugfs_rename() did not
>> process the return value of the function?
>
> Yes, At the same time, I also found that many positions using
> debugfs_change_name did not determine the return value.
>
>>
>>>
>>> Reviewed-by: Muchun Song <muchun.song@linux.dev>
>>>
>>> Thanks.
> 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
>>>>
>>>
>>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-03-05 18:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-05 2:01 [PATCH] mm/shrinker_debug: Fix possible memory leak in shrinker_debugfs_rename function Liu Ye
2025-03-05 3:17 ` Muchun Song
2025-03-05 3:26 ` Qi Zheng
[not found] ` <875d80ee-d99a-4580-8648-36adb1e8591c@kylinos.cn>
2025-03-05 6:46 ` Muchun Song
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox