Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2153428ybl; Sun, 18 Aug 2019 19:48:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqyjTCYdxn6son8YRpqltv2eR05ZbaFdLX3JTQ5B73BMpvJb1pMOpuCBPJlXSQk+nrGpl8/Q X-Received: by 2002:a17:902:ba81:: with SMTP id k1mr21226714pls.213.1566182882820; Sun, 18 Aug 2019 19:48:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566182882; cv=none; d=google.com; s=arc-20160816; b=DoeHqMj3mvqhO8gQ5VG+UDZAQZH3UkJVHTyWkJL5wugQjNeJ+iq5VSv+o6pPczZ6GE 0GPsyeCR4JRSsCkBY84zGwIk5DvZleQr9N3I8fqiuP9WazD5Mr5kFtK3NrpHTboF3h36 atYBSopeowk9DdohlMAJTTmPx7CujOYt3dj9AFfZK6FDL80Lyx9zj1LjbcBvPlvSeqNq xxEDEWcQSKxf+1ayxM+vIBQepYUXm6ArzdduDWqLghQ5laXK2QXT9V6vJVReszhEeN0s Ydp2aoBkkw54Z+MvCKG8YUJmK5j+f307Vd7JOvEnM/l/n/KoBdO5hcwyvp87l3/pyP3Q PZVA== 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=wGyW4pmaDvW/xobvRCheZylYnIK2Mlk/QoBxdqMYERo=; b=anajW7DFrE75XUj8gvrZFlBfCcCxEYaNAQhqDmYMTMN5PhWDu831Bi3K8LMXWx9w+R m31eyiACd/zLWQ/PvdT+ub/0Gtk4tfOU5GTJYGEU90DO9NZKkafiVDk0mUXfkXUOoSV3 W1xnsynAfDKThNdo1mcC/IptaxaV3k5CVyiJFeg7KlA1N/yCECosFnvsqle72P3FzGpm Sa9UiZebrXFLpTWSOCytoj8FR4eW9Bg6FW3juSYeHizCvtcVhCEdvY0NzHImudbJ+M/d UIr1rFRfRiTkPKEoClp0BAhBEbpfQ0cSxB3t0lV821naOvlKI+YuGPLCXnv6xLq3SEEt enIQ== 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 s31si9004599plb.362.2019.08.18.19.47.37; Sun, 18 Aug 2019 19:48:02 -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 S1726281AbfHSCqN (ORCPT + 99 others); Sun, 18 Aug 2019 22:46:13 -0400 Received: from mail-yw1-f65.google.com ([209.85.161.65]:42937 "EHLO mail-yw1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726132AbfHSCqN (ORCPT ); Sun, 18 Aug 2019 22:46:13 -0400 Received: by mail-yw1-f65.google.com with SMTP id z63so117404ywz.9 for ; Sun, 18 Aug 2019 19:46:12 -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=wGyW4pmaDvW/xobvRCheZylYnIK2Mlk/QoBxdqMYERo=; b=O8wURTL7Pmq9H0Brh31yayN5tSkyan97DBe/UbyblOSm+JTV51Fb6CVHedeGIDlmc3 RVweYJnqv6WROXoofXdHyMFxiCQ7Ko6rZnPbMwpXr8Zl22Yg+Zrj9kiA0QaD8LplDPNT f4eAeVxCyAmx49bONKY3zPuHTaTn1s9GZZWdo5wDOZzs2OS3fHy2iyAXAAGqmb6ERia6 bEOvfh9LLOKzAIP+3jKzEhzJOJdrTLO/KsirtyU8FNbP1E6fbEb7LNHIqPZrnxH0HHW1 eX/eH4Z6Y+MxWJWM5rtoH71RyCbJUaFlnSW25OSpnQJqTi87T/6ltkGGw8rQ0FdyBdVf p3Aw== X-Gm-Message-State: APjAAAU4zBTxIzHi6oBNUgQlSLdcsrw17C+6NgRqv6YUEnRqk0gAoXmF 2cqwTrtaRKhEVw5to4U4SpU= X-Received: by 2002:a81:ae55:: with SMTP id g21mr14907282ywk.222.1566182772167; Sun, 18 Aug 2019 19:46:12 -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 r9sm2991434ywl.108.2019.08.18.19.46.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 18 Aug 2019 19:46:11 -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 , Thomas Gleixner , Kate Stewart , Randy Dunlap , linux-mtd@lists.infradead.org (open list:NAND FLASH SUBSYSTEM), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2] mtd: rawnand: Fix a memory leak bug Date: Sun, 18 Aug 2019 21:46:04 -0500 Message-Id: <1566182765-7150-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 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_bbt.c b/drivers/mtd/nand/raw/nand_bbt.c index 2ef15ef..96045d6 100644 --- a/drivers/mtd/nand/raw/nand_bbt.c +++ b/drivers/mtd/nand/raw/nand_bbt.c @@ -1232,7 +1232,7 @@ static int nand_scan_bbt(struct nand_chip *this, struct nand_bbt_descr *bd) if (!td) { if ((res = nand_memory_bbt(this, bd))) { pr_err("nand_bbt: can't scan flash and build the RAM-based BBT\n"); - goto err; + goto err_free_bbt; } return 0; } @@ -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