mtd: speedtest: fix integer overflow
Linux-MTD Mailing List
linux-mtd at lists.infradead.org
Fri Mar 11 10:59:06 EST 2011
Gitweb: http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=e70727e442eb61581f836a9a0ca0c3b70d8a3ff2
Commit: e70727e442eb61581f836a9a0ca0c3b70d8a3ff2
Parent: 5d9d9936209e589569a97985285b3282310cf2db
Author: David Lambert <dave at lambsys.com>
AuthorDate: Mon Mar 7 12:00:46 2011 +0200
Committer: David Woodhouse <David.Woodhouse at intel.com>
CommitDate: Fri Mar 11 14:22:49 2011 +0000
mtd: speedtest: fix integer overflow
32-bit integers used in 'calc_speed()' may overflow and lead to
incorrect results. Use 64-bit integers instead.
Signed-off-by: David Lambert <dave at lambsys.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy at nokia.com>
Signed-off-by: David Woodhouse <David.Woodhouse at intel.com>
---
drivers/mtd/tests/mtd_speedtest.c | 14 +++++++-------
1 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/mtd/tests/mtd_speedtest.c b/drivers/mtd/tests/mtd_speedtest.c
index 3ce6fce..627d4e2 100644
--- a/drivers/mtd/tests/mtd_speedtest.c
+++ b/drivers/mtd/tests/mtd_speedtest.c
@@ -314,16 +314,16 @@ static inline void stop_timing(void)
static long calc_speed(void)
{
- long ms, k, speed;
+ uint64_t k;
+ long ms;
ms = (finish.tv_sec - start.tv_sec) * 1000 +
(finish.tv_usec - start.tv_usec) / 1000;
- k = goodebcnt * mtd->erasesize / 1024;
- if (ms)
- speed = (k * 1000) / ms;
- else
- speed = 0;
- return speed;
+ if (ms == 0)
+ return 0;
+ k = goodebcnt * (mtd->erasesize / 1024) * 1000;
+ do_div(k, ms);
+ return k;
}
static int scan_for_bad_eraseblocks(void)
More information about the linux-mtd-cvs
mailing list