linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: Fixed division by zero warning
@ 2021-09-08  5:29 Yoshitaka Ikeda
  2021-09-08  6:17 ` Yoshitaka Ikeda
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Yoshitaka Ikeda @ 2021-09-08  5:29 UTC (permalink / raw)
  To: Mark Brown
  Cc: Yoshitaka Ikeda, Philipp Zabel, Pratyush Yadav, linux-spi,
	Masahiro Mizutani, Ken Kurematsu

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>
---
 drivers/spi/atmel-quadspi.c  | 2 +-
 drivers/spi/spi-bcm-qspi.c   | 3 ++-
 drivers/spi/spi-mtk-nor.c    | 2 +-
 drivers/spi/spi-stm32-qspi.c | 2 +-
 4 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/spi/atmel-quadspi.c b/drivers/spi/atmel-quadspi.c
index 95d4fa32c299..92d9610df1fd 100644
--- a/drivers/spi/atmel-quadspi.c
+++ b/drivers/spi/atmel-quadspi.c
@@ -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;
 
 	/*
diff --git a/drivers/spi/spi-bcm-qspi.c b/drivers/spi/spi-bcm-qspi.c
index a78e56f566dd..0d95fe54b3c0 100644
--- a/drivers/spi/spi-bcm-qspi.c
+++ b/drivers/spi/spi-bcm-qspi.c
@@ -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:
diff --git a/drivers/spi/spi-mtk-nor.c b/drivers/spi/spi-mtk-nor.c
index 41e7b341d261..5c93730615f8 100644
--- a/drivers/spi/spi-mtk-nor.c
+++ b/drivers/spi/spi-mtk-nor.c
@@ -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)) {
diff --git a/drivers/spi/spi-stm32-qspi.c b/drivers/spi/spi-stm32-qspi.c
index 27f35aa2d746..514337c86d2c 100644
--- a/drivers/spi/spi-stm32-qspi.c
+++ b/drivers/spi/spi-stm32-qspi.c
@@ -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);
 
-- 
2.33.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] spi: Fixed division by zero warning
  2021-09-08  5:29 [PATCH] spi: Fixed division by zero warning Yoshitaka Ikeda
@ 2021-09-08  6:17 ` Yoshitaka Ikeda
  2021-09-17 16:42 ` Pratyush Yadav
  2021-09-20 15:30 ` Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Yoshitaka Ikeda @ 2021-09-08  6:17 UTC (permalink / raw)
  To: Mark Brown
  Cc: Yoshitaka Ikeda, Philipp Zabel, Pratyush Yadav, linux-spi,
	Masahiro Mizutani, Ken Kurematsu

On 2021/09/08 14:29, Yoshitaka Ikeda wrote:
> Fixes: 7512eaf54190 ("spi: cadence-quadspi: Fix dummy cycle calculation when buswidth > 1")

I'm sorry, this is wrong and not necessary.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] spi: Fixed division by zero warning
  2021-09-08  5:29 [PATCH] spi: Fixed division by zero warning Yoshitaka Ikeda
  2021-09-08  6:17 ` Yoshitaka Ikeda
@ 2021-09-17 16:42 ` Pratyush Yadav
  2021-09-20 15:30 ` Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Pratyush Yadav @ 2021-09-17 16:42 UTC (permalink / raw)
  To: Yoshitaka Ikeda
  Cc: Mark Brown, Philipp Zabel, linux-spi, Masahiro Mizutani, Ken Kurematsu

Hi Yoshitaka,

On 08/09/21 05:29AM, Yoshitaka Ikeda wrote:
> 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")

You are right, there is no need for this.

> Signed-off-by: Yoshitaka Ikeda <ikeda@nskint.co.jp>
> ---
>  drivers/spi/atmel-quadspi.c  | 2 +-
>  drivers/spi/spi-bcm-qspi.c   | 3 ++-
>  drivers/spi/spi-mtk-nor.c    | 2 +-
>  drivers/spi/spi-stm32-qspi.c | 2 +-
>  4 files changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/spi/atmel-quadspi.c b/drivers/spi/atmel-quadspi.c
> index 95d4fa32c299..92d9610df1fd 100644
> --- a/drivers/spi/atmel-quadspi.c
> +++ b/drivers/spi/atmel-quadspi.c
> @@ -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;
>  
>  	/*
> diff --git a/drivers/spi/spi-bcm-qspi.c b/drivers/spi/spi-bcm-qspi.c
> index a78e56f566dd..0d95fe54b3c0 100644
> --- a/drivers/spi/spi-bcm-qspi.c
> +++ b/drivers/spi/spi-bcm-qspi.c
> @@ -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;

This is a legitimate fix. The other 3 won't make much of a difference in 
practice but are good changes regardless IMO.

Acked-by: Pratyush Yadav <p.yadav@ti.com>

>  
>  	switch (width) {
>  	case SPI_NBITS_SINGLE:
> diff --git a/drivers/spi/spi-mtk-nor.c b/drivers/spi/spi-mtk-nor.c
> index 41e7b341d261..5c93730615f8 100644
> --- a/drivers/spi/spi-mtk-nor.c
> +++ b/drivers/spi/spi-mtk-nor.c
> @@ -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)) {
> diff --git a/drivers/spi/spi-stm32-qspi.c b/drivers/spi/spi-stm32-qspi.c
> index 27f35aa2d746..514337c86d2c 100644
> --- a/drivers/spi/spi-stm32-qspi.c
> +++ b/drivers/spi/spi-stm32-qspi.c
> @@ -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);
>  
> -- 
> 2.33.0

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] spi: Fixed division by zero warning
  2021-09-08  5:29 [PATCH] spi: Fixed division by zero warning Yoshitaka Ikeda
  2021-09-08  6:17 ` Yoshitaka Ikeda
  2021-09-17 16:42 ` Pratyush Yadav
@ 2021-09-20 15:30 ` Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2021-09-20 15:30 UTC (permalink / raw)
  To: Yoshitaka Ikeda
  Cc: Mark Brown, Philipp Zabel, Ken Kurematsu, linux-spi,
	Masahiro Mizutani, Pratyush Yadav

On Wed, 8 Sep 2021 05:29:12 +0000, Yoshitaka Ikeda wrote:
> 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.
> 
> 

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/1] spi: Fixed division by zero warning
      commit: 09134c5322df9f105d9ed324051872d5d0e162aa

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-20 15:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-08  5:29 [PATCH] spi: Fixed division by zero warning Yoshitaka Ikeda
2021-09-08  6:17 ` Yoshitaka Ikeda
2021-09-17 16:42 ` Pratyush Yadav
2021-09-20 15:30 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).