mtd: rawnand: Fix a memory leak bug
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> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
This commit is contained in:
parent
d83aef09aa
commit
86aa04f4c2
|
@ -1232,7 +1232,7 @@ static int nand_scan_bbt(struct nand_chip *this, struct nand_bbt_descr *bd)
|
||||||
if (!td) {
|
if (!td) {
|
||||||
if ((res = nand_memory_bbt(this, bd))) {
|
if ((res = nand_memory_bbt(this, bd))) {
|
||||||
pr_err("nand_bbt: can't scan flash and build the RAM-based BBT\n");
|
pr_err("nand_bbt: can't scan flash and build the RAM-based BBT\n");
|
||||||
goto err;
|
goto err_free_bbt;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1245,7 +1245,7 @@ static int nand_scan_bbt(struct nand_chip *this, struct nand_bbt_descr *bd)
|
||||||
buf = vmalloc(len);
|
buf = vmalloc(len);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
res = -ENOMEM;
|
res = -ENOMEM;
|
||||||
goto err;
|
goto err_free_bbt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Is the bbt at a given page? */
|
/* 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);
|
res = check_create(this, buf, bd);
|
||||||
if (res)
|
if (res)
|
||||||
goto err;
|
goto err_free_buf;
|
||||||
|
|
||||||
/* Prevent the bbt regions from erasing / writing */
|
/* Prevent the bbt regions from erasing / writing */
|
||||||
mark_bbt_region(this, td);
|
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);
|
vfree(buf);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err:
|
err_free_buf:
|
||||||
|
vfree(buf);
|
||||||
|
err_free_bbt:
|
||||||
kfree(this->bbt);
|
kfree(this->bbt);
|
||||||
this->bbt = NULL;
|
this->bbt = NULL;
|
||||||
return res;
|
return res;
|
||||||
|
|
Loading…
Reference in New Issue