All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Glauber <jglauber@cavium.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: "David S . Miller" <davem@davemloft.net>,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
	Mahipal Challa <Mahipal.Challa@cavium.com>,
	Robert Richter <rrichter@cavium.com>,
	Jan Glauber <jglauber@cavium.com>
Subject: [PATCH v2 3/5] crypto: thunderx_zip: Prevent division by zero
Date: Mon,  9 Apr 2018 17:45:52 +0200	[thread overview]
Message-ID: <20180409154554.7578-4-jglauber@cavium.com> (raw)
In-Reply-To: <20180409154554.7578-1-jglauber@cavium.com>

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>
---
 drivers/crypto/cavium/zip/zip_main.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/cavium/zip/zip_main.c b/drivers/crypto/cavium/zip/zip_main.c
index 1cd8aa488185..79b449e0f955 100644
--- a/drivers/crypto/cavium/zip/zip_main.c
+++ b/drivers/crypto/cavium/zip/zip_main.c
@@ -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"
-- 
2.16.2

  parent reply	other threads:[~2018-04-09 15:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-09 15:45 [PATCH v2 0/5] ThunderX ZIP driver bug fixes Jan Glauber
2018-04-09 15:45 ` [PATCH v2 1/5] crypto: thunderx_zip: Fix fallout from CONFIG_VMAP_STACK Jan Glauber
2018-04-09 15:45 ` [PATCH v2 2/5] crypto: thunderx_zip: Limit result reading attempts Jan Glauber
2018-04-09 15:45 ` Jan Glauber [this message]
2018-04-09 15:45 ` [PATCH v2 4/5] crypto: thunderx_zip: Fix statistics pending request value Jan Glauber
2018-04-09 15:45 ` [PATCH v2 5/5] crypto: thunderx_zip: Fix smp_processor_id() warnings Jan Glauber
2018-04-20 16:51 ` [PATCH v2 0/5] ThunderX ZIP driver bug fixes Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180409154554.7578-4-jglauber@cavium.com \
    --to=jglauber@cavium.com \
    --cc=Mahipal.Challa@cavium.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rrichter@cavium.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.