Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

spi: Fixed division by zero warning

The reason for dividing by zero is because the dummy bus width is zero,
but if the dummy n bytes is zero, it indicates that there is no data transfer,
so there is no need for calculation.

Fixes: 7512eaf54190 ("spi: cadence-quadspi: Fix dummy cycle calculation when buswidth > 1")
Signed-off-by: Yoshitaka Ikeda <ikeda@nskint.co.jp>
Acked-by: Pratyush Yadav <p.yadav@ti.com>
Link: https://lore.kernel.org/r/OSZPR01MB70049C8F56ED8902852DF97B8BD49@OSZPR01MB7004.jpnprd01.prod.outlook.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Yoshitaka Ikeda and committed by
Mark Brown
09134c53 3323129a

+5 -4
+1 -1
drivers/spi/atmel-quadspi.c
··· 310 310 return mode; 311 311 ifr |= atmel_qspi_modes[mode].config; 312 312 313 - if (op->dummy.buswidth && op->dummy.nbytes) 313 + if (op->dummy.nbytes) 314 314 dummy_cycles = op->dummy.nbytes * 8 / op->dummy.buswidth; 315 315 316 316 /*
+2 -1
drivers/spi/spi-bcm-qspi.c
··· 395 395 if (addrlen == BSPI_ADDRLEN_4BYTES) 396 396 bpp = BSPI_BPP_ADDR_SELECT_MASK; 397 397 398 - bpp |= (op->dummy.nbytes * 8) / op->dummy.buswidth; 398 + if (op->dummy.nbytes) 399 + bpp |= (op->dummy.nbytes * 8) / op->dummy.buswidth; 399 400 400 401 switch (width) { 401 402 case SPI_NBITS_SINGLE:
+1 -1
drivers/spi/spi-mtk-nor.c
··· 160 160 { 161 161 int dummy = 0; 162 162 163 - if (op->dummy.buswidth) 163 + if (op->dummy.nbytes) 164 164 dummy = op->dummy.nbytes * BITS_PER_BYTE / op->dummy.buswidth; 165 165 166 166 if ((op->data.buswidth == 2) || (op->data.buswidth == 4)) {
+1 -1
drivers/spi/spi-stm32-qspi.c
··· 397 397 ccr |= FIELD_PREP(CCR_ADSIZE_MASK, op->addr.nbytes - 1); 398 398 } 399 399 400 - if (op->dummy.buswidth && op->dummy.nbytes) 400 + if (op->dummy.nbytes) 401 401 ccr |= FIELD_PREP(CCR_DCYC_MASK, 402 402 op->dummy.nbytes * 8 / op->dummy.buswidth); 403 403