drivers/mtd/smart.c: Fix a Smart wear-leveling bug. From Ken Petit

This commit is contained in:
Ken Pettit 2015-11-18 07:01:13 -06:00 committed by Gregory Nutt
parent 7e58e4c4cf
commit f0f7dd9956
2 changed files with 6 additions and 3 deletions

View File

@ -11107,3 +11107,5 @@
CRC calculation. From Karim Keddam (2015-11-17).
* drivers/mtd/w25.c: Fix W25 FLASH driver page read/write logic. From
Ken Petit (2015-11-18).
* drivers/mtd/smart.c: Fix a Smart wear-leveling bug. From Ken Petit
(2015-11-18).

View File

@ -3895,9 +3895,9 @@ static inline int smart_read_wearstatus(FAR struct smart_struct_s *dev)
/* Calculate number of bytes to read from this sector */
toread = remaining;
if (toread > dev->sectorsize - SMARTFS_FMT_WEAR_POS)
if (toread > dev->sectorsize - (SMARTFS_FMT_WEAR_POS + sizeof(struct smart_sect_header_s)))
{
toread = dev->sectorsize - SMARTFS_FMT_WEAR_POS;
toread = dev->sectorsize - (SMARTFS_FMT_WEAR_POS + sizeof(struct smart_sect_header_s));
}
/* Setup the sector read request (we are our own client) */
@ -4509,7 +4509,8 @@ static int smart_readsector(FAR struct smart_struct_s *dev,
fvdbg("Entry\n");
req = (FAR struct smart_read_write_s *) arg;
DEBUGASSERT(req->offset < dev->sectorsize);
DEBUGASSERT(req->offset+req->count < dev->sectorsize);
DEBUGASSERT(req->offset+req->count+ sizeof(struct smart_sect_header_s) <=
dev->sectorsize);
/* Ensure the logical sector has been allocated */