diff mbox

lightnvm: fix memory leak in pblk_luns_init

Message ID 20180222210147.GA29523@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Huaicheng Li Feb. 22, 2018, 9:01 p.m. UTC
Signed-off-by: Huaicheng Li <huaicheng@cs.uchicago.edu>
---
 drivers/lightnvm/pblk-init.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Matias Bjorling Feb. 23, 2018, 6:12 a.m. UTC | #1
On 02/23/2018 12:03 AM, Huaicheng Li wrote:
> Please ignore my previous email as I found the memory is free'ed at
> pblk_init()'s error handling logic.
> Sorry for the interruption.
> 
> On Thu, Feb 22, 2018 at 3:01 PM, Huaicheng Li <huaicheng@cs.uchicago.edu>
> wrote:
> 
>> Signed-off-by: Huaicheng Li <huaicheng@cs.uchicago.edu>
>> ---
>> drivers/lightnvm/pblk-init.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c
>> index 93d671ca518e..330665d91d8d 100644
>> --- a/drivers/lightnvm/pblk-init.c
>> +++ b/drivers/lightnvm/pblk-init.c
>> @@ -510,6 +510,7 @@ static int pblk_luns_init(struct pblk *pblk, struct
>> ppa_addr *luns)
>>                  if (ret) {
>>                          while (--i >= 0)
>>                                  kfree(pblk->luns[i].bb_list);
>> +                       kfree(pblk->luns);
>>                          return ret;
>>                  }
>>          }
>> --
>> 2.13.6
>>
>>
> 

No worries. The initialization part is pretty complex due to all the 
data structures being set up. I would love to have a clean 
initialization function, which cleans up after it self. But being able 
to share the "fail" bringup and tear-down code is very helpful and makes 
other parts easier.
=?UTF-8?q?Javier=20Gonz=C3=A1lez?= Feb. 23, 2018, 8:56 a.m. UTC | #2
> On 23 Feb 2018, at 07.12, Matias Bjørling <mb@lightnvm.io> wrote:
> 
> On 02/23/2018 12:03 AM, Huaicheng Li wrote:
>> Please ignore my previous email as I found the memory is free'ed at
>> pblk_init()'s error handling logic.
>> Sorry for the interruption.
>> On Thu, Feb 22, 2018 at 3:01 PM, Huaicheng Li <huaicheng@cs.uchicago.edu>
>> wrote:
>>> Signed-off-by: Huaicheng Li <huaicheng@cs.uchicago.edu>
>>> ---
>>> drivers/lightnvm/pblk-init.c | 1 +
>>> 1 file changed, 1 insertion(+)
>>> 
>>> diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c
>>> index 93d671ca518e..330665d91d8d 100644
>>> --- a/drivers/lightnvm/pblk-init.c
>>> +++ b/drivers/lightnvm/pblk-init.c
>>> @@ -510,6 +510,7 @@ static int pblk_luns_init(struct pblk *pblk, struct
>>> ppa_addr *luns)
>>>                 if (ret) {
>>>                         while (--i >= 0)
>>>                                 kfree(pblk->luns[i].bb_list);
>>> +                       kfree(pblk->luns);
>>>                         return ret;
>>>                 }
>>>         }
>>> --
>>> 2.13.6
> 
> No worries. The initialization part is pretty complex due to all the
> data structures being set up. I would love to have a clean
> initialization function, which cleans up after it self. But being able
> to share the "fail" bringup and tear-down code is very helpful and
> makes other parts easier.

As part of the 2.0 patches, I took a first try at refactoring the
init/exit sequences to maintain the same fail paths but minimizing
dependencies across structures. One of the big parts have been the bad
block initialization, which now is much cleaner, but still needs more
work to be as I would like it to. Patches are very welcome :)

Javier
diff mbox

Patch

diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c
index 93d671ca518e..330665d91d8d 100644
--- a/drivers/lightnvm/pblk-init.c
+++ b/drivers/lightnvm/pblk-init.c
@@ -510,6 +510,7 @@  static int pblk_luns_init(struct pblk *pblk, struct ppa_addr *luns)
 		if (ret) {
 			while (--i >= 0)
 				kfree(pblk->luns[i].bb_list);
+			kfree(pblk->luns);
 			return ret;
 		}
 	}