All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yoshitaka Ikeda <ikeda@nskint.co.jp>
To: Mark Brown <broonie@kernel.org>
Cc: Philipp Zabel <p.zabel@pengutronix.de>,
	"linux-spi@vger.kernel.org" <linux-spi@vger.kernel.org>,
	Masahiro Mizutani <m.mizutani@nskint.co.jp>,
	Ken Kurematsu <k.kurematsu@nskint.co.jp>,
	Yoshitaka Ikeda <ikeda@nskint.co.jp>
Subject: [PATCH v2] spi: spi-cadence-quadspi: Fix division by zero warning
Date: Thu, 15 Jul 2021 00:46:30 +0000	[thread overview]
Message-ID: <362e0cbc-ed82-bf7d-025c-d586d11eaac2@nskint.co.jp> (raw)

Fix below division by zero warning:
- Added an if statement because buswidth can be zero, resulting in division by zero.
- The modified code was based on another driver (atmel-quadspi).

[    0.795337] Division by zero in kernel.
   :
[    0.834051] [<807fd40c>] (__div0) from [<804e1acc>] (Ldiv0+0x8/0x10)
[    0.839097] [<805f0710>] (cqspi_exec_mem_op) from [<805edb4c>] (spi_mem_exec_op+0x3b0/0x3f8)

Signed-off-by: Yoshitaka Ikeda <ikeda@nskint.co.jp>
---
v2:
- Fix commit message.
---
   drivers/spi/spi-cadence-quadspi.c | 10 ++++++----
   1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
index 7a00346ff9b9..13d1f0ce618e 100644
--- a/drivers/spi/spi-cadence-quadspi.c
+++ b/drivers/spi/spi-cadence-quadspi.c
@@ -307,11 +307,13 @@ static unsigned int cqspi_calc_rdreg(struct cqspi_flash_pdata *f_pdata)
   
   static unsigned int cqspi_calc_dummy(const struct spi_mem_op *op, bool dtr)
   {
-	unsigned int dummy_clk;
+	unsigned int dummy_clk = 0;
   
-	dummy_clk = op->dummy.nbytes * (8 / op->dummy.buswidth);
-	if (dtr)
-		dummy_clk /= 2;
+	if (op->dummy.buswidth && op->dummy.nbytes) {
+		dummy_clk = op->dummy.nbytes * (8 / op->dummy.buswidth);
+		if (dtr)
+			dummy_clk /= 2;
+	}
   
   	return dummy_clk;
   }
-- 
2.32.0

             reply	other threads:[~2021-07-15  0:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-15  0:46 Yoshitaka Ikeda [this message]
2021-07-15 12:24 ` [PATCH v2] spi: spi-cadence-quadspi: Fix division by zero warning Mark Brown
2021-07-15 16:18   ` Yoshitaka Ikeda
2021-07-15 19:53 ` Mark Brown

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=362e0cbc-ed82-bf7d-025c-d586d11eaac2@nskint.co.jp \
    --to=ikeda@nskint.co.jp \
    --cc=broonie@kernel.org \
    --cc=k.kurematsu@nskint.co.jp \
    --cc=linux-spi@vger.kernel.org \
    --cc=m.mizutani@nskint.co.jp \
    --cc=p.zabel@pengutronix.de \
    /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.