mtd: nand: sunxi: check ecc->size values

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Mon Aug 1 18:59:06 PDT 2016


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=a92c721dc638b3745266ffe85617fe54dfadff19
Commit:     a92c721dc638b3745266ffe85617fe54dfadff19
Parent:     872164e41fc8dee154e5f5d22580b34e198eed69
Author:     Boris Brezillon <boris.brezillon at free-electrons.com>
AuthorDate: Mon Jun 6 13:59:13 2016 +0200
Committer:  Boris Brezillon <boris.brezillon at free-electrons.com>
CommitDate: Mon Jul 11 08:40:12 2016 +0200

    mtd: nand: sunxi: check ecc->size values
    
    Verify that the ecc->size value is either 512 or 1024 bytes.
    This should always be the case if this field was assigned to the
    nand->ecc_step_size_ds value, but can be wrong when the user overloaded
    this value with the nand-ecc-step-size DT property.
    
    Signed-off-by: Boris Brezillon <boris.brezillon at free-electrons.com>
---
 drivers/mtd/nand/sunxi_nand.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/mtd/nand/sunxi_nand.c b/drivers/mtd/nand/sunxi_nand.c
index bb440b9..6e319ba 100644
--- a/drivers/mtd/nand/sunxi_nand.c
+++ b/drivers/mtd/nand/sunxi_nand.c
@@ -1786,6 +1786,9 @@ static int sunxi_nand_hw_common_ecc_ctrl_init(struct mtd_info *mtd,
 	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