mtd: nand_bbt: unify/fix error handling in nand_scan_bbt()
Don't leak this->bbt, and return early if check_create() fails. It helps to have a single error path to avoid these problems. Signed-off-by: Brian Norris <computersforpeace@gmail.com>
This commit is contained in:
@@ -1077,7 +1077,7 @@ static void verify_bbt_descr(struct mtd_info *mtd, struct nand_bbt_descr *bd)
|
|||||||
static int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
|
static int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
|
||||||
{
|
{
|
||||||
struct nand_chip *this = mtd->priv;
|
struct nand_chip *this = mtd->priv;
|
||||||
int len, res = 0;
|
int len, res;
|
||||||
uint8_t *buf;
|
uint8_t *buf;
|
||||||
struct nand_bbt_descr *td = this->bbt_td;
|
struct nand_bbt_descr *td = this->bbt_td;
|
||||||
struct nand_bbt_descr *md = this->bbt_md;
|
struct nand_bbt_descr *md = this->bbt_md;
|
||||||
@@ -1098,10 +1098,9 @@ static int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
|
|||||||
if (!td) {
|
if (!td) {
|
||||||
if ((res = nand_memory_bbt(mtd, bd))) {
|
if ((res = nand_memory_bbt(mtd, 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");
|
||||||
kfree(this->bbt);
|
goto err;
|
||||||
this->bbt = NULL;
|
|
||||||
}
|
}
|
||||||
return res;
|
return 0;
|
||||||
}
|
}
|
||||||
verify_bbt_descr(mtd, td);
|
verify_bbt_descr(mtd, td);
|
||||||
verify_bbt_descr(mtd, md);
|
verify_bbt_descr(mtd, md);
|
||||||
@@ -1111,9 +1110,8 @@ static int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
|
|||||||
len += (len >> this->page_shift) * mtd->oobsize;
|
len += (len >> this->page_shift) * mtd->oobsize;
|
||||||
buf = vmalloc(len);
|
buf = vmalloc(len);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
kfree(this->bbt);
|
res = -ENOMEM;
|
||||||
this->bbt = NULL;
|
goto err;
|
||||||
return -ENOMEM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Is the bbt at a given page? */
|
/* Is the bbt at a given page? */
|
||||||
@@ -1125,6 +1123,8 @@ static int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
res = check_create(mtd, buf, bd);
|
res = check_create(mtd, buf, bd);
|
||||||
|
if (res)
|
||||||
|
goto err;
|
||||||
|
|
||||||
/* Prevent the bbt regions from erasing / writing */
|
/* Prevent the bbt regions from erasing / writing */
|
||||||
mark_bbt_region(mtd, td);
|
mark_bbt_region(mtd, td);
|
||||||
@@ -1132,6 +1132,11 @@ static int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
|
|||||||
mark_bbt_region(mtd, md);
|
mark_bbt_region(mtd, md);
|
||||||
|
|
||||||
vfree(buf);
|
vfree(buf);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
err:
|
||||||
|
kfree(this->bbt);
|
||||||
|
this->bbt = NULL;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user