diff --git a/ChangeLog b/ChangeLog index 89a5e5ff9ee..26f03abe0b2 100755 --- a/ChangeLog +++ b/ChangeLog @@ -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). diff --git a/drivers/mtd/smart.c b/drivers/mtd/smart.c index 828924418d7..dba51011345 100644 --- a/drivers/mtd/smart.c +++ b/drivers/mtd/smart.c @@ -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 */