mtd: speedtest: fix integer overflow
authorDavid Lambert <dave@lambsys.com>
Mon, 7 Mar 2011 10:00:46 +0000 (12:00 +0200)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Fri, 11 Mar 2011 14:22:49 +0000 (14:22 +0000)
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>
drivers/mtd/tests/mtd_speedtest.c

index 3ce6fce75e075401bda65f8edc1140e29775c17a..627d4e2466a3bccbedd3ca27c304f2b47bd414ca 100644 (file)
@@ -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)