提交 e70727e4 编写于 作者: D David Lambert 提交者: David Woodhouse

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: NDavid Lambert <dave@lambsys.com>
Signed-off-by: NArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: NDavid Woodhouse <David.Woodhouse@intel.com>
上级 5d9d9936
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册