mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-05 08:26:59 +00:00
mtd: nand: sunxi: prevent a small memory leak
I moved the sanity check on ecc->size before the allocation so that we don't leak memory on error. Fixes: 05af074a4b73 ('mtd: nand: sunxi: check ecc->size values') Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
This commit is contained in:
parent
ab9d6a7835
commit
40297e7f89
1 changed files with 3 additions and 3 deletions
|
@ -1814,13 +1814,13 @@ static int sunxi_nand_hw_common_ecc_ctrl_init(struct mtd_info *mtd,
|
||||||
int ret;
|
int ret;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (ecc->size != 512 && ecc->size != 1024)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
data = kzalloc(sizeof(*data), GFP_KERNEL);
|
data = kzalloc(sizeof(*data), GFP_KERNEL);
|
||||||
if (!data)
|
if (!data)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
if (ecc->size != 512 && ecc->size != 1024)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
/* Prefer 1k ECC chunk over 512 ones */
|
/* Prefer 1k ECC chunk over 512 ones */
|
||||||
if (ecc->size == 512 && mtd->writesize > 512) {
|
if (ecc->size == 512 && mtd->writesize > 512) {
|
||||||
ecc->size = 1024;
|
ecc->size = 1024;
|
||||||
|
|
Loading…
Reference in a new issue