MTD NAND: Check if block number is out of ragne at top of loop, not bottom, to avoid some bogus transfers

This commit is contained in:
Gregory Nutt 2013-12-05 18:19:48 -06:00
parent 40e0253189
commit ed9756c137
2 changed files with 27 additions and 14 deletions

View File

@ -6164,4 +6164,7 @@
from FLASH (2013-12-05).
* fs/fat/fs_configfat.c: Fix a typo in the FAT16 formatting logic.
Was this ever able to format a FAT16 disk? (2013-12-05).
* drivers/mtd/mtd_nand.c: Check if block number is within range at
the top of the loop not the bottom. Otherwise, we will do a bogus
transfer with the out-of-range block before we test it (2013-12-05).

View File

@ -638,6 +638,17 @@ static ssize_t nand_bread(struct mtd_dev_s *dev, off_t startpage,
for (remaining = npages; remaining > 0; remaining--)
{
/* Check for attempt to read beyond the end of NAND */
if (block > maxblock)
{
fdbg("ERROR: Read beyond the end of FLASH, block=%ld\n",
(long)block);
ret = -ESPIPE;
goto errout_with_lock;
}
/* Read the next page from NAND */
ret = nand_readpage(nand, block, page, buffer);
@ -656,13 +667,7 @@ static ssize_t nand_bread(struct mtd_dev_s *dev, off_t startpage,
if (++page >= pagesperblock)
{
page = 0;
if (++block > maxblock)
{
fdbg("ERROR: Read beyond the end of FLASH, block=%d\n",
block);
ret = -ESPIPE;
goto errout_with_lock;
}
block++;
}
/* Increment the buffer point by the size of one page */
@ -729,6 +734,17 @@ static ssize_t nand_bwrite(struct mtd_dev_s *dev, off_t startpage,
for (remaining = npages; remaining > 0; remaining--)
{
/* Check for attempt to write beyond the end of NAND */
if (block > maxblock)
{
fdbg("ERROR: Write beyond the end of FLASH, block=%ld\n",
(long)block);
ret = -ESPIPE;
goto errout_with_lock;
}
/* Write the next page into NAND */
ret = nand_writepage(nand, block, page, buffer);
@ -747,13 +763,7 @@ static ssize_t nand_bwrite(struct mtd_dev_s *dev, off_t startpage,
if (++page >= pagesperblock)
{
page = 0;
if (++block > maxblock)
{
fdbg("ERROR: Write beyond the end of FLASH, block=%d\n",
block);
ret = -ESPIPE;
goto errout_with_lock;
}
block++;
}
/* Increment the buffer point by the size of one page */