From 1e271b21a989657bc569ea8174218ab371935fe8 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Mon, 27 Jul 2015 12:26:12 -0600 Subject: [PATCH] Fix potential divide-by-zero in calc_rate() Signed-off-by: Jens Axboe --- eta.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/eta.c b/eta.c index aed61ecc..f608c4e5 100644 --- a/eta.c +++ b/eta.c @@ -290,14 +290,19 @@ static void calc_rate(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_rate; diff = io_bytes[i] - prev_io_bytes[i]; + if (mtime) + this_rate = ((1000 * diff) / mtime) / 1024; + else + this_rate = 0; + if (unified_rw_rep) { rate[i] = 0; - rate[0] += ((1000 * diff) / mtime) / 1024; + rate[0] += this_rate; } else - rate[i] = ((1000 * diff) / mtime) / 1024; + rate[i] = this_rate; prev_io_bytes[i] = io_bytes[i]; } -- 2.25.1