summaryrefslogtreecommitdiff
path: root/nuttx/drivers/mtd/smart.c
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-07-03 18:14:51 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-07-03 18:14:51 -0600
commit80559ac5add5a6ffb0ad3083eeff50002d036d2f (patch)
tree4a495a328823cb8a1612490539ef5a58e9a3476d /nuttx/drivers/mtd/smart.c
parentc22fa6e2d573dac1191e6896f66ac227d4873bf4 (diff)
downloadpx4-nuttx-80559ac5add5a6ffb0ad3083eeff50002d036d2f.tar.gz
px4-nuttx-80559ac5add5a6ffb0ad3083eeff50002d036d2f.tar.bz2
px4-nuttx-80559ac5add5a6ffb0ad3083eeff50002d036d2f.zip
Fix for a bug that would show up if CONFIG_MTD_BYTE_WRITE was not selected and the SMART sector size was larger than the mtd device's block size (like it would be if using SMARTFS on larger flash devices). From Ken Pettit
Diffstat (limited to 'nuttx/drivers/mtd/smart.c')
-rw-r--r--nuttx/drivers/mtd/smart.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/nuttx/drivers/mtd/smart.c b/nuttx/drivers/mtd/smart.c
index c999ffee5..ea1fe387d 100644
--- a/nuttx/drivers/mtd/smart.c
+++ b/nuttx/drivers/mtd/smart.c
@@ -578,7 +578,9 @@ static ssize_t smart_bytewrite(struct smart_struct_s *dev, size_t offset,
/* First calculate the start block and number of blocks affected */
startblock = offset / dev->geo.blocksize;
- nblocks = (nbytes + dev->geo.blocksize-1) / dev->geo.blocksize;
+ nblocks = (offset - startblock * dev->geo.blocksize + nbytes +
+ dev->geo.blocksize-1) / dev->geo.blocksize;
+
DEBUGASSERT(nblocks <= dev->mtdBlksPerSector);
/* Do a block read */