From patchwork Sat May 13 04:29:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?UTF-8?q?Javier=20Gonz=C3=A1lez?= X-Patchwork-Id: 9725003 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7248060146 for ; Sat, 13 May 2017 04:30:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 601652888D for ; Sat, 13 May 2017 04:30:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 53569288AE; Sat, 13 May 2017 04:30:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 502FE2888D for ; Sat, 13 May 2017 04:30:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750935AbdEMEaI (ORCPT ); Sat, 13 May 2017 00:30:08 -0400 Received: from mail-wm0-f51.google.com ([74.125.82.51]:35295 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750779AbdEMEaG (ORCPT ); Sat, 13 May 2017 00:30:06 -0400 Received: by mail-wm0-f51.google.com with SMTP id b84so35952360wmh.0 for ; Fri, 12 May 2017 21:30:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lightnvm-io.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=mzJEy4FxdtZbDouMnXWb8ItIpu/YNYKUx41pKcYhdDY=; b=0u+oBFTKlXoH+aC0nIokEkUV0lqERdCle/AaavUbnNxeI6VtEI7cUlCpHT2HKn9kJ5 dyK776e8W6ndZTL7BpE+DgFdmlYP4lVa/y0W4Wp1YiZ34+LDtp+0PKzTh5E8Xs2jUd8h BmGeWYuMOJx8k12EVprQIQd5zGxTsXpjrDRmOYAKx8Ry07TnUYgt9qT9W8KU21T+95S/ uFhvZJA/8BWeog1MU/aHc3OqN3w4u8xL+Dauf2CqjSmnE0puXEStsoxOpiTs5tGnQk9o EYDucxth9wYqSsgu1rv+Tbl3oYvYYoR32hw6UMO6I+GfQvPRv0ohc0WP/EW7KcUTf/VJ JMuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=mzJEy4FxdtZbDouMnXWb8ItIpu/YNYKUx41pKcYhdDY=; b=VXGvxh9kX4D9k2ufDrYKfUoJ/2JVG524PiKHOT3OGOzs7aI42ZijjqJEKEPRrZDvmG Z5DuY4iOiKzNoUyrj7PGXowTSYquCNx7TwwNPms7H3Eqw9M4vwVpy4HQYP0Ra56qLjEY XlaL/oTOVaZo5XhkV+nqrkGvFA6UJFCxrdMy9vExdfermpPD8AljchHrP5rJUZ+ZanC2 K8LkWDleVwTP5BD3H/l1NORSt4zFTUTrzDqkXaOGQUPOn95IFaYHlgqpHJgyarZpNsu4 0Od0phpoVT7dkC6G6aqmV+2dLB1R3oGK0nkVDfRDgRT02mQ18GhNXDINHyx8SfZzXE7v a2jg== X-Gm-Message-State: AODbwcCUcHT6u6+lKLLTu63McWC7wNni4iAbdG7pH9BziJPuIDac+6EY i6xmIgU7q08YaA== X-Received: by 10.80.135.214 with SMTP id 22mr6073526edz.124.1494649805346; Fri, 12 May 2017 21:30:05 -0700 (PDT) Received: from uHalley.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id m9sm2676138edm.62.2017.05.12.21.30.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 May 2017 21:30:04 -0700 (PDT) From: "=?UTF-8?q?Javier=20Gonz=C3=A1lez?=" X-Google-Original-From: =?UTF-8?q?Javier=20Gonz=C3=A1lez?= To: mb@lightnvm.io, axboe@fb.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Javier=20Gonz=C3=A1lez?= Subject: [PATCH] lightnvm: pblk: fix bad free seq. on error path Date: Sat, 13 May 2017 06:29:55 +0200 Message-Id: <1494649795-569-1-git-send-email-javier@cnexlabs.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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; + } } }