[PATCH] lightnvm: pblk: fix bad free seq. on error path
From: Javier GonzÃlez
Date: Sat May 13 2017 - 00:30:49 EST
Braces around the error patch for metadata pre-allocation are wrongly
placed. This causes a memory leak in case of a memory allocation
failure. Fix it
Signed-off-by: Javier GonzÃlez <javier@xxxxxxxxxxxx>
---
drivers/lightnvm/pblk-init.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c
index ae8cd6d5af8b..a2ee875aede3 100644
--- a/drivers/lightnvm/pblk-init.c
+++ b/drivers/lightnvm/pblk-init.c
@@ -604,12 +604,12 @@ static int pblk_lines_init(struct pblk *pblk)
l_mg->smeta_alloc_type = PBLK_KMALLOC_META;
for (i = 0; i < PBLK_DATA_LINES; i++) {
l_mg->sline_meta[i].meta = kmalloc(lm->smeta_len, GFP_KERNEL);
- if (!l_mg->sline_meta[i].meta)
- while (--i >= 0) {
+ if (!l_mg->sline_meta[i].meta) {
+ while (--i >= 0)
kfree(l_mg->sline_meta[i].meta);
- ret = -ENOMEM;
- goto fail;
- }
+ ret = -ENOMEM;
+ goto fail;
+ }
}
if (lm->emeta_len > KMALLOC_MAX_CACHE_SIZE) {
@@ -617,12 +617,12 @@ static int pblk_lines_init(struct pblk *pblk)
for (i = 0; i < PBLK_DATA_LINES; i++) {
l_mg->eline_meta[i].meta = vmalloc(lm->emeta_len);
- if (!l_mg->eline_meta[i].meta)
- while (--i >= 0) {
+ if (!l_mg->eline_meta[i].meta) {
+ while (--i >= 0)
vfree(l_mg->eline_meta[i].meta);
- ret = -ENOMEM;
- goto fail;
- }
+ ret = -ENOMEM;
+ goto fail_free_meta;
+ }
}
} else {
l_mg->emeta_alloc_type = PBLK_KMALLOC_META;
@@ -630,12 +630,12 @@ static int pblk_lines_init(struct pblk *pblk)
for (i = 0; i < PBLK_DATA_LINES; i++) {
l_mg->eline_meta[i].meta =
kmalloc(lm->emeta_len, GFP_KERNEL);
- if (!l_mg->eline_meta[i].meta)
- while (--i >= 0) {
+ if (!l_mg->eline_meta[i].meta) {
+ while (--i >= 0)
kfree(l_mg->eline_meta[i].meta);
- ret = -ENOMEM;
- goto fail;
- }
+ ret = -ENOMEM;
+ goto fail_free_meta;
+ }
}
}
--
2.7.4