All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jheng-Jhong Wu <goodwater.wu@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: goodwater.wu@gmail.com,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2] staging: mt29f_spinand: fix memory leak while programming pages
Date: Thu,  2 Aug 2018 15:51:30 +0800	[thread overview]
Message-ID: <1533196290-9669-1-git-send-email-goodwater.wu@gmail.com> (raw)
In-Reply-To: <1533116658-14924-1-git-send-email-goodwater.wu@gmail.com>

In spinand_program_page(), it uses devm_kzalloc() to allocate memory to
wbuf dynamically if internal ECC is on, but it doesn't free memory
allocated to wbuf at the end of this function. Before the spinand device
is removed and frees memory automatically, programming pages may run many
times. This leads to a memory leak issue when internal ECC is on.

Changelog:

v2:
- use kzalloc()/kfree() to replace devm_kzalloc()/devm_kfree()
- add some descriptions to commit message

Signed-off-by: Jheng-Jhong Wu <goodwater.wu@gmail.com>
---
 drivers/staging/mt29f_spinand/mt29f_spinand.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/mt29f_spinand/mt29f_spinand.c b/drivers/staging/mt29f_spinand/mt29f_spinand.c
index e389009..d740c76 100644
--- a/drivers/staging/mt29f_spinand/mt29f_spinand.c
+++ b/drivers/staging/mt29f_spinand/mt29f_spinand.c
@@ -492,7 +492,7 @@ static int spinand_program_page(struct spi_device *spi_nand,
 #ifdef CONFIG_MTD_SPINAND_ONDIEECC
 	unsigned int i, j;
 
-	wbuf = devm_kzalloc(&spi_nand->dev, CACHE_BUF, GFP_KERNEL);
+	wbuf = kzalloc(CACHE_BUF, GFP_KERNEL);
 	if (!wbuf)
 		return -ENOMEM;
 
@@ -553,6 +553,8 @@ static int spinand_program_page(struct spi_device *spi_nand,
 		}
 		enable_hw_ecc = 0;
 	}
+
+	kfree(wbuf);
 #endif
 
 	return 0;
-- 
2.7.4


  parent reply	other threads:[~2018-08-02  7:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-01  9:44 [PATCH] staging: mt29f_spinand: fix memory leak while programming pages Jheng-Jhong Wu
2018-08-01 11:45 ` Dan Carpenter
     [not found]   ` <CALtPoQCyoe5V0m5=3K1XeZm41aDCaJ0rmYU-a=qkm=Yb8jgMxg@mail.gmail.com>
2018-08-02  3:42     ` Jheng-Jhong Wu
2018-08-02  6:12       ` Dan Carpenter
2018-08-02  7:51 ` Jheng-Jhong Wu [this message]
2018-08-02  8:02   ` [PATCH v2] " Greg Kroah-Hartman
2018-08-02  8:31     ` Jheng-Jhong Wu
2018-08-02  8:41       ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1533196290-9669-1-git-send-email-goodwater.wu@gmail.com \
    --to=goodwater.wu@gmail.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.