* [PATCH -next] mtd/ftl: Fix memleak in ftl_add_mtd()
@ 2022-07-15 7:11 Gaosheng Cui
2022-08-18 1:31 ` cuigaosheng
0 siblings, 1 reply; 4+ messages in thread
From: Gaosheng Cui @ 2022-07-15 7:11 UTC (permalink / raw)
To: cuigaosheng1, miquel.raynal, richard, vigneshr
Cc: linux-mtd, linux-kernel, gongruiqi1, wangweiyang2
When add_mtd_blktrans_dev failed, partition's memory will be freed
by kfree, but there are some structure members that are allocated
for memory independently, such as partition->VirtualBlockMap,
partition->EUNInfo, partition->ZferInfo, and partition->bam_cache,
so kfree(partition) may cause memory leaks, using ftl_freepart(partition)
will fix it.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
---
drivers/mtd/ftl.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
index f655d2905270..200271bdc7aa 100644
--- a/drivers/mtd/ftl.c
+++ b/drivers/mtd/ftl.c
@@ -1031,6 +1031,7 @@ static void ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
partition->mbd.devnum = -1;
if (!add_mtd_blktrans_dev(&partition->mbd))
return;
+ ftl_freepart(partition);
}
kfree(partition);
--
2.25.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH -next] mtd/ftl: Fix memleak in ftl_add_mtd()
2022-07-15 7:11 [PATCH -next] mtd/ftl: Fix memleak in ftl_add_mtd() Gaosheng Cui
@ 2022-08-18 1:31 ` cuigaosheng
2022-08-18 6:59 ` Richard Weinberger
0 siblings, 1 reply; 4+ messages in thread
From: cuigaosheng @ 2022-08-18 1:31 UTC (permalink / raw)
To: miquel.raynal, richard, vigneshr, cuigaosheng1
Cc: linux-mtd, linux-kernel, gongruiqi1, wangweiyang2
PING
在 2022/7/15 15:11, Gaosheng Cui 写道:
> When add_mtd_blktrans_dev failed, partition's memory will be freed
> by kfree, but there are some structure members that are allocated
> for memory independently, such as partition->VirtualBlockMap,
> partition->EUNInfo, partition->ZferInfo, and partition->bam_cache,
> so kfree(partition) may cause memory leaks, using ftl_freepart(partition)
> will fix it.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
> ---
> drivers/mtd/ftl.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
> index f655d2905270..200271bdc7aa 100644
> --- a/drivers/mtd/ftl.c
> +++ b/drivers/mtd/ftl.c
> @@ -1031,6 +1031,7 @@ static void ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
> partition->mbd.devnum = -1;
> if (!add_mtd_blktrans_dev(&partition->mbd))
> return;
> + ftl_freepart(partition);
> }
>
> kfree(partition);
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH -next] mtd/ftl: Fix memleak in ftl_add_mtd()
2022-08-18 1:31 ` cuigaosheng
@ 2022-08-18 6:59 ` Richard Weinberger
2022-08-19 2:37 ` cuigaosheng
0 siblings, 1 reply; 4+ messages in thread
From: Richard Weinberger @ 2022-08-18 6:59 UTC (permalink / raw)
To: cuigaosheng
Cc: Miquel Raynal, Vignesh Raghavendra, linux-mtd, linux-kernel,
gongruiqi1, wangweiyang2
----- Ursprüngliche Mail -----
> Von: "cuigaosheng" <cuigaosheng1@huawei.com>
>
> PING
There seems to be a problem with your caps lock key. ;-)
> 在 2022/7/15 15:11, Gaosheng Cui 写道:
>> When add_mtd_blktrans_dev failed, partition's memory will be freed
>> by kfree, but there are some structure members that are allocated
>> for memory independently, such as partition->VirtualBlockMap,
>> partition->EUNInfo, partition->ZferInfo, and partition->bam_cache,
>> so kfree(partition) may cause memory leaks, using ftl_freepart(partition)
>> will fix it.
Is this leak observable via kmemleak or such?
I always thought ->remove_dev() unconditionally do a cleanup later.
>> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
>> Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
>> ---
>> drivers/mtd/ftl.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
>> index f655d2905270..200271bdc7aa 100644
>> --- a/drivers/mtd/ftl.c
>> +++ b/drivers/mtd/ftl.c
>> @@ -1031,6 +1031,7 @@ static void ftl_add_mtd(struct mtd_blktrans_ops *tr,
>> struct mtd_info *mtd)
>> partition->mbd.devnum = -1;
>> if (!add_mtd_blktrans_dev(&partition->mbd))
>> return;
>> + ftl_freepart(partition);
>> }
>>
> > kfree(partition);
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH -next] mtd/ftl: Fix memleak in ftl_add_mtd()
2022-08-18 6:59 ` Richard Weinberger
@ 2022-08-19 2:37 ` cuigaosheng
0 siblings, 0 replies; 4+ messages in thread
From: cuigaosheng @ 2022-08-19 2:37 UTC (permalink / raw)
To: Richard Weinberger, cuigaosheng1
Cc: Miquel Raynal, Vignesh Raghavendra, linux-mtd, linux-kernel,
gongruiqi1, wangweiyang2
> There seems to be a problem with your caps lock key. ;-)
I wil adjust my caps lock key, Thanks for reminding.
> Is this leak observable via kmemleak or such?
> I always thought ->remove_dev() unconditionally do a cleanup later.
When I'm working on other issues with mtd,I needed to analyze the mtd driver
initialization process,during reading the code, refer to other driver
implementation,I found this problem, not kmemleak. Thanks.
在 2022/8/18 14:59, Richard Weinberger 写道:
> ----- Ursprüngliche Mail -----
>> Von: "cuigaosheng" <cuigaosheng1@huawei.com>
>>
>> PING
> There seems to be a problem with your caps lock key. ;-)
>
>> 在 2022/7/15 15:11, Gaosheng Cui 写道:
>>> When add_mtd_blktrans_dev failed, partition's memory will be freed
>>> by kfree, but there are some structure members that are allocated
>>> for memory independently, such as partition->VirtualBlockMap,
>>> partition->EUNInfo, partition->ZferInfo, and partition->bam_cache,
>>> so kfree(partition) may cause memory leaks, using ftl_freepart(partition)
>>> will fix it.
> Is this leak observable via kmemleak or such?
> I always thought ->remove_dev() unconditionally do a cleanup later.
>
>>> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
>>> Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
>>> ---
>>> drivers/mtd/ftl.c | 1 +
>>> 1 file changed, 1 insertion(+)
>>>
>>> diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
>>> index f655d2905270..200271bdc7aa 100644
>>> --- a/drivers/mtd/ftl.c
>>> +++ b/drivers/mtd/ftl.c
>>> @@ -1031,6 +1031,7 @@ static void ftl_add_mtd(struct mtd_blktrans_ops *tr,
>>> struct mtd_info *mtd)
>>> partition->mbd.devnum = -1;
>>> if (!add_mtd_blktrans_dev(&partition->mbd))
>>> return;
>>> + ftl_freepart(partition);
>>> }
>>>
>>> kfree(partition);
> .
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-08-19 2:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-15 7:11 [PATCH -next] mtd/ftl: Fix memleak in ftl_add_mtd() Gaosheng Cui
2022-08-18 1:31 ` cuigaosheng
2022-08-18 6:59 ` Richard Weinberger
2022-08-19 2:37 ` cuigaosheng
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).