Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1308697ybl; Sun, 18 Aug 2019 00:30:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqzWfRZPaj+qJjoU86xc31gsG7R9eI6qbhK9Q57RD+hm7xJ+STkBmw5Dwlhwp8cLNWv+DFrx X-Received: by 2002:a17:902:7442:: with SMTP id e2mr6665562plt.315.1566113412730; Sun, 18 Aug 2019 00:30:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566113412; cv=none; d=google.com; s=arc-20160816; b=ROpZcPImVZmehy/EUk6b/TogrtRFzziSy9op92rGPE3w2R7dHFVBT6gwfiKPzyzIiv MyaxdBCdjAsDfy32Qdp8B93njipzdk7G8BPbaMTpfu3u/meznxgkI+30cDO6M7fmtcvv HUT9VxYqdFvuXZprHRfeTpgKdqVomidhbPHoNb0j8TSKecYGdUN1XIU2lZlcWqbVkzkz 6O6tmOIAlmpB9Px/3OMKN/eoTXbJ0Az0g+0jndZl72Z5kTgqny1P0z9wHzaT9VExMZ+x CkpkJyh9mBYpXLSEuIO1RhugK+2Bu41U4DlJGHIo5we/vHdYwcYvLS6VLchc5hnew/3d sPoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=o9Rkq3dkBHyl5deQARpSgyWUVR/JbkupDTFCJi/n5xw=; b=oo4Ewg44krDOVgOnpjhqaJi4wkMSJkdtl/ayZumOvDE5/hw+5H97Rlep2aENLlmIna 6UaLI9NVil/koPFEwuRPfVyAuMaK+7xjEVSbMsr7P/uEW99PSwqwEeC8XFsSaGWQ9jOZ qcfoks5lANHZJjXddBlm7BoMCwz5rMsIXm64yWX5A3YyWJIDiFXXmfnuBryv0NaVf65b UC4NhYeiI9U1ChQX6iGWnD3/HIkJpl/DH71VATPO8pxHCIPcXeWaWuL1fOecsMKy8wie q9TGeEXcy1gl/Zte/mGtHhAtIP+mPyPywNeWv8CdgOMJkIWpAy/woRmVvMcSLRLniEL6 BhIw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a63si630144pla.54.2019.08.18.00.29.58; Sun, 18 Aug 2019 00:30:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726400AbfHRH2y (ORCPT + 99 others); Sun, 18 Aug 2019 03:28:54 -0400 Received: from mail-yb1-f195.google.com ([209.85.219.195]:42218 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726073AbfHRH2y (ORCPT ); Sun, 18 Aug 2019 03:28:54 -0400 Received: by mail-yb1-f195.google.com with SMTP id h8so3330259ybq.9 for ; Sun, 18 Aug 2019 00:28:53 -0700 (PDT) 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; bh=o9Rkq3dkBHyl5deQARpSgyWUVR/JbkupDTFCJi/n5xw=; b=m0M0wTe2vd4i264b75gFhQeonve+s/aH/LsA6GoJi4t0KTiKXy9o3xos/eZV9h3G3Z imOHWmtir4bOCYxDQ5L//jnrHanHeqW4sbZOHpVzlH3n4tjseQdhQLw8V8JnULqVamLr 3kw9nDdaskKSYv3oDKXYIDjHT42iOxZKgtQXtWdUr/Mp1maZHbr4MOGjV+mB6l2okh1U oPL0P2zVrdlckf3TMkwviUMBinYCIvMArR6KRk8qGAnhKaXf8Q5H7Z8KKLz3dvRf2xRT akbOmbYLgJz3NspWtg4UZv11qyK06dF2VzwDdaFEIOrAVZKr2Pteqp7zqSKkybHvZAIN TYhQ== X-Gm-Message-State: APjAAAVp3Tl14t6RR3ghppFHSUD8gfCaQmv121l6tMCrQPY4mh4de5S9 1psrr36VKPmmpVfQqLaFpBQ= X-Received: by 2002:a25:d143:: with SMTP id i64mr12704171ybg.111.1566113333214; Sun, 18 Aug 2019 00:28:53 -0700 (PDT) Received: from localhost.localdomain (24-158-240-219.dhcp.smyr.ga.charter.com. [24.158.240.219]) by smtp.gmail.com with ESMTPSA id j130sm2396856ywg.31.2019.08.18.00.28.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 18 Aug 2019 00:28:52 -0700 (PDT) From: Wenwen Wang To: Wenwen Wang Cc: Miquel Raynal , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , Vignesh Raghavendra , Boris Brezillon , Frieder Schrempf , Greg Kroah-Hartman , Allison Randal , Randy Dunlap , Thomas Gleixner , linux-mtd@lists.infradead.org (open list:NAND FLASH SUBSYSTEM), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] mtd: rawnand: Fix a memory leak bug Date: Sun, 18 Aug 2019 02:28:40 -0500 Message-Id: <1566113321-4464-1-git-send-email-wenwen@cs.uga.edu> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In nand_scan_bbt(), a temporary buffer 'buf' is allocated through vmalloc(). However, if check_create() fails, 'buf' is not deallocated, leading to a memory leak bug. To fix this issue, free 'buf' before returning the error. Signed-off-by: Wenwen Wang --- drivers/mtd/nand/raw/nand_bbt.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_bbt.c b/drivers/mtd/nand/raw/nand_bbt.c index 2ef15ef..864a00a 100644 --- a/drivers/mtd/nand/raw/nand_bbt.c +++ b/drivers/mtd/nand/raw/nand_bbt.c @@ -1245,7 +1245,7 @@ static int nand_scan_bbt(struct nand_chip *this, struct nand_bbt_descr *bd) buf = vmalloc(len); if (!buf) { res = -ENOMEM; - goto err; + goto err_free_bbt; } /* Is the bbt at a given page? */ @@ -1258,7 +1258,7 @@ static int nand_scan_bbt(struct nand_chip *this, struct nand_bbt_descr *bd) res = check_create(this, buf, bd); if (res) - goto err; + goto err_free_buf; /* Prevent the bbt regions from erasing / writing */ mark_bbt_region(this, td); @@ -1268,7 +1268,9 @@ static int nand_scan_bbt(struct nand_chip *this, struct nand_bbt_descr *bd) vfree(buf); return 0; -err: +err_free_buf: + vfree(buf); +err_free_bbt: kfree(this->bbt); this->bbt = NULL; return res; -- 2.7.4