From: Jason Liu Date: Fri, 19 Nov 2010 08:40:45 +0000 (+0800) Subject: mtd: nand: add check for out of page read X-Git-Tag: v2.6.38-rc1~21^2~35 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=e14feafbe0d5c6d64bb6fe4eba928cb57ac9a4c8;p=karo-tx-linux.git mtd: nand: add check for out of page read When run mtd_oobtest case, there will be one error for step(4), which turned out it need add one check for out of page read in nand_do_read_oob just like mtd_do_write_oob did it already. This commit also fix one typo error for comments in mtd_do_write_oob Signed-off-by: Jason Liu Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 1f75a1b1f7c3..75d199e4f25b 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -1782,6 +1782,13 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from, else len = mtd->oobsize; + /* Do not allow read past end of page */ + if ((ops->ooboffs + readlen) > len) { + DEBUG(MTD_DEBUG_LEVEL0, "%s: Attempt to read " + "past end of page\n", __func__); + return -EINVAL; + } + if (unlikely(ops->ooboffs >= len)) { DEBUG(MTD_DEBUG_LEVEL0, "%s: Attempt to start read " "outside oob\n", __func__); @@ -2377,7 +2384,7 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, return -EINVAL; } - /* Do not allow reads past end of device */ + /* Do not allow write past end of device */ if (unlikely(to >= mtd->size || ops->ooboffs + ops->ooblen > ((mtd->size >> chip->page_shift) -