mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] lightnvm: pblk: fix bad free seq. on error path
@ 2017-05-13  4:29 Javier González
  0 siblings, 0 replies; only message in thread
From: Javier González @ 2017-05-13  4:29 UTC (permalink / raw)
  To: mb, axboe; +Cc: linux-block, linux-kernel, Javier González

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@cnexlabs.com>
---
 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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-05-13  4:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-13  4:29 [PATCH] lightnvm: pblk: fix bad free seq. on error path Javier González

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®