Skip to content

Commit 55cef88

Browse files
yoikedabroonie
authored andcommitted
spi: spi-cadence-quadspi: Fix division by zero warning
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) Fixes: 7512eaf ("spi: cadence-quadspi: Fix dummy cycle calculation when buswidth > 1") Signed-off-by: Yoshitaka Ikeda <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent c934fec commit 55cef88

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/spi/spi-cadence-quadspi.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,13 @@ static unsigned int cqspi_calc_rdreg(struct cqspi_flash_pdata *f_pdata)
307307

308308
static unsigned int cqspi_calc_dummy(const struct spi_mem_op *op, bool dtr)
309309
{
310-
unsigned int dummy_clk;
310+
unsigned int dummy_clk = 0;
311311

312-
dummy_clk = op->dummy.nbytes * (8 / op->dummy.buswidth);
313-
if (dtr)
314-
dummy_clk /= 2;
312+
if (op->dummy.buswidth && op->dummy.nbytes) {
313+
dummy_clk = op->dummy.nbytes * (8 / op->dummy.buswidth);
314+
if (dtr)
315+
dummy_clk /= 2;
316+
}
315317

316318
return dummy_clk;
317319
}

0 commit comments

Comments
 (0)