From: Jens Axboe Date: Mon, 27 Jul 2015 18:29:55 +0000 (-0600) Subject: Fix potential divide-by-zero in calc_iops() X-Git-Tag: fio-2.2.10~31 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=95c2f38e08f135571a86f46d14291a4e0ff1c1d7;hp=1e271b21a989657bc569ea8174218ab371935fe8 Fix potential divide-by-zero in calc_iops() Signed-off-by: Jens Axboe --- diff --git a/eta.c b/eta.c index f608c4e5..db045cb2 100644 --- a/eta.c +++ b/eta.c @@ -315,14 +315,19 @@ static void calc_iops(int unified_rw_rep, unsigned long mtime, int i; for (i = 0; i < DDIR_RWDIR_CNT; i++) { - unsigned long long diff; + unsigned long long diff, this_iops; diff = io_iops[i] - prev_io_iops[i]; + if (mtime) + this_iops = (diff * 1000) / mtime; + else + this_iops = 0; + if (unified_rw_rep) { iops[i] = 0; - iops[0] += (diff * 1000) / mtime; + iops[0] += this_iops; } else - iops[i] = (diff * 1000) / mtime; + iops[i] = this_iops; prev_io_iops[i] = io_iops[i]; }