* [PATCH v2] mtd: rawnand: Fix a memory leak bug
@ 2019-08-19 2:46 ` Wenwen Wang
0 siblings, 0 replies; 6+ messages in thread
From: Wenwen Wang @ 2019-08-19 2:46 UTC (permalink / raw)
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,
open list:NAND FLASH SUBSYSTEM, open list
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 <wenwen@cs.uga.edu>
---
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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2] mtd: rawnand: Fix a memory leak bug
@ 2019-08-19 2:46 ` Wenwen Wang
0 siblings, 0 replies; 6+ messages in thread
From: Wenwen Wang @ 2019-08-19 2:46 UTC (permalink / raw)
To: Wenwen Wang
Cc: Kate Stewart, Vignesh Raghavendra, Boris Brezillon,
Richard Weinberger, Randy Dunlap, open list, Frieder Schrempf,
Marek Vasut, open list:NAND FLASH SUBSYSTEM, Miquel Raynal,
Thomas Gleixner, Brian Norris, David Woodhouse
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 <wenwen@cs.uga.edu>
---
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
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] mtd: rawnand: Fix a memory leak bug
2019-08-19 2:46 ` Wenwen Wang
@ 2019-08-26 12:59 ` Miquel Raynal
-1 siblings, 0 replies; 6+ messages in thread
From: Miquel Raynal @ 2019-08-26 12:59 UTC (permalink / raw)
To: Wenwen Wang
Cc: Miquel Raynal, Kate Stewart, Vignesh Raghavendra,
Boris Brezillon, Richard Weinberger, Randy Dunlap, open list,
Frieder Schrempf, Marek Vasut, open list:NAND FLASH SUBSYSTEM,
Thomas Gleixner, Brian Norris, David Woodhouse
On Mon, 2019-08-19 at 02:46:04 UTC, Wenwen Wang wrote:
> 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 <wenwen@cs.uga.edu>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.
Miquel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] mtd: rawnand: Fix a memory leak bug
@ 2019-08-26 12:59 ` Miquel Raynal
0 siblings, 0 replies; 6+ messages in thread
From: Miquel Raynal @ 2019-08-26 12:59 UTC (permalink / raw)
To: Wenwen Wang
Cc: Kate Stewart, Vignesh Raghavendra, Boris Brezillon,
Richard Weinberger, Randy Dunlap, open list, Frieder Schrempf,
Marek Vasut, open list:NAND FLASH SUBSYSTEM, Miquel Raynal,
Thomas Gleixner, Brian Norris, David Woodhouse
On Mon, 2019-08-19 at 02:46:04 UTC, Wenwen Wang wrote:
> 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 <wenwen@cs.uga.edu>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.
Miquel
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] mtd: rawnand: Fix a memory leak bug
2019-08-19 2:46 ` Wenwen Wang
@ 2019-08-26 13:05 ` Boris Brezillon
-1 siblings, 0 replies; 6+ messages in thread
From: Boris Brezillon @ 2019-08-26 13:05 UTC (permalink / raw)
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,
open list:NAND FLASH SUBSYSTEM, open list
On Sun, 18 Aug 2019 21:46:04 -0500
Wenwen Wang <wenwen@cs.uga.edu> wrote:
> 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 <wenwen@cs.uga.edu>
> ---
> 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);
I know it's too late, but calling
vfree(buf);
here
> 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);
instead of here would have fixed the leak without the need for an extra
err label.
> return 0;
>
> -err:
> +err_free_buf:
> + vfree(buf);
> +err_free_bbt:
> kfree(this->bbt);
> this->bbt = NULL;
> return res;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] mtd: rawnand: Fix a memory leak bug
@ 2019-08-26 13:05 ` Boris Brezillon
0 siblings, 0 replies; 6+ messages in thread
From: Boris Brezillon @ 2019-08-26 13:05 UTC (permalink / raw)
To: Wenwen Wang
Cc: Kate Stewart, Vignesh Raghavendra, Boris Brezillon,
Richard Weinberger, Randy Dunlap, open list, Frieder Schrempf,
Marek Vasut, open list:NAND FLASH SUBSYSTEM, Miquel Raynal,
Thomas Gleixner, Brian Norris, David Woodhouse
On Sun, 18 Aug 2019 21:46:04 -0500
Wenwen Wang <wenwen@cs.uga.edu> wrote:
> 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 <wenwen@cs.uga.edu>
> ---
> 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);
I know it's too late, but calling
vfree(buf);
here
> 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);
instead of here would have fixed the leak without the need for an extra
err label.
> return 0;
>
> -err:
> +err_free_buf:
> + vfree(buf);
> +err_free_bbt:
> kfree(this->bbt);
> this->bbt = NULL;
> return res;
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-08-26 13:06 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-19 2:46 [PATCH v2] mtd: rawnand: Fix a memory leak bug Wenwen Wang
2019-08-19 2:46 ` Wenwen Wang
2019-08-26 12:59 ` Miquel Raynal
2019-08-26 12:59 ` Miquel Raynal
2019-08-26 13:05 ` Boris Brezillon
2019-08-26 13:05 ` Boris Brezillon
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.