From f881abe2dac8a917bbc01cc1b3eeb0378afad644 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 3 Jul 2014 18:14:51 -0600 Subject: [PATCH] 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 --- drivers/mtd/smart.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/smart.c b/drivers/mtd/smart.c index c999ffee5ff..ea1fe387df5 100644 --- a/drivers/mtd/smart.c +++ b/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 */