mtd: nand: sunxi: prevent a small memory leak
Linux-MTD Mailing List
linux-mtd at lists.infradead.org
Mon Aug 1 18:59:08 PDT 2016
Gitweb: http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=40297e7f897281aa7bd61bf1323837a11a10479f
Commit: 40297e7f897281aa7bd61bf1323837a11a10479f
Parent: ab9d6a783544bbf8834277f8409048ddc35712ed
Author: Dan Carpenter <dan.carpenter at oracle.com>
AuthorDate: Fri Jun 24 15:24:03 2016 +0300
Committer: Boris Brezillon <boris.brezillon at free-electrons.com>
CommitDate: Mon Jul 11 08:40:18 2016 +0200
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 at oracle.com>
Signed-off-by: Boris Brezillon <boris.brezillon at free-electrons.com>
---
drivers/mtd/nand/sunxi_nand.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/mtd/nand/sunxi_nand.c b/drivers/mtd/nand/sunxi_nand.c
index d2b7457..e414b31 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;
More information about the linux-mtd-cvs
mailing list