summaryrefslogtreecommitdiffstats
path: root/drivers/mtd/nand/sunxi_nand.c
diff options
context:
space:
mode:
authorDan Carpenter <dan.carpenter@oracle.com>2016-06-24 14:24:03 +0200
committerBoris Brezillon <boris.brezillon@free-electrons.com>2016-07-11 08:40:18 +0200
commit40297e7f897281aa7bd61bf1323837a11a10479f (patch)
treeac2e9dbb110c308f8d0ee52419a9b1b02ad47758 /drivers/mtd/nand/sunxi_nand.c
parentmtd: nand: sunxi: add reset line support (diff)
downloadlinux-40297e7f897281aa7bd61bf1323837a11a10479f.tar.xz
linux-40297e7f897281aa7bd61bf1323837a11a10479f.zip
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>
Diffstat (limited to 'drivers/mtd/nand/sunxi_nand.c')
-rw-r--r--drivers/mtd/nand/sunxi_nand.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/drivers/mtd/nand/sunxi_nand.c b/drivers/mtd/nand/sunxi_nand.c
index d2b7457d447f..e414b31b71c1 100644
--- a/drivers/mtd/nand/sunxi_nand.c
+++ b/drivers/mtd/nand/sunxi_nand.c
@@ -1814,13 +1814,13 @@ static int sunxi_nand_hw_common_ecc_ctrl_init(struct mtd_info *mtd,
int ret;
int i;
+ if (ecc->size != 512 && ecc->size != 1024)
+ return -EINVAL;
+
data = kzalloc(sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;
- if (ecc->size != 512 && ecc->size != 1024)
- return -EINVAL;
-
/* Prefer 1k ECC chunk over 512 ones */
if (ecc->size == 512 && mtd->writesize > 512) {
ecc->size = 1024;