Skip to contentSkip to conversation

lightnvm: fix memory leak in pblk_luns_init

PATCH In review Huaicheng Li 3 participants 3 messages Feb 22, 2018 – Feb 23, 2018 1 message not in the archive Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lightnvm: fix memory leak in pblk_luns_init

---
drivers/lightnvm/pblk-init.c | 1 +

1 file changed, 1 insertion(+)
drivers/lightnvm/pblk-init.c +0 -0
index 93d671ca518e..330665d91d8d 100644
@@ -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;
		}
	}
Signature · 1 line
2.13.6

A message that is not in the archive (sent off-list or not yet received): CANr0WEcDSy3YuZ8kaNuB7Z0wFfiV6AwT=bg4W3MNq--2txX2xQ@mail.gmail.com

#2 lore raw
Quoted 21 lines · Huaicheng Li

Please ignore my previous email as I found the memory is free'ed at pblk_init()'s error handling logic.
Sorry for the interruption.

Quoted 14 lines · Huaicheng Li

---
drivers/lightnvm/pblk-init.c | 1 +

1 file changed, 1 insertion(+)
drivers/lightnvm/pblk-init.c +0 -0
index 93d671ca518e..330665d91d8d 100644
@@ -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);
Quoted 9 lines
Quoted 8 lines
drivers/lightnvm/pblk-init.c +1 -0
+                       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.

#3 lore raw
Quoted 26 lines · Matias Bjørling
Quoted 23 lines · Huaicheng Li

Please ignore my previous email as I found the memory is free'ed at pblk_init()'s error handling logic.
Sorry for the interruption.

Quoted 18 lines · Huaicheng Li

---
drivers/lightnvm/pblk-init.c | 1 +

1 file changed, 1 insertion(+)
drivers/lightnvm/pblk-init.c +1 -0
index 93d671ca518e..330665d91d8d 100644
@@ -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;
                }
        }
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

--
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