Skip to content

Commit

Permalink
crypto: cavium - Prevent division by zero
Browse files Browse the repository at this point in the history
Avoid two potential divisions by zero when calculating average
values for the zip statistics.

Signed-off-by: Jan Glauber <jglauber@cavium.com>
Reviewed-by: Robert Richter <rrichter@cavium.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
Jan Glauber authored and Herbert Xu committed Apr 20, 2018
1 parent c782a8c commit a40c880
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions drivers/crypto/cavium/zip/zip_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,11 @@ static int zip_show_stats(struct seq_file *s, void *unused)
atomic64_add(val, &st->pending_req);
}

avg_chunk = (atomic64_read(&st->comp_in_bytes) /
atomic64_read(&st->comp_req_complete));
avg_cr = (atomic64_read(&st->comp_in_bytes) /
atomic64_read(&st->comp_out_bytes));
val = atomic64_read(&st->comp_req_complete);
avg_chunk = (val) ? atomic64_read(&st->comp_in_bytes) / val : 0;

val = atomic64_read(&st->comp_out_bytes);
avg_cr = (val) ? atomic64_read(&st->comp_in_bytes) / val : 0;
seq_printf(s, " ZIP Device %d Stats\n"
"-----------------------------------\n"
"Comp Req Submitted : \t%lld\n"
Expand Down

0 comments on commit a40c880

Please sign in to comment.