Skip to content

Commit

Permalink
mtd: nand: add check for out of page read
Browse files Browse the repository at this point in the history
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 <r64343@freescale.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
Jason Liu authored and David Woodhouse committed Dec 3, 2010
1 parent 1534b8b commit e14feaf
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion drivers/mtd/nand/nand_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
Expand Down Expand Up @@ -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) -
Expand Down

0 comments on commit e14feaf

Please sign in to comment.