From 95c2f38e08f135571a86f46d14291a4e0ff1c1d7 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Mon, 27 Jul 2015 12:29:55 -0600 Subject: [PATCH] Fix potential divide-by-zero in calc_iops() Signed-off-by: Jens Axboe --- eta.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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]; } -- 2.25.1