lkml.org 
[lkml]   [2018]   [Aug]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2] staging: mt29f_spinand: fix memory leak while programming pages
Date
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
\
 
 \ /
  Last update: 2018-08-02 09:52    [W:0.075 / U:0.080 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site