From patchwork Wed Dec 2 14:28:08 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [RFC,MTD-UTILS] : flash_lock: fix length being passed Date: Wed, 02 Dec 2009 04:28:08 -0000 From: vimal singh X-Patchwork-Id: 40046 Message-Id: To: Linux MTD This patch fixes the 'length' calculation. Making it: + mtdLockInfo.length = (num_sectors - 1) * mtdInfo.erasesize; Rather: - mtdLockInfo.length = num_sectors * mtdInfo.erasesize; Say there are 240 blocks present in the device. Then: offset starts from: 0x0 and full size of device: 0x1E00000 doing: 240 * 0x20000 gives -> 0x1E00000 But last block address should be 0x1DE0000 (which spans for 0x20000 bytes, adding upto size of 0x1E00000) Signed-off-by: Vimal Singh --- --- flash_lock.c.org 2009-11-24 19:33:18.000000000 +0530 +++ flash_lock.c 2009-11-24 19:33:13.000000000 +0530 @@ -71,7 +71,7 @@ int main(int argc, char *argv[]) } mtdLockInfo.start = ofs; - mtdLockInfo.length = num_sectors * mtdInfo.erasesize; + mtdLockInfo.length = (num_sectors - 1) * mtdInfo.erasesize; if(ioctl(fd, MEMLOCK, &mtdLockInfo)) { fprintf(stderr, "Could not lock MTD device: %s\n", argv[1]); @@ -81,4 +81,3 @@ int main(int argc, char *argv[]) return 0; } -