diff mbox series

spi: sn-f-ospi: Fix division by zero

Message ID 20250206082717.3833004-1-hayashi.kunihiko@socionext.com
State New
Headers show
Series spi: sn-f-ospi: Fix division by zero | expand

Commit Message

Kunihiko Hayashi Feb. 6, 2025, 8:27 a.m. UTC
When there is no dummy cycle in the spi-nor commands, both dummy bus cycle
bytes and width are zero. Because of the cpu's warning when divided by
zero, the warning should be avoided. Return just zero to avoid such
calculations.

Fixes: 1b74dd64c861 ("spi: Add Socionext F_OSPI SPI flash controller driver")
Signed-off-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
---
 drivers/spi/spi-sn-f-ospi.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Kunihiko Hayashi Feb. 6, 2025, 8:36 a.m. UTC | #1
On 2025/02/06 17:27, Kunihiko Hayashi wrote:
> When there is no dummy cycle in the spi-nor commands, both dummy bus cycle
> bytes and width are zero. Because of the cpu's warning when divided by
> zero, the warning should be avoided. Return just zero to avoid such
> calculations.
> 
> Fixes: 1b74dd64c861 ("spi: Add Socionext F_OSPI SPI flash controller
> driver")
> Signed-off-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
> ---
>   drivers/spi/spi-sn-f-ospi.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/spi/spi-sn-f-ospi.c b/drivers/spi/spi-sn-f-ospi.c
> index adac645732fe..56ef114effc9 100644
> --- a/drivers/spi/spi-sn-f-ospi.c
> +++ b/drivers/spi/spi-sn-f-ospi.c
> @@ -116,6 +116,9 @@ struct f_ospi {
>   
>   static u32 f_ospi_get_dummy_cycle(const struct spi_mem_op *op)
>   {
> +	if (!op->dummy.nbytes)
> +		return 0;
> +
>   	return (op->dummy.nbytes * 8) / op->dummy.buswidth;
>   }
>   

Sorry, I missed a tag. I'll resend the patch.

Thank you,

---
Best Regards
Kunihiko Hayashi
diff mbox series

Patch

diff --git a/drivers/spi/spi-sn-f-ospi.c b/drivers/spi/spi-sn-f-ospi.c
index adac645732fe..56ef114effc9 100644
--- a/drivers/spi/spi-sn-f-ospi.c
+++ b/drivers/spi/spi-sn-f-ospi.c
@@ -116,6 +116,9 @@  struct f_ospi {
 
 static u32 f_ospi_get_dummy_cycle(const struct spi_mem_op *op)
 {
+	if (!op->dummy.nbytes)
+		return 0;
+
 	return (op->dummy.nbytes * 8) / op->dummy.buswidth;
 }