From 476882d7947f650783b255a8da74954069af90de Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Mon, 14 Apr 2014 09:45:19 -0600 Subject: [PATCH] eta: fix potential divide by zero Signed-off-by: Jens Axboe --- eta.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/eta.c b/eta.c index 42066e0d..7500082f 100644 --- a/eta.c +++ b/eta.c @@ -174,14 +174,26 @@ static int thread_eta(struct thread_data *td) double perc, perc_t; bytes_done = ddir_rw_sum(td->io_bytes); - perc = (double) bytes_done / (double) bytes_total; - if (perc > 1.0) - perc = 1.0; + + if (bytes_total) { + perc = (double) bytes_done / (double) bytes_total; + if (perc > 1.0) + perc = 1.0; + } else + perc = 0.0; if (td->o.time_based) { - perc_t = (double) elapsed / (double) timeout; - if (perc_t < perc) - perc = perc_t; + if (timeout) { + perc_t = (double) elapsed / (double) timeout; + if (perc_t < perc) + perc = perc_t; + } else { + /* + * Will never hit, we can't have time_based + * without a timeout set. + */ + perc = 0.0; + } } eta_sec = (unsigned long) (elapsed * (1.0 / perc)) - elapsed; -- 2.25.1