spi: Fixed division by zero warning
authorYoshitaka Ikeda <ikeda@nskint.co.jp>
Wed, 8 Sep 2021 05:29:12 +0000 (05:29 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 18 Nov 2021 18:16:24 +0000 (19:16 +0100)
[ Upstream commit 09134c5322df9f105d9ed324051872d5d0e162aa ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/spi/atmel-quadspi.c
drivers/spi/spi-bcm-qspi.c
drivers/spi/spi-mtk-nor.c
drivers/spi/spi-stm32-qspi.c

index 95d4fa32c2995edd4cdbf0fc4580285ed9a20099..92d9610df1fd8fb50857839a5a1041bd9c80be08 100644 (file)
@@ -310,7 +310,7 @@ static int atmel_qspi_set_cfg(struct atmel_qspi *aq,
                return mode;
        ifr |= atmel_qspi_modes[mode].config;
 
-       if (op->dummy.buswidth && op->dummy.nbytes)
+       if (op->dummy.nbytes)
                dummy_cycles = op->dummy.nbytes * 8 / op->dummy.buswidth;
 
        /*
index ea1865c08fc22d4d5c82932c6119c346ef434a83..151e154284bdee06f18ebd39305259017810d425 100644 (file)
@@ -395,7 +395,8 @@ static int bcm_qspi_bspi_set_flex_mode(struct bcm_qspi *qspi,
        if (addrlen == BSPI_ADDRLEN_4BYTES)
                bpp = BSPI_BPP_ADDR_SELECT_MASK;
 
-       bpp |= (op->dummy.nbytes * 8) / op->dummy.buswidth;
+       if (op->dummy.nbytes)
+               bpp |= (op->dummy.nbytes * 8) / op->dummy.buswidth;
 
        switch (width) {
        case SPI_NBITS_SINGLE:
index 41e7b341d2616f28fd8625490c8af265dacea673..5c93730615f8d7eac53af6f4f91338a774e23518 100644 (file)
@@ -160,7 +160,7 @@ static bool mtk_nor_match_read(const struct spi_mem_op *op)
 {
        int dummy = 0;
 
-       if (op->dummy.buswidth)
+       if (op->dummy.nbytes)
                dummy = op->dummy.nbytes * BITS_PER_BYTE / op->dummy.buswidth;
 
        if ((op->data.buswidth == 2) || (op->data.buswidth == 4)) {
index 27f35aa2d746dbfe8e4e548e720916735023c04b..514337c86d2c3f4b3e1f6b064fcc90af7997db7e 100644 (file)
@@ -397,7 +397,7 @@ static int stm32_qspi_send(struct spi_mem *mem, const struct spi_mem_op *op)
                ccr |= FIELD_PREP(CCR_ADSIZE_MASK, op->addr.nbytes - 1);
        }
 
-       if (op->dummy.buswidth && op->dummy.nbytes)
+       if (op->dummy.nbytes)
                ccr |= FIELD_PREP(CCR_DCYC_MASK,
                                  op->dummy.nbytes * 8 / op->dummy.buswidth);