aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/tests
diff options
context:
space:
mode:
authorDavid Lambert <dave@lambsys.com>2011-03-07 05:00:46 -0500
committerDavid Woodhouse <David.Woodhouse@intel.com>2011-03-11 09:22:49 -0500
commite70727e442eb61581f836a9a0ca0c3b70d8a3ff2 (patch)
tree52691fbc86e772642978cc09a32eaaf807ef1016 /drivers/mtd/tests
parent5d9d9936209e589569a97985285b3282310cf2db (diff)
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@lambsys.com> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/mtd/tests')
-rw-r--r--drivers/mtd/tests/mtd_speedtest.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/drivers/mtd/tests/mtd_speedtest.c b/drivers/mtd/tests/mtd_speedtest.c
index 3ce6fce75e07..627d4e2466a3 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)
314 314
315static long calc_speed(void) 315static long calc_speed(void)
316{ 316{
317 long ms, k, speed; 317 uint64_t k;
318 long ms;
318 319
319 ms = (finish.tv_sec - start.tv_sec) * 1000 + 320 ms = (finish.tv_sec - start.tv_sec) * 1000 +
320 (finish.tv_usec - start.tv_usec) / 1000; 321 (finish.tv_usec - start.tv_usec) / 1000;
321 k = goodebcnt * mtd->erasesize / 1024; 322 if (ms == 0)
322 if (ms) 323 return 0;
323 speed = (k * 1000) / ms; 324 k = goodebcnt * (mtd->erasesize / 1024) * 1000;
324 else 325 do_div(k, ms);
325 speed = 0; 326 return k;
326 return speed;
327} 327}
328 328
329static int scan_for_bad_eraseblocks(void) 329static int scan_for_bad_eraseblocks(void)