mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2025-01-18 20:04:16 +08:00
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>
This commit is contained in:
parent
5d9d993620
commit
e70727e442
@ -314,16 +314,16 @@ static inline void stop_timing(void)
|
|||||||
|
|
||||||
static long calc_speed(void)
|
static long calc_speed(void)
|
||||||
{
|
{
|
||||||
long ms, k, speed;
|
uint64_t k;
|
||||||
|
long ms;
|
||||||
|
|
||||||
ms = (finish.tv_sec - start.tv_sec) * 1000 +
|
ms = (finish.tv_sec - start.tv_sec) * 1000 +
|
||||||
(finish.tv_usec - start.tv_usec) / 1000;
|
(finish.tv_usec - start.tv_usec) / 1000;
|
||||||
k = goodebcnt * mtd->erasesize / 1024;
|
if (ms == 0)
|
||||||
if (ms)
|
return 0;
|
||||||
speed = (k * 1000) / ms;
|
k = goodebcnt * (mtd->erasesize / 1024) * 1000;
|
||||||
else
|
do_div(k, ms);
|
||||||
speed = 0;
|
return k;
|
||||||
return speed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int scan_for_bad_eraseblocks(void)
|
static int scan_for_bad_eraseblocks(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user